knexjs ( http://knexjs.org/ ) is SQL query builder.
This gist is a simple knexjs sample.
- Clone this gist to a local folder
- Run
npm run build
in the local folder
node index.js --createSchema
: Create the database schema. (The default SQL client is sqlite3. The schema is created by db_schema.js )node index.js --update
: Run INSERT & UPDATE & TRANSACTION Samples (db_update.js).node inex.js --query
: Run SELECT samples (db_query.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) ] |
+------------------------------------------------------+
- This sample read the database config from
config.js
.
The default configuration is sqlite db client. The sqlite database file is "db.sqlite".