This repository was archived by the owner on Feb 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
src/service/templates/models/sqlite/templates/service.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
src/service/templates/models/sqlite/templates/service.model.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
}; |