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

SQLite Support #60

Merged
merged 2 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

};