think-websql
v0.0.14
Published
A websql package for a typescript file
Downloads
2
Readme
#Add Package
npm install --save think-websql
#Create File:
custom_definitions/think-websql.d.ts
#Example Typescript:
'''
import ThinkWebSql = require("think-websql");
@Injectable()
export class UserData {
db: any;
constructor() {
this.db = ThinkWebSql.WindowDatabase.openDatabase('thinkdb', '1.0', 'DB ThinkApp', 2 * 1024 * 1024);
this.db.transaction(function (tx: any){
tx.executeSql('CREATE TABLE IF NOT EXISTS user (id unique, username, password, hasLoggedIn, defaultPassword);');
tx.executeSql('INSERT INTO user (id, username, password, hasLoggedIn, defaultPassword) values (1, "thinker", "120130", "false", "102030");');
});
}
login(user: User) {
return new Promise((resolve, reject) => {
this.db.transaction(function (tx: any) {
tx.executeSql("SELECT password from user WHERE username = '" + user.username.toLowerCase() + "'", [], function (tx: any, results: any) {
if (results.rows.length > 0) {
if (results.rows.item(0).password == user.password)
resolve(true);
}
resolve(false);
}, null);
});
});
}
}
'''