refactor sqlite3 to postgreSQL