# coal **Repository Path**: huyinghuan/coal ## Basic Information - **Project Name**: coal - **Description**: Simple ORM base on knexjs - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2015-01-29 - **Last Updated**: 2024-12-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README coal ---------------- ORM Base on [knexjs](http://knexjs.org) ## Install ```shell npm install coal --save ``` ## Getting start ### database configure configure.coffee ```coffeescript module.exports = database: client: 'mysql' connection: host: 'localhost' user: 'root' password: '123456' database: 'test_coal' schema: 'schame' ``` init tables ```coffeescript Coal = require 'coal' config = require './config' coal = new Coal(config, true) ``` > you need install database driver like: npm install mysql or npm install sqlite3 ## API ### Coal(config, isBuildTable) @config: the database config. @isBuildTable: Is auto update table or create table. default is false. > if use in product environment, please init database schema structure at first. > and then set isBuildTable as false. > if you are developing, set it be true. let coal auto check the schema change, and > apply in database. ### coal.prepareSchema() build table use schemas and check the schema change then apply in database. if in product, just run once. use combine with ```Coal(config, isBuildTable)``` ### coal.Model(tableName) return an instance of Model. ### Model.save(obj) return promises ### Model.update(obj[, where]) ```where``` argument is optional. it must be array, like ["id", "=", 1] return promises ### Model.find(fields[, where]) param ```fields``` must be array. return promises ### Model.findOne(fields[, where]) the same with up. ### Model.delOne(key, value) return promises ### Model.delMul(key, valueArray) return promises ### Model.sql(sql) param ```sql``` is a sql string. like ```select * from people``` return promises ### Model.table() return a knex instance. ## Sample see the directory ```sample``` ## LICENSE MIT ## History v0.0.2 support simple operate function. like: save, update, delOne, delMul, sql and so on v0.0.1 init coal