Registry / database / gatepost

gatepost

JSON →
library7.2.0jsnpmunverified

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.

npm install gatepost
INSTALL
IMPORT
SIG · GATEPOST
G
gatepost
databasejavascriptv7.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Gatepost
import Gatepost from 'gatepost'
const { Gatepost } = require('gatepost')
Gatepost is a default export; named destructuring will fail.
Model
const gatepost = require('gatepost')(connectionString); const Book = new gatepost.Model(options);
const { Model } = require('gatepost')
Model is accessed via the instance returned by Gatepost(connectionString), not a direct export.
EmptyResult
const { EmptyResult } = Gatepost;
import { EmptyResult } from 'gatepost'
EmptyResult is a named export from the module, but Gatepost default export also has it. Direct import from 'gatepost' works if using named exports.

Demonstrates importing Gatepost, connecting to PostgreSQL, defining a Model, and executing a SQL query with a template string.

import Gatepost from 'gatepost'; import SQL from 'sql-template-strings'; const gp = Gatepost('postgres://user:password@localhost/mydb'); const Book = new gp.Model({ title: {}, id: {} }, { name: 'Book', cache: true }); Book.fromSQL({ name: 'getByCategory', sql: (args) => SQL`SELECT id, title FROM books WHERE category = ${args.category}`, oneResult: false }); Book.getByCategory({ category: 'fiction' }).then(books => { books.forEach(book => console.log(book.toJSON())); }).catch(err => { console.error(err); });
Debug
Known issues
gotchaModel is not a direct export; you must call Gatepost(connectionString) first.
fix
const gp = require('gatepost')(connectionString); const Model = gp.Model;
affects: >=0.0.0
gotchaSQL function must return a query object or string compatible with pg.query; using knex query builders works automatically.
fix
Ensure sql returns a plain string, {text, values} object, or knex query builder.
affects: >=0.0.0
breakingRemoved support for callbacks; Promises only.
fix
Use .then()/.catch() or async/await.
affects: >=7.0.0
Errors
Common errors & fixes
TypeError: Gatepost is not a function
Importing the module incorrectly: using named import instead of default.
fix
Use `import Gatepost from 'gatepost'` or `const Gatepost = require('gatepost').default`
Cannot find module 'verymodel'
VeryModel is a required peer dependency but not installed.
fix
Run `npm install verymodel`
gatepost.EmptyResult: No rows returned
A query with `oneResult: true` returned zero rows.
fix
Catch the EmptyResult error or ensure the query returns exactly one row.
Upgrade
Version history
7.2.0latest on npm
Audit
Dependencies
verymodelrequiredProvides Model factories and instances for validation and data conversion.
pgrequiredPostgreSQL client for executing queries.
Agent activity
4 hits · last 30 days
node
4
Resources
gatepost — npm install gatepost · libregistry