How should i create multiple tables at a time in Sqlite db in Nativescript with angular?


#1

I have created one service, Within that i have created one method named ‘createDb()’. In my component, I have injected this service. Inside the component’s ngOnInit lifecycle, I have called that createDb() method from service. That time table also created. Is this the proper way to create db and multiple tables in sqlite database in nativescript with angular2 framework?

Inside createDb() function, i tried to create multiple tables as given below.

`(new Sqlite(“Gaugingticket.db”)).then(db => {

database = db;
db.execSQL(“CREATE TABLE IF NOT EXISTS vinfoo (id INTEGER PRIMARY KEY AUTOINCREMENT, vname TEXT, location TEXT, openingdate NUMERIC, typeserialgaugingtape TEXT, draftfwd NUMERIC, draftaft NUMERIC, trim TEXT, list TEXT)”);

db.execSQL(“CREATE TABLE IF NOT EXISTS ogauge (id INTEGER PRIMARY KEY AUTOINCREMENT, vname TEXT, openingdate NUMERIC, tankname TEXT, grade TEXT, refht REAL, obssdgullage REAL,h20 INTEGER,temp INTEGER)”);

db.execSQL(“CREATE TABLE IF NOT EXISTS cgauge ( id INTEGER PRIMARY KEY AUTOINCREMENT, vname TEXT,closingdate NUMERIC, tankname TEXT, grade TEXT, refht REAL, obssdgullage REAL,h20 INTEGER,temp INTEGER)”);

db.execSQL(“CREATE TABLE IF NOT EXISTS ssummary (id INTEGER PRIMARY KEY AUTOINCREMENT,vname TEXT, remarks TEXT, referenceheight TEXT, calibratedby TEXT, calibrateddate NUMERIC, waterpaste TEXT, thermotypesrno NUMERIC)”);

db.execSQL(“CREATE TABLE IF NOT EXISTS vvinfoo (id INTEGER PRIMARY KEY AUTOINCREMENT, vname TEXT, location TEXT, openingdate NUMERIC, typeserialgaugingtape TEXT, draftfwd NUMERIC, draftaft NUMERIC, trim TEXT, list TEXT)”);

db.execSQL(“CREATE TABLE IF NOT EXISTS oogauge (id INTEGER PRIMARY KEY AUTOINCREMENT, vname TEXT, openingdate NUMERIC, tankname TEXT, grade TEXT, refht REAL, obssdgullage REAL,h20 INTEGER,temp INTEGER)”);

db.execSQL(“CREATE TABLE IF NOT EXISTS ccgauge ( id INTEGER PRIMARY KEY AUTOINCREMENT, vname TEXT,closingdate NUMERIC, tankname TEXT, grade TEXT, refht REAL, obssdgullage REAL,h20 INTEGER,temp INTEGER)”);

db.execSQL(“CREATE TABLE IF NOT EXISTS sssummary (id INTEGER PRIMARY KEY AUTOINCREMENT,vname TEXT, remarks TEXT, referenceheight TEXT, calibratedby TEXT, calibrateddate NUMERIC, waterpaste TEXT, thermotypesrno NUMERIC)”);

});}`