Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

ionicsqlite added #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions backends/ionicsqlite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const frappe = require('frappejs');
const Database = require('frappejs/backends/database');
const Observable = require('frappejs/utils/observable');

module.exports = class IonicSqlite extends Database{
constructor() {
super();
}

addOne(doctype,data,num,db){
var y = '('+'?, '.repeat(num-1)+'?)';
console.log('insert data: ',data);
return db.executeSql(`INSERT INTO ${doctype} VALUES ${y}`,data).then(res => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when and how db variable is initialized?

console.log("Inserted entry!!!");
return res;
})
.catch(err => {
console.log('error: ', err);
});
}

getAll(doctype,condtion,db){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't change the function signature of getAll it should only take parameters as provided by the base Database class

return db.executeSql(`SELECT * FROM ${doctype} where ${condtion}`, []).then(data => {
let items = [];
if (data.rows.length > 0) {
for (var i = 0; i < data.rows.length; i++) {
items.push(data.rows.item(i));
}
}
console.log("All items received!");
return items;
}, err => {
console.log('Error: ', err);
return [];
})
}

deleteOne(doctype,old_name,db){
return db.executeSql(`DELETE FROM ${doctype} WHERE name=?`,[old_name])
.then(res => {
console.log("Deleted!");
return res;
})
.catch(err => {
console.log('error: ', err);
});
}

getOne(doctype,name,db){
return this.database.executeSql(`SELECT * FROM ${doctype} WHERE name=?`,[name])
.then(data => {
//console.log(data.rows.length);
let temp = data.rows.item(0);
console.log("One value received");
return temp;
})
.catch(err => {
console.log('error: ',err);
});
}

}