Skip to content
This repository was archived by the owner on Feb 15, 2018. It is now read-only.

Commit

Permalink
added sqlite support (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
kc-dot-io authored Jun 6, 2017
1 parent 02a89d5 commit b905740
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/service/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
}
},
{
"name": "SQLite",
"checked": false,
"value": {
"template": "sqlite",
"require": "feathers-knex",
"deps": ["sqlite3", "feathers-knex"]
}
},
"name": "Mysql",
"checked": false,
"value": {
Expand All @@ -50,7 +58,6 @@
"deps": ["mysql", "feathers-knex"]
}
},

{
"name": "None",
"checked": false,
Expand Down
7 changes: 7 additions & 0 deletions src/service/templates/models/sqlite/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"prompts": {
"whenNot": "config.sqlite.db",
"name": "config.sqlite.db",
"description": "What database do you want to use?"
}
}
20 changes: 20 additions & 0 deletions src/service/templates/models/sqlite/templates/service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"require": "./{{options.name}}.model",
"options": [{
"db": "config.{{answers.model.template}}.db",
"table":"{{options.name}}",
"paginate": "config.paginate"
}],
"before":{
"all": [{ "require": "./hooks/before", "options": [] }]
},
"after":{
"all": [{ "require": "./hooks/after", "options": [] }]
},
"filters": {
"all": {
"require": "./filters/default",
"options": []
}
}
}
41 changes: 41 additions & 0 deletions src/service/templates/models/sqlite/templates/service.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const client = require('knex');
const service = require('feathers-knex');
const user = require("os").userInfo().username;

export default function (options) {

const debug = require('debug')(`feathers:service:${options.table}:sqlite`)

const model = client({
client: 'sqlite3',
connection: {
filename: './' + (options.db || 'feathers') + '.sqlite'
}
});

var sqlite = service({
Model: model,
name: options.table,
paginate: options.paginate
});

// <!-- init block
return sqlite
.init({}, (table) => {
// define your schema here
debug(`created ${table._tableName} table`);
table.increments('id');
table.string('text');
table.boolean('complete');
})
.then(() => {
console.log(`SQLite ${options.db}.${options.table} has been created.`);
console.log(`You should remove the "init block" in ${__filename} now.`);
return sqlite;
})
.catch(err => console.log('SQLite init failed:', err));
// init block -->

return sqlite; // uncomment, when removing init block

};

0 comments on commit b905740

Please sign in to comment.