The model for this Datastore. T
must extend from Model
The name of the database. Usually the name of the type in lower case.
The directory where the database will be created.
A function that returns the type. For example () => Human
LevelDB method wrappers. See DatastoreOperations for more info.
Name of the database.
The LevelDB storage.
A function that returns the type of the model.
This method is used to create a new object with this model. Without calling this method, you will not be able to use .save() or .delete() methods on the object.
const store = new Datastore<Human>(...)
const human = store.create(new Human(...))
await human.save() //Without using .create() this will throw.
T
object to initialize.
T
object with its Model.store field set.
This method deletes one single object from database.
const store = new Datastore<Human>(...)
const humanId = '...'
const humanEdited = await store.delete().id(humanId).run()
console.log(humanEdited)
A new instance of DeleteOperation<T>
. More info on this is in DeleteOperation.
This method deletes a batch of objects from database.
const store = new Datastore<Human>(...)
const humanIds: string[] = ['...', '...']
await store.delete().ids(humanIds).run()
A new instance of BatchedDeleteOperation<T>
. More info on this is in BatchedDeleteOperation.
This method edits one single object from database.
const store = new Datastore<Human>(...)
const humanId = '...'
const humanEdited = await store.edit().id(humanId).with({...}).run()
console.log(humanEdited)
A new instance of EditOperation<T>
. More info on this is in EditOperation.
This method gets objects from the database.
const store = new Datastore<Human>(...)
const humans = await store.get().take(5).run()
console.log(humans)
A new instance of GetOperation<T>
. More info on this is in GetOperation.
This method is used to push a new object to the database.
const store = new Datastore<Human>(...)
const human = await store.push().item(new Human(...)).run()
console.log(human)
A new instance of PushOperation<T>
. More info on this is in PushOperation.
This method is used to push a bunch of objects to the database.
const store = new Datastore<Human>(...)
const humansData: Human[] = [...]
const humans = await store.pushBatched().items(humansData).run()
console.log(humans)
A new instance of BatchedPushOperation<T>
. More info on this is in BatchedPushOperation.
Generated using TypeDoc
The Datastore object is used to call methods on LevelDB instance.
Usage
const store = new Datastore<Human>('human', './database', () => Human)