0.1.1 • Published 4 years ago
@im_banana/databasetool v0.1.1
Database Tool
With this tool you can create json database easly
installation
npm install @im_banana/databasetoolExample
const databasetool = require("@im_banana/databasetool")
// setup table
// table name make it a table class
// | |
// v v
class User extends databasetool.Table {
constructor(name, age) {
// data to store
this.data = {
name,
age
}
}
}
// you can create more :D
class Dog extends databasetool.Table {
constructor(name, age) {
this.data = {
name,
age
}
}
}
// make sure you register all
User.register()
Dog.register()
// create new database
// database name (file name too)
// |
// v
const db = new dbtool.Database("data")
// add the tables to the database
db.addTable(User)
db.addTable(Dog)
// make the database file and data
db.registerDatabase()
// Wait for the database to register
setTimeout(() => {
// create new user table
db.create(new User("test", 3))
// save the database file
db.commit()
}, 5000)API
const databasetool = require("@im_banana/databasetool")databasetool.Table
main class for database table.
example
class User extends databasetool.Table {
constructor(name, age) {
// data to store
this.data = {
name,
age
}
}
}\.register()
register the table in the system.
example
User.register()\.find(\, \)
Find table instance in the database.
example
User.find(db, {id: 0})options
options for the data from the table + id
databasetool.Database(\)
create new database.
example
const db = new databasetool.Database("database")\.addTable(\)
add a table to the data base.
example
db.addTable(User)\.create(\)
create new instance table in the database.
example
db.create(new User("name", 0))\.delete(\)
delete table instance from the database.
example
db.delete(new User("name", 0))\.change(\<new_table>, \<old_table>)
change table instance in the database.
example
db.create(new User("name", 0))\.commit()
save the database.
example
db.commit()