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.
Offshore
✓ const Offshore = require('offshore');
✗ import Offshore from 'offshore';
This package does not ship ESM; it must be required via CommonJS.
Collection
✓ const User = Offshore.Collection.extend({...});
✗ class User extends Offshore.Collection {}
Offshore uses .extend() pattern, not ES6 class inheritance.
offshore
✓ const offshore = new Offshore();
✗ const offshore = new offshore.Offshore();
The constructor is the default export.
Defines a User model, initializes Offshore with a PostgreSQL adapter, registers the collection, and creates a record.
const Offshore = require('offshore');
const User = Offshore.Collection.extend({
identity: 'user',
connection: 'myLocalPostgres',
attributes: {
firstName: { type: 'string', required: true },
lastName: { type: 'string', required: true },
email: { type: 'string', required: true, unique: true }
}
});
const offshore = new Offshore();
const config = {
adapters: {
'postgresql': require('sails-postgresql'),
'memory': require('offshore-memory')
},
connections: {
'myLocalPostgres': {
adapter: 'postgresql',
host: process.env.DB_HOST ?? 'localhost',
port: 5432,
database: process.env.DB_NAME ?? 'mydb',
user: process.env.DB_USER ?? 'postgres',
password: process.env.DB_PASSWORD ?? ''
},
'tmpmemory': {
adapter: 'memory'
}
},
defaults: {
migrate: 'safe'
}
};
User.registerCollection();
offshore.initialize(config, (err, ontology) => {
if (err) return console.error(err);
const UserModel = ontology.collections.user;
UserModel.create({ firstName: 'John', lastName: 'Doe', email: 'john@example.com' }, (err, user) => {
if (err) return console.error(err);
console.log('Created user:', user);
});
});
Errors
Common errors & fixes
Error: Cannot find module 'sails-postgresql'
Missing adapter dependency.
fixnpm install sails-postgresql
Offshore.Collection.extend is not a function
Using import statement instead of require, or wrong object reference.
fixUse const Offshore = require('offshore'); then Offshore.Collection.extend(...). Cannot find module 'offshore/...'
Trying to import a submodule that does not exist.
fixOffshore does not support deep imports; only require('offshore'). Audit
Dependencies
lodashrequiredUsed extensively for object manipulation and iteration.
asyncrequiredUsed for asynchronous control flow.
anchorrequiredValidation library used for attribute definitions.
switchbackrequiredUsed for callback flow control.