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.
SwormSchema
✓ const { SwormSchema } = require('sworm-schema')
✗ import { SwormSchema } from 'sworm-schema'
Package is CommonJS only; named export via destructuring. No default export. ESM import will fail.
SwormSchema (default import mistake)
✓ const { SwormSchema } = require('sworm-schema')
✗ const SwormSchema = require('sworm-schema')
Common mistake: treating it as default export. SwormSchema is not a default export; you must destructure.
Constructor usage
✓ const { SwormSchema } = require('sworm-schema'); const schema = new SwormSchema({ url: 'sqlite:test.db', schema: { ... } })
✗ const schema = new SwormSchema()
Constructor requires both 'url' and 'schema' options. Missing required options will throw.
Creates an in-memory SQLite database from a schema definition, inserts a record, queries it, then cleans and drops the database.
const { SwormSchema } = require('sworm-schema');
const swormSchema = new SwormSchema({
url: 'sqlite:test/db/test.db',
schema: {
people: {
id: { type: 'integer' },
name: { type: 'text' },
},
places: {
id: { type: 'integer' },
name: { type: 'text' },
},
},
});
async function run() {
await swormSchema.create();
const db = await swormSchema.connect();
const person = db.model({ table: 'people' });
await person({ id: 1, name: 'Alice' }).save();
console.log(await db.query('select * from people'));
await swormSchema.clean();
await swormSchema.drop();
}
run().catch(console.error);
Errors
Common errors & fixes
TypeError: SwormSchema is not a constructor
Importing SwormSchema as default instead of named export.
fixconst { SwormSchema } = require('sworm-schema') Cannot read property 'connect' of undefined
SwormSchema instance not properly created or async methods called without await.
fixEnsure new SwormSchema() is called with correct options and all methods are awaited.
Error: Invalid schema definition: missing type for column 'id'
Column definition in schema object lacks 'type' property.
fixAdd type to each column, e.g., id: { type: 'integer' }. Error: sworm is not a function
SWORM peer dependency missing or incompatible version.
fixInstall sworm@^3.7 as a peer dependency.
Audit
Dependencies
swormrequiredPeer dependency required at runtime for database connections and query execution.