the-db
DB for the-framework
Installation
$ npm install the-db --save
Usage
Basic Usage
'use strict' const TheDB = const TheResource DataTypes: STRING } = // Define a resource class// See https://github.com/realglobe-Inc/clay-resource for more detail // Convert entity attributes on inbound static { const digest = { /* ... */ } attributespasswordHash = return attributes } // Convert entity attributes on outbound static { delete attributespassword return attributes } // Resource policy // https://github.com/realglobe-Inc/clay-policy#usage static { return username: type: STRING password: type: STRING } // Create index to enable filter/sort with nested attributes static { return 'profile.name' 'profile.email' } // Enhance entity class static { return { let firstName lastName = this return firstName lastName } } // Hook after entity create static { console } // Hook after entity update static { console } // Hook after entity destroy static { console } const db = dialect: 'sqlite' // Uses "clay-driver-sqlite" package storage: 'var/my-app.db' // File path to save db // Using defined database { // Use the connected resource const User = dbresources let user = await User /* ... */}
Dialect Examples
env.dialect
option decides where to store data with Clay-Driver.
'use strict' const TheDB = // Using sqlite const sqlite = dialect: 'sqlite' // Uses "clay-driver-sqlite" package storage: 'var/my-app.db' // File path to save // Using json const json = dialect: 'json' // Uses "clay-driver-json" package storage: 'var/my-app.json' // File path to save // Using mysql const mysql =
Data migrations
'use strict' const TheDB = const TheResource DataTypes: STRING /*....*/ = /* ... */ const db = /* ... */ db // Using defined database { // Migration scripts const migrations = // Called only if no migration has ever executed async 'none' db const User = dbresources // Migration scripts await User /* ... */ await db // Update to next version async '1.0.0' db /* ... */ await db await db}
API Guide
License
This software is released under the MIT License.