簡體   English   中英

如何對node.js使用persist?

[英]How do I use persist with node.js?

我正在嘗試熟悉該節點的持久性軟件包。 有人可以告訴我是否使用persist.connect在這里建立連接,還是這些屬性?

var persist = require("persist");
var type = persist.type;

// define some model objects
Phone = persist.define("Phone", {
  "number": type.STRING
});

Person = persist.define("Person", {
  "name": type.STRING
}).hasMany(this.Phone);

persist.connect({
  driver: 'sqlite3',
  filename: 'test.db',
  trace: true
}, function(err, connection) {
  Person.using(connection).all(function(err, people) {
    // people contains all the people
  });
});

如果我將this.Phone更改為Phone則上面的代碼在我的系統上運行不會出錯。

persist.connect “連接”到包含數據庫的test.db文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM