A simple Bookshelfjs sample
Bookshelfjs ( http://bookshelfjs.org/ ) is a javascript ORM for Node.js This gist is a simple bookshelfjs sample.
Installation
- Clone this gist to a local folder
- Run
npm run build
in the local folder
Configuration
- This sample read the database config from
config.js
.
The default configuration is sqlite db client. The sqlite database file is "db.sqlite".
Database Schema
node index.js --createSchema
: Create the database schema. (The default SQL client is sqlite3. The schema is created by db_schema.js )- This simple sample creates 2 tables: MACHINE & MACHINE_STATUS
- MACHINE Table
+------------------------------------------------+
| ID [ PK, INTEGER, auto-increments ] |
|================================================|
| MACHINE_NAME [ varchar(255), UNIQUE, INDEX ] |
| HOST_NAME [ varchar(255) ] |
+------------------------------------------------+
- MACHINE_STATUS Table
+------------------------------------------------------+
| MACHINE_ID [ FK REFERENCES MACHINE(ID), INTEGER ] |
|======================================================|
| STATUS [ varchar(255) ] |
+------------------------------------------------------+
ORM
orm.js
: defineded all the Object-relational mappingorm_query.js
: A sample of query Machines data. (node index.js --ormQuery
for test it.)orm_update.js
: A sample of update Machines data. (node index.js --ormUpdate
for test it.)