How to use nedb-promises - 8 common examples

To help you get started, we’ve selected a few nedb-promises examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cutls / TheDesk / src / main / Client.ts View on Github external
public static async getAuthClient(username: string, protocol: Protocol = 'http'): Promise {
        let clients = protocol === 'http' ? this.authorizedHTTP : this.authorizedWebSocket

        if (!clients.has(username)) {
            // usernameからドメインをとトークンをデータベースから取得してクライアントを作る
            let db = Datastore.create({
                filename: join(app.getPath("userData"), "account.db"),
                autoload: true
            })
            try {
                let doc = await db.findOne<{ domain: string; accessToken: string; }>({ full: username })
                Client.setAuthClient(protocol, username, Client.createAuthClient(protocol, doc.domain, doc.accessToken))
            } catch (err) {
                throw err
            }
        }

        return clients.get(username)!
    }
github w3f / polkadot-deployer / lib / core / db.js View on Github external
save: async (config) => {
    const cfg = JSON.parse(JSON.stringify(config));
    const datastore = Datastore.create(dbPath());

    // do not store sensitive info
    delete cfg.keys;
    delete cfg.nodeKeys;

    return datastore.insert(cfg);
  },
github phishy / wflow / api.js View on Github external
const fs = require('fs');
const tempDirectory = require("temp-dir");

const runJob = require("./lib/runJob");

var app = require("express")();
var http = require("http").createServer(app);
var io = require("socket.io")(http);
const cors = require("cors");
const bodyParser = require("body-parser");
app.use(cors());
app.use(bodyParser.json());

let db = {};
db.runs = Datastore.create(`${tempDirectory}/wflow/data/runs.db`);
db.jobs = Datastore.create(`${tempDirectory}/wflow/data/jobs.db`);
db.steps = Datastore.create(`${tempDirectory}/wflow/data/steps.db`);

app.get('/', (req, res)=>{
  res.send('Hello!');
});

app.post("/runs", async (req, res) => {
  var workflow = req.body;
  workflow.status = "incomplete";

  var wRes = await db.runs.insert(workflow);
  workflow._id = wRes._id;

  for (let jobId in workflow.jobs) {
    let job = workflow.jobs[jobId];
github phishy / wflow / api.js View on Github external
const tempDirectory = require("temp-dir");

const runJob = require("./lib/runJob");

var app = require("express")();
var http = require("http").createServer(app);
var io = require("socket.io")(http);
const cors = require("cors");
const bodyParser = require("body-parser");
app.use(cors());
app.use(bodyParser.json());

let db = {};
db.runs = Datastore.create(`${tempDirectory}/wflow/data/runs.db`);
db.jobs = Datastore.create(`${tempDirectory}/wflow/data/jobs.db`);
db.steps = Datastore.create(`${tempDirectory}/wflow/data/steps.db`);

app.get('/', (req, res)=>{
  res.send('Hello!');
});

app.post("/runs", async (req, res) => {
  var workflow = req.body;
  workflow.status = "incomplete";

  var wRes = await db.runs.insert(workflow);
  workflow._id = wRes._id;

  for (let jobId in workflow.jobs) {
    let job = workflow.jobs[jobId];

    var jRes = await db.jobs.insert({
github cutls / TheDesk / src / main / Auth.ts View on Github external
return
    }

    if (tokenData.accessToken === undefined) {
      let error = new Error("Failed to get access token.")
      error.name = "ERROR_GET_TOKEN"
      event.sender.send(`login-complete`, undefined, error)
      return
    }

    const client = Client.createAuthClient('http', instance, tokenData.accessToken)

    let resp: Response = await client.get("/accounts/verify_credentials")
    let you = resp.data

    let db = Datastore.create({
      filename: join(app.getPath("userData"), "account.db"),
      autoload: true
    })

    let docs: AccountDoc = {
      domain: instance,
      acct: you.acct,
      full: you.acct + "@" + instance,
      avatar: you.avatar,
      avatarStatic: you.avatar_static,
      accessToken: tokenData.accessToken,
    }

    try {
      let newDoc = await db.insert(docs)
      Client.setAuthClient('http', newDoc.full, client)
github cutls / TheDesk / src / main / Timeline.ts View on Github external
private static async onAddTimeline(event: Event, name: string, type: string) {
        if (!(type in this.endpoints) && type !== 'no-auth') {
            event.sender.send(`add-timeline`, undefined, new Error("Not supported type"))
            return
        }

        let db = Datastore.create({
            filename: join(app.getPath("userData"), "timeline.db"),
            autoload: true
        })

        let docs: TimelineDoc = {
            name: name,
            type: type,
        }

        try {
            let newDoc = await db.insert(docs)
            event.sender.send(`add-timeline`, newDoc)
        } catch (err) {
            let error = new Error("Cannot save timeline.")
            error.name = "ERROR_ADD_TIMELINE"
            event.sender.send(`add-timeline`, undefined, error)
github w3f / polkadot-deployer / lib / core / db.js View on Github external
list: async (projection = {}) => {
    const datastore = Datastore.create(dbPath());

    return datastore.find({}, projection).sort({ name: 1 });
  },
github cutls / TheDesk / src / main / Timeline.ts View on Github external
private static async getTimeline(id: string): Promise {
        let db = Datastore.create({
            filename: join(app.getPath("userData"), "timeline.db"),
            autoload: true
        })

        try {
            return db.findOne({ _id: id })
        } catch (err) {
            throw err
        }
    }

nedb-promises

A dead-simple promise wrapper for nedb.

MIT
Latest version published 1 year ago

Package Health Score

54 / 100
Full package analysis

Popular nedb-promises functions