This repository has been archived by the owner on May 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
7 changed files
with
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
const NeedName = require('./needName'); | ||
|
||
module.exports = class extends NeedName { | ||
prompting() { | ||
return this.ask; | ||
} | ||
|
||
writing() { | ||
const name = _.lowerFirst(this.getName); | ||
|
||
this.writeFiles({ | ||
'db/field.js': [`bin/fields/${name}.js`, { | ||
name | ||
}] | ||
}); | ||
} | ||
}; |
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,15 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
users: (db, type = 'sqlite') => ( | ||
db.create('<%= name %>', { | ||
id: 'text PRIMARY KEY NOT NULL' | ||
}) | ||
), | ||
|
||
create_user: id => db => ( | ||
db.insert('<%= name %>', { | ||
id | ||
}) | ||
) | ||
}; |
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,37 @@ | ||
'use strict'; | ||
|
||
const Base = require('./../base'); | ||
|
||
module.exports = class extends Base { | ||
initializing() { | ||
this.addDependencies([ | ||
'babel-polyfill', | ||
'cat-utils', | ||
'sqlite3' | ||
]); | ||
} | ||
|
||
default() { | ||
if(!this.config.get('cat')) | ||
this.composeWith(require.resolve('./../add'), { | ||
item: 'db', | ||
name: 'users' | ||
}); | ||
} | ||
|
||
writing() { | ||
this.writePkgScripts({ | ||
db: 'node ./bin/db.js', | ||
'db-shell': 'db-shell' | ||
}); | ||
|
||
this.writeFiles({ | ||
'fields.js': 'bin/fields/index.js', | ||
'db.js': 'bin/db.js' | ||
}); | ||
} | ||
|
||
install() { | ||
this.addInstall(); | ||
} | ||
} |
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,11 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const sqlite = require('cat-utils/lib/sqlite').default; | ||
|
||
const fields = require('./fields'); | ||
const db = new sqlite(); | ||
|
||
db.sqlite.serialize(() => { | ||
fields(db); | ||
}); |
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,47 @@ | ||
'use strict'; | ||
|
||
require('babel-polyfill'); | ||
const process = require('process'); | ||
|
||
const {users, create_user} = require('./users'); | ||
|
||
module.exports = async (db, type = 'sqlite') => { | ||
const tables = { | ||
users | ||
}; | ||
const create_data = {}; | ||
const choices = process.argv.length === 2 ? Object.keys(tables) : process.argv.slice(2); | ||
const choice_data = []; | ||
|
||
try { | ||
await Promise.all( | ||
choices.map(key => { | ||
if(create_data[key]) | ||
choice_data.push(create_data[key]); | ||
|
||
if(tables[key]) | ||
return tables[key](db, type); | ||
|
||
throw new Error(`"${key}" is not in tables.`); | ||
}) | ||
); | ||
|
||
await choice_data.map(create_func => create_func(db)); | ||
|
||
switch(type) { | ||
case 'sqlite': | ||
if(choices.includes('users')) { | ||
const user_id = `'363a5f9b-7e93-4f8d-9f1a-a3941fc0905d'`; | ||
|
||
if(await create_user(user_id)(db)) | ||
console.log(`test user id: ${user_id}`) | ||
} | ||
break; | ||
} | ||
|
||
console.log('done'); | ||
process.exit(); | ||
} catch(e) { | ||
console.log(e); | ||
} | ||
}; |
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