UNPKG

lowkie

Version:

My Custom lowkie / Express Applcation

49 lines (48 loc) 1.34 kB
'use strict'; const events = require('events'); const lowkieSchema = require('./schema'); const lowkieModel = require('./model'); const lowkieConnect = require('./connect'); const lowkieProxyHandler = require('./lowkieProxyHandler'); /** * lowkie ORM singleton class * * @class lowkie */ class lowkie { /** * Creates an instance of lowkie. * @param {any} [options={}] * * @memberOf lowkie */ constructor(options = {}) { this.config = Object.assign({ adapterType: 'file', debug: false, strictSchemas: true, overwriteInvalidJSON: true, }, options); this.connections = new Map(); this.db = undefined; this.dbs = {}; this.models = {}; this.connection = new events.EventEmitter(); this.model = lowkieModel.bind(this); this.connect = lowkieConnect.bind(this); this.Schema.Types = lowkieSchema.Types; return new Proxy(this, lowkieProxyHandler.call(this)); } /** * creates lowkie schema, also includes helpers for document validations * * @param {object} scheme * @returns instance of lowkieSchema * * @memberOf lowkie */ Schema(scheme, db = 'default') { return new lowkieSchema(scheme, this, db); } } module.exports = lowkie;