Registry / database / great-scott

great-scott

JSON →
library0.7.0jsnpmunverified

A Marty-like data source for PostgreSQL. Version 0.7.0 is the latest stable release. Provides a base DataSource class that wraps pg-promise with query building, connection management, and helper methods for insert/update. Integrates with Immutable.js models and automatic camelCase/snake_case conversion. Lightweight alternative to ORMs like Sequelize or Objection for projects already using Marty.js or Flux patterns with Immutable data.

npm install great-scott
INSTALL
IMPORT
SIG · GREAT-SCOTT
G
great-scott
databasejavascriptv0.7.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.

DataSource
import { DataSource } from 'great-scott'
const DataSource = require('great-scott').DataSource
ESM default export does not exist; named export only.
DataSource
const { DataSource } = require('great-scott')
const DataSource = require('great-scott')
CommonJS requires destructuring from named exports.
DataSource
import DataSource from 'great-scott'
Not available as default import; use named import instead.

Extends DataSource to define a User model with Immutable.js Record, query builder select, and insert/update helpers.

import { DataSource } from 'great-scott'; import { Record } from 'immutable'; const UserModel = Record({ id: null, name: null, }); class UserDataSource extends DataSource { constructor() { super({ tableName: 'users', model: UserModel, connectionString: process.env.POSTGRES_URL ?? '', }); } parse(row) { const data = {}; for (const [key, val] of Object.entries(row)) { data[_.camelCase(key)] = val; } return new this.model(data); } format(model) { const obj = model.toObject(); const data = {}; for (const [key, val] of Object.entries(obj)) { data[_.snakeCase(key)] = val; } return data; } findAll() { const query = this.builder.select().from('users'); return this.execute(query); } createUser(model) { return this.insert(model); } } const ds = new UserDataSource(); ds.findAll().then(console.log);
Debug
Known issues
gotchaRequires Immutable.js Record for model property; plain objects will cause errors.
fix
Define models using Immutable.js Record, e.g., const MyModel = Record({...}).
affects: >=0.0.0
deprecatedVersion 0.7.0 is a minor release; API may change without major version bump.
fix
Pin to exact version and expect breaking changes in future 0.x releases.
affects: >=0.7.0
gotchatableName is required for insert/update helper methods; not optional as described.
fix
Always provide tableName when calling insert() or update().
affects: >=0.0.0
gotchaDataSource is not a standard ES6 class; methods like parse and format must be defined manually.
fix
Implement parse() and format() in your subclass to handle data transformation.
affects: >=0.0.0
gotchaUses Underscore.js `_.camelCase` and `_.snakeCase` in README example; these are not included in dependencies.
fix
Install underscore (or lodash) and import it, or implement your own conversion functions.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: this.model is not a constructor
model property is not a valid Immutable.js Record class.
fix
Ensure model is defined as a Record, e.g., const Model = Record({...});
Cannot find module 'immutable'
Immutable.js is not installed or not a runtime dependency.
fix
Install immutable: npm install immutable
TypeError: this.builder is not defined
Calling this.builder in a static method; builder is only available in instance methods.
fix
Use this.builder only in instance methods, not static methods like findAll.
Error: tableName is required for insert/update helpers
tableName was not provided in constructor options.
fix
Pass tableName in super({tableName: 'your_table', ...}).
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies
pg-promiserequiredPostgreSQL connection and query execution
immutableoptionalImmutable.js Record for model definition
Agent activity
6 hits · last 30 days
node
6
Resources
great-scott — npm install great-scott · libregistry