{"id":42783,"library":"gatepost","title":"Gatepost","description":"Gatepost is a reverse ORM for PostgreSQL that binds SQL statements to Model factories and instances, casting results as Model instances without modeling the database schema. It relies on VeryModel for model validation and allows flexible SQL generation via knex, template strings, or raw queries. Current stable version is 7.2.0. Unlike traditional ORMs, Gatepost focuses on query results rather than table structures. It uses Promises and supports caching. Release cadence is irregular. Key differentiators: schema-agnostic, compatible with knex, and uses VeryModel for validation.","status":"active","version":"7.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/fritzy/gatepost","tags":["javascript","pg","postgres","postgresql","database","db","orm","query","sql"],"install":[{"cmd":"npm install gatepost","lang":"bash","label":"npm"},{"cmd":"yarn add gatepost","lang":"bash","label":"yarn"},{"cmd":"pnpm add gatepost","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides Model factories and instances for validation and data conversion.","package":"verymodel","optional":false},{"reason":"PostgreSQL client for executing queries.","package":"pg","optional":false}],"imports":[{"note":"Gatepost is a default export; named destructuring will fail.","wrong":"const { Gatepost } = require('gatepost')","symbol":"Gatepost","correct":"import Gatepost from 'gatepost'"},{"note":"Model is accessed via the instance returned by Gatepost(connectionString), not a direct export.","wrong":"const { Model } = require('gatepost')","symbol":"Model","correct":"const gatepost = require('gatepost')(connectionString); const Book = new gatepost.Model(options);"},{"note":"EmptyResult is a named export from the module, but Gatepost default export also has it. Direct import from 'gatepost' works if using named exports.","wrong":"import { EmptyResult } from 'gatepost'","symbol":"EmptyResult","correct":"const { EmptyResult } = Gatepost;"}],"quickstart":{"code":"import Gatepost from 'gatepost';\nimport SQL from 'sql-template-strings';\n\nconst gp = Gatepost('postgres://user:password@localhost/mydb');\n\nconst Book = new gp.Model({\n  title: {},\n  id: {}\n}, {\n  name: 'Book',\n  cache: true\n});\n\nBook.fromSQL({\n  name: 'getByCategory',\n  sql: (args) => SQL`SELECT id, title FROM books WHERE category = ${args.category}`,\n  oneResult: false\n});\n\nBook.getByCategory({ category: 'fiction' }).then(books => {\n  books.forEach(book => console.log(book.toJSON()));\n}).catch(err => {\n  console.error(err);\n});","lang":"typescript","description":"Demonstrates importing Gatepost, connecting to PostgreSQL, defining a Model, and executing a SQL query with a template string."},"warnings":[{"fix":"const gp = require('gatepost')(connectionString); const Model = gp.Model;","message":"Model is not a direct export; you must call Gatepost(connectionString) first.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure sql returns a plain string, {text, values} object, or knex query builder.","message":"SQL function must return a query object or string compatible with pg.query; using knex query builders works automatically.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use .then()/.catch() or async/await.","message":"Removed support for callbacks; Promises only.","severity":"breaking","affected_versions":">=7.0.0"}],"env_vars":null,"search_vec":"'7.2.0':51 'agnost':78 'allow':36 'bind':10 'cach':69 'cadenc':71 'cast':18 'compat':79 'current':47 'databas':26,91 'db':92 'differenti':75 'factori':15 'flexibl':37 'focus':56 'gatepost':1,2,55 'generat':39 'instanc':17,22 'irregular':73 'javascript':87 'key':74 'knex':41,81 'model':14,21,24,33 'orm':6,54,93 'pg':88 'postgr':89 'postgresql':8,90 'promis':66 'queri':46,58,94 'rather':60 'raw':45 'releas':70 'reli':29 'result':19,59 'revers':5 'schema':27,77 'schema-agnost':76 'sql':11,38,95 'stabl':48 'statement':12 'string':43 'structur':63 'support':68 'tabl':62 'templat':42 'tradit':53 'unlik':52 'use':65,83 'valid':34,86 'version':49 'verymodel':31,84 'via':40 'without':23","created_at":"2026-06-05T16:56:39.048825+00:00","updated_at":"2026-06-05T16:56:39.048825+00:00","problems":[{"fix":"Use `import Gatepost from 'gatepost'` or `const Gatepost = require('gatepost').default`","cause":"Importing the module incorrectly: using named import instead of default.","error":"TypeError: Gatepost is not a function"},{"fix":"Run `npm install verymodel`","cause":"VeryModel is a required peer dependency but not installed.","error":"Cannot find module 'verymodel'"},{"fix":"Catch the EmptyResult error or ensure the query returns exactly one row.","cause":"A query with `oneResult: true` returned zero rows.","error":"gatepost.EmptyResult: No rows returned"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/fritzy/gatepost","github":"git://github.com/fritzy/gatepost","docs":null,"changelog":null,"pypi":null,"npm":"gatepost","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}