本文整理汇总了TypeScript中ionic-native.SQLite类的典型用法代码示例。如果您正苦于以下问题:TypeScript SQLite类的具体用法?TypeScript SQLite怎么用?TypeScript SQLite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SQLite类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(private navController: NavController, private platform: Platform) {
this.database = new SQLite();
this.database.openDatabase({name: "data.db", location: "default"}).then(() => {
//this.refresh();
}, (error) => {
console.log("ERROR: ", error);
});
}
示例2: tests
}).then(() => {
this.db.executeSql('CREATE TABLE IF NOT EXISTS tests (id INTEGER PRIMARY KEY AUTOINCREMENT, name Text, user_id Text, date TIMESTAMP)', {}).then((data) =>{
console.log("TESTS TABLE CREATED", JSON.stringify(data.res));
}, (error) => {
console.log("Error creating tests table", JSON.stringify(error.err));
});
this.db.executeSql('CREATE TABLE IF NOT EXISTS test_sections (id INTEGER PRIMARY KEY AUTOINCREMENT, section INTEGER, question TEXT, score TEXT, question_id INTEGER, test_id INTEGER, CONSTRAINT composite_id UNIQUE (section, question_id, test_id))', {}).then((data) =>{
console.log("TEST SECTIONS TABLE CREATED", JSON.stringify(data.res));
}, (error) => {
console.log("Error creating tests table", JSON.stringify(error.err));
});
}, (err) => {
示例3: add
public add() {
this.database.executeSql("INSERT INTO user (firstname, lastname) VALUES (?, ?)", ['Alejandro', 'Romero']).then((data) => {
console.log("INSERTED: " + JSON.stringify(data));
}, (error) => {
console.log("ERROR: " + JSON.stringify(error));
});
}
示例4: createTable
createTable(){
let sql = 'CREATE TABLE IF NOT EXISTS product(' +
'id INTEGER PRIMARY KEY AUTOINCREMENT, ' +
'type TEXT, ' +
'quantity INTEGER, ' +
'price TEXT, ' +
'name TEXT)';
return this.db.executeSql(sql, []);
}
示例5: getAll
getAll(){
let query = 'SELECT * FROM product';
return this.db.executeSql(query, [])
.then(response => {
let products = [];
for (let index = 0; index < response.rows.length; index++) {
products.push(response.rows.item(index));
}
return Promise.resolve(products);
})
}
示例6: refresh
public refresh() {
this.database.executeSql("SELECT * FROM user", {}).then((data) => {
this.user = [];
if(data.rows.length > 0) {
for(var i = 0; i < data.rows.length; i++) {
this.user.push({firstname: data.rows.item(i).firstname, lastname: data.rows.item(i).lastname});
}
}
}, (error) => {
console.log("ERROR: " + JSON.stringify(error));
});
}
示例7: deleteTestByUser
public deleteTestByUser(user_id: number) {
let sql = 'DELETE FROM tests WHERE user_id = ?';
return this.db.executeSql(sql, [user_id]);
}
示例8: update
// Update an existing note with a given ID
public update(test: Test) {
let sql = 'UPDATE test_sections SET score = ? WHERE section = ? AND question_id = ? AND test_id = ?';
return this.db.executeSql(sql, [test.score, test.section, test.question_id, test.test_id]);
}
示例9: deleteAnswers
public deleteAnswers(id: number){
let sql = 'DELETE FROM test_sections WHERE test_id = ?';
return this.db.executeSql(sql, [id]);
}