Lump of clay-db
Table of Contents
Installation
$ npm install clay-lump --save
Usage
Three steps to use use clay lump.
- Create lump instance with
clayLump(config)
. - Access resource with
lump.resource(resourceName)
- Use resource methods like
resource.create()
orresource.list()
to handle data
'use strict' const clayLump = const SqliteDriver = { let lump01 = const Dog = lump01 let john = await Dog console // -> { id: '1a6358694adb4aa89c15f94be50d5b78', name: 'john', type: 'Saint Bernard', age: 3 } let dogs = await Dog let lump02 = const Dog = lump02 let bess = await Dog const Dog2 = lump02 let bess2 = await Dog // Sync lumps01 to lump02 await lump02 // Both lumps will be updated const Dog = lump02 let john = await Dogentities // Synced from lump01 console // -> { id: '1a6358694adb4aa89c15f94be50d5b78', name: 'john', type: 'Saint Bernard', age: 3 } }
For more detail, see API Guide
Advanced Usage
Applying Policies
To restrict data structure of resources, you can pass ClayPolicy
to policies
options of clay lump constructor.
'use strict' const clayLump = const STRING DATE = clayLumpTypes { let lump02 = // Define policy on resource lump02 // Use the resource with policy const User = lump02 let user01 = await User // -> Throws policy error /* ... */ // Use policy as validator const User = lump02 let policy = User policy }
Listening to events
Resources are instances of EventEmitter and fires events. See ResourceEvents to know what you can listen.
'use strict' const clayLump = const ResourceEvents = clayLump // Events fired from resourceconst ENTITY_CREATE ENTITY_CREATE_BULK ENTITY_UPDATE ENTITY_UPDATE_BULK ENTITY_DESTROY ENTITY_DESTROY_BULK ENTITY_DROP } = ResourceEvents { let lump02 = // Add listener on resource lump02 // Use the resource with policy const User = lump02 console // -> Returns policy info let user01 = await User // -> Throws policy error /* ... */ }
API Guide
License
This software is released under the Apache-2.0 License.