2
我有以下2種方法來創建鈦的Db表。如何使用模型在鈦中創建數據庫表?
方法1 - 使用鈦代碼中的查詢創建sqlite數據庫。像Ti.Database.open(「DBName」);然後使用SQLite查詢
var db = Ti.Database.open('DBName');
db.execute('CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT)');
它的做工精細創建表。
,但我需要知道如何使用模型
方法2創建表 - 創建數據庫Ti.Database.open( 「數據庫名」);
創建模型book.js這裏是代碼
exports.definition = {
config: {
"columns": {
"id":"TEXT PRIMARY KEY",
"title":"TEXT ",
"author":"TEXT",
},
adapter: {
type: "sql",
collection_name: "book"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// extended functions and properties go here
});
return Collection;
}
};
現在我是有點混亂,使用模型創建表。
請幫助和指導我創建表。