UNPKG

suma-db

Version:

A Brazilian database that supports JSON(JavaScript Object Notation)

101 lines (95 loc) 3.58 kB
(function () { "use strict" const Base = require("./Base.js") class Suma extends Base { constructor(path) { if (typeof path == 'string') path = { path, prefix: ':', web: false, spaces: 4 } super(path, path?.content || {}, path?.prefix || ":", path?.spaces ?? 4) if (path?.web) this.web = require("./systems/web.js")(path.webPath, this.read(), path.port) } ref(key, value) { return require('./methods/ref.js')({ class: this, key, value }); } reference(key, value) { return require('./methods/ref.js')({ class: this, key, value }); } all(collection = false, limit = Number.MAX_VALUE) { return require("./methods/all.js")({ class: this }, collection, limit) } fetch(values, rapid = false) { if (rapid?.rapid) rapid = rapid?.rapid return require("./methods/fetch.js")(this, values, rapid) } clear(timeout = 1) { if (timeout.timeout) timeout = timeout.timeout return require("./methods/clear.js")(this, timeout) } async refAsync(key, value) { return require('./methods/ref.js')({ class: this, key, value }); } async referenceAsync(key, value) { return require('./methods/ref.js')({ class: this, key, value }); } async post(...values) { return require("./methods/post.js")({ class: this }, ...values) } put(value) { return require("./methods/put.js")(this, value) } keys() { return require("./methods/keys.js")(this) } values() { return require("./methods/values.js")(this) } entries() { return require('./methods/entries.js')(this) } forEach(callback) { return require("./methods/forEach.js")(this, callback) } map(callback) { return require("./methods/map.js")(this, callback) } has(key) { if (key.key) key = key.key return require("./methods/has.js")(this, key) } toString() { return require("./methods/toString.js")(this) } static get version() { return require("../package.json").version } static get author() { return "Belzinhu" } get size() { return this.all().length } async ping() { let pingStart = process.hrtime(); ;(await this.refAsync("ping")).val(); await (require(`util`).promisify(setTimeout))(5000) let pingStop = process.hrtime(pingStart); let pingDb = Math.round(((pingStop[0] * 1e9) + pingStop[1]) / 1e6) || ~~(Math.random() * 17) + 1 return pingDb } startsWith(path='') { if(typeof path === 'string') path = {path} return require("./methods/startsWith")(this,path) } endsWith(path) { if(typeof path === 'string') path = {path} return require("./methods/endsWith")(this,path) } contains(path) { if(typeof path === 'string') path = {path} return require("./methods/contains.js")(this,path) } } module.exports = { Collection: require("collections/map"), Database: Suma } }).call(this)