jg-orm
v0.1.3
Published
orm
Downloads
26
Readme
Installation
npm i jg-orm
Functional
- #init
- define models and sql init
- #Select
- select rows
- #SelectOne
- select one row
- #Delete
- remove rows
- #Save
- update or insert row
- #Insert
- insert row
- #Query
- use sql query string
import sql from 'jg-orm'
const $sql = await sql.init({
sync: true,
options
})
// "result" is Array
const result = await sql.Select({
table: 'table',
columns: '*',
where: {
id: 1
}
})
// "result" is Object
const result = await sql.SelectOne({
table: 'table',
columns: '*',
where: {
id: 1
}
})
const result = await sql.Delete({
table: 'table',
where: {
id: 1
}
})
const result = await sql.Save({
table: 'table',
values: {
name: 'User'
},
// if no "where", call Insert
where: {
id: 1
}
})
const result = await sql.Insert({
table: 'table',
values: {
name: 'User'
}
})
const result = await sql.Query('SELECT * FROM [table] WHERE id=1')
Example settings, options
#sqlite
npm i [email protected]
{
path: 'server/data/models',
options: {
dialect: 'sqlite',
storage: `server/data/db.sqlite`,
host: 'localhost'
}
}