Skip to content

snake-npms/snake-orm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

snake-orm

npm Support Sqlite, Mysql

More Info Please Look the Doc

Install

$ npm install snake-orm -S
# And one of the following:
$ npm install --save mysql2
$ npm install --save sqlite3

Easy use like below:

await User.joins('wallet').where({username: 'zhangsan'}).where('wallets.amount > ?', 100).limit(10).offset(3)

Usage

let SnackeOrm = require('snake-orm')
SnakeOrm.getOrCreateSnakeOrmProxy(database, username, password, {
    dialect: ['mysql'|'sqlite3'], 
    host: 'localhost', 
    logger: true
  })

# Create Model
const { SnakeModel } = SnackeOrm
class User extends SnakeModel {
    # default SnakeOrmProxy database
	#static get database () {
	#    return 'database_test'
	#}
	
	# default class name plural
	# static get table () {
	# 	return 'users'
	# }
	
	constructor () {
		super(...arguments)
	}
}
module.exports = User

Methods

Class Methods

  • find (valueOfPrimaryKey) -> it's [Bomb Method]
  • findBy (options)
  • where (options, ...args)
  • not (options)
  • select (fields)
  • order (options)
  • group (fields)
  • having (options, ...args)
  • limit (limit)
  • offset (offset)
  • paginate (page, perPage)
  • count ()
  • sum (field)
  • avg (field)
  • min (field)
  • max (field)
  • withTransaction(blockAfn)
  • findOrCreateBy (object, blockAfn)
  • create(object, blockAfn)
  • updateAll(object)
  • destroyAll()
  • destroyAllTableData()

Instance Methods

  • update(object, blockAfn)
  • save()
  • increment(field, value)
  • decrement(field, value)
  • destroy()

Log Sql

please set debug or logger -> true

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages