Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views2 pages

DB Functions

Uploaded by

Laszlo Ross
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

DB Functions

Uploaded by

Laszlo Ross
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

[auth]

create account
login
logout
reset password
enter password
check each request

[db]
create table
change name
add/remove column
- all inputs
- select
- related, single + many
delete table

maybe views

[domain objects]
get all
query
insert
update
delete (soft)

let db = {}

db.init = name => {


this.dbase = new Database(name)
}

db._create_q_string = len => {


let q_array = new Array(len)
q_array.fill('?')
let str = q_array.join(', ')
return str
}

db.get = (table, id) => {


let id_field = `[${table}_id]`
let sql = `select * from [${table}] where ${id_field} = ?`
let item = db.query(sql).get(id)
return item
}

db.insert = (db, table, obj) => {


let cols = []
let vals = []

for (let [k, v] of obj) {


cols.push(`[${k}]`)
vals.push(y)
}

let colString = cols.join(', ')


let qString = _create_q_string(vals)
let sql = `insert into [$table] (${colString}) values (qString)`
db.prepare(sql).run(...vals)
}

You might also like