Published
Edited
Apr 29, 2018
Insert cell
Insert cell
Insert cell
db = window.openDatabase("Grades", "1.0", "grades", 4000000)
Insert cell
Insert cell
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE bar (id INT PRIMARY KEY, Name TEXT,Score INTEGER)');
})
Insert cell
Insert cell
db.transaction(function (tx) {
tx.executeSql('INSERT INTO bar (id,Name,Score) VALUES (1,"Kimon",60)');
tx.executeSql('INSERT INTO bar (id,Name,Score) VALUES (2,"Joe",99)');
tx.executeSql('INSERT INTO bar (id,Name,Score) VALUES (3,"Janos",100)');
})
Insert cell
Insert cell
runQuery = (dbh,query,param,cb) => {
dbh.transaction(function (tx) {
tx.executeSql(query,param,cb);
})
}
Insert cell
Insert cell
runQuery(db,'INSERT INTO bar (id, Name) VALUES (3,"Ed")')
Insert cell
runQuery(db,'INSERT INTO bar (id, Name, Score) VALUES (4,"Ting",80)')
Insert cell
runQuery(db,'DELETE FROM bar WHERE Name = "Kimon"')
Insert cell
runQuery(db,'UPDATE bar SET Score=99 WHERE Name="Ed"')
Insert cell
Insert cell
runQuery(db,'SELECT * FROM bar',[], function (tx,results) {
var len = results.rows.length;
var i;
console.log(len);
for (i = 0; i < len; i++) {
console.log(results.rows.item(i).Name);
}
})

Insert cell
Insert cell
Insert cell
Insert cell
mydb = window.openDatabase("EMR", "1.0", "My WebSQL test database", 2*1024*1024)

Insert cell
Insert cell
mydb.transaction(function (tx) {
tx.executeSql('CREATE TABLE Patients (id INT PRIMARY KEY, mrn TEXT,firstname TEXT,lastname TEXT, dateofbirth INTEGER,address TEXT,city TEXT,state TEXT, zip TEXT)');
})
Insert cell
Insert cell
Insert cell
Insert cell

mydb.transaction(function (tx) {
tx.executeSql('INSERT INTO Patients (id,firstname,mrn,zip) VALUES (1,"A","1","11790")');
tx.executeSql('INSERT INTO Patients (id,firstname,mrn,zip) VALUES (2,"B","2","11790")');
tx.executeSql('INSERT INTO Patients (id,firstname,mrn,zip) VALUES (3,"C","3","11792")');
tx.executeSql('INSERT INTO Patients (id,firstname,mrn,zip) VALUES (4,"D","4","11790")');
tx.executeSql('INSERT INTO Patients (id,firstname,mrn,zip) VALUES (5,"E","5","11791")');
tx.executeSql('INSERT INTO Encounter (id,description,mrnofpatient) VALUES (1,"Cold","1")');
tx.executeSql('INSERT INTO Encounter (id,description,mrnofpatient) VALUES (2,"Fever","2")');
tx.executeSql('INSERT INTO Encounter (id,description,mrnofpatient) VALUES (3,"Flu","3")');
tx.executeSql('INSERT INTO Labs (id,value,mrnofpatient) VALUES (3,145,"1")');
tx.executeSql('INSERT INTO Labs (id,value,mrnofpatient) VALUES (2,155,"2")');
})

Insert cell
Insert cell
runQuery(mydb,'SELECT * FROM Patients',[], function (tx,results) {
var len = results.rows.length;
var i;
console.log(len);

for (i = 0; i < len; i++) {
console.log(results.rows.item(i).firstname);
console.log(results.rows.item(i).zip);
}
})
Insert cell
{
runQuery(mydb,'SELECT * FROM Patients INNER JOIN Encounter ON Patients.id = Encounter.id ',[], function (tx,results) {
var len = results.rows.length;
var i;
console.log(len);
for (i = 0; i < len; i++) {
console.log(results.rows.item(i));
}
})
return("Exercise 4b Code");
}
Insert cell
Insert cell
{
runQuery(mydb,'SELECT Labs.value,Encounter.mrnofpatient,Patients.id FROM ((Labs INNER JOIN Encounter ON Labs.mrnofpatient = Encounter.mrnofpatient) Encounter INNER JOIN Patients ON Encounter.id = Patients.id);',[], function (tx,results) {
var len = results.rows.length;
var i;
console.log(len);
for (i = 0; i < len; i++) {
console.log(results.rows.item(i));
}
})
return("Exercise 4c Code");
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more