sub-manager-backend/objects/Entity.mjs

28 lines
604 B
JavaScript
Raw Normal View History

2023-09-07 09:39:09 +00:00
import dv from "./dv.mjs"
export default class Entity{
constructor(data){
if(data?.id){
if(!Number.isInteger(data.id)){throw new TypeError("id must be an integer!")}
this.id = data.id
}
}
async insert(db){
return db(this.table)
.insert(this)
}
async update(db){
return db(this.table)
.where('id',this.id)
.update(this)
}
async del(db){
if(!this?.id){throw new Error("cannot delete without an id!")}
return db(this.table)
.where('id',this.id)
this.del()
}
}
2023-09-06 16:26:15 +00:00