think-websql

0.0.14 • Public • Published

Add Package

npm install --save think-websql

Create File:

custom_definitions/think-websql.d.ts

alt tag

alt tag

alt tag

Example Typescript:

alt tag

'''

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);

        });

    });

}

}

'''

Readme

Keywords

Package Sidebar

Install

npm i think-websql

Weekly Downloads

13

Version

0.0.14

License

MIT

Last publish

Collaborators

  • felipe.almeida