bajankristof / nedb-models Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
in nedb-promises we could access instance by:
let datastore = Datastore.create('/path/to/db.db')
and call
datastore.persistence.compactDatafile();
manually.
but in nedb-model
static datastore() {
return {
filename: 'books.db'
}
}
the static datastore only accept config object or could i pass a datastore instance?
and how could i get the datastore instance from nedb-model instance?
is there any example code?
reference #5
today i just try to access the datastore instance via __datastore prop.
call MyDemoModel.__datastore.persistence.compactDatafile()
but console show's that :
TypeError: Cannot read property 'compactDatafile' of undefined
i print the __datastore property it's not the original nedb instance:
__datastore Datastore {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined }
persistence undefined
this is my test code:
const Datastore = require('nedb-promises');
const { Model } = require('nedb-models');
const datastore = Datastore.create({
filename: './mydemo.db',
inMemoryOnly: false,
autoload: true,
timestampData: true
});
class MyDemoModel extends Model {
static datastore() {
return datastore;
}
}
(async()=>{
// eslint-disable-next-line no-unused-vars
let demoObj1 = await MyDemoModel.create({k1:1,k2:2});
// eslint-disable-next-line no-unused-vars
let demoObj2 = await MyDemoModel.create({k1:2,k2:3});
// datastore.persistance.compactDatafile();
console.log("__datastore",MyDemoModel.__datastore);
console.log("persistence",MyDemoModel.__datastore.persistence);
MyDemoModel.__datastore.persistence.compactDatafile();
})().catch(err=>{
console.error(err);
});
Hi.
Having a data store with model attached
class ItemStore extends Datastore {
constructor() {
super({
filename: './db/item.db',
autoload: true
});
this.attachModel(Item);
}
}
when I do
dataStore.insert(new Item(req.body)).then(inserted => ...)
or even
dataStore.insert(req.body).then(inserted => ...)
I would expect that inserted
is an instance of Item
, but it is just a plain object instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.