Node嵌入式數據庫:NeDB
用于Node.js應用的嵌入式持久數據庫,采用Javascript開發,沒有任何依賴(當然除了NPM模塊)。你可以把它想象成用于Node.js項目的SQLite數據庫。其 API 是MongoDB的一個子集。您可以使用它作為一個持久性或只存在內存中的數據存儲。
NeDB并不旨在替換大型的數據庫如MongoDB。它的目標是為你提供一個簡潔,簡單的方法來查詢數據,并堅持久化到磁盤中,適合于那些沒有很多并發連接的Web應用,比如一個持續集成和部署服務器與利用Node Webkit構建的桌面應用。
// 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 loading var 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 loading var 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.db var 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();
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!