Git Product home page Git Product logo

nedb-models's People

Contributors

bajankristof avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nedb-models's Issues

How could i access the DataStoreInstance from Model?

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?

i can't access the datastore instance via __datastore

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);
});

DataStore insert should return model instance

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.