zoukankan      html  css  js  c++  java
  • nedb nodejs 数据库学习

      // Type 1: In-memory only datastore (no need to load the database)
    var Datastore = require('nedb')
      , db = new Datastore();
    
    
    // Type 2: Persistent datastore with manual loadingvar Datastore = require('nedb')
      , db = new Datastore({ filename: 'path/to/datafile' });
    db.loadDatabase(function (err) {    // Callback is optional// Now commands will be executed
    });
    
    
    // Type 3: Persistent datastore with automatic loadingvar Datastore = require('nedb')
      , db = new Datastore({ filename: 'path/to/datafile', autoload: true });
    // You can issue commands right away// Type 4: Persistent datastore for a Node Webkit app called 'nwtest'// For example on Linux, the datafile will be ~/.config/nwtest/nedb-data/something.dbvar Datastore = require('nedb')
      , path = require('path')
      , db = new Datastore({ filename: path.join(require('nw.gui').App.dataPath, 'something.db') });
    
    
    // Of course you can create multiple datastores if you need several// collections. In this case it's usually a good idea to use autoload for all collections.
    db = {};
    db.users = new Datastore('path/to/users.db');
    db.robots = new Datastore('path/to/robots.db');
    
    // You need to load each database (here we do it asynchronously)db.users.loadDatabase();
    db.robots.loadDatabase();





  • 相关阅读:
    JavaScript-年月日转换12小时制
    Javascript-双色球
    Javascript-for循环案例-打印1-100之间所有的数字
    HDU4240_Route Redundancy
    HDU2883_kebab
    POJ3041_Asteroids
    HDU3829_Cat VS Dog
    BZOJ2806_Cheat
    HDU4641_K-string
    CF271D_Good Substrings
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/5737349.html
Copyright © 2011-2022 走看看