Skip to content

Commit 86d2868

Browse files
authored
Merge pull request #1 from smooth-code/first-version
First version
2 parents 1c0d80e + 7552eb2 commit 86d2868

21 files changed

+4716
-0
lines changed

.babelrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"loose": true,
7+
"targets": {
8+
"node": "8.4"
9+
}
10+
}
11+
]
12+
],
13+
"plugins": ["transform-object-rest-spread", "transform-class-properties"]
14+
}

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
lib/

.eslintrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['airbnb-base', 'prettier'],
4+
parser: 'babel-eslint',
5+
parserOptions: {
6+
ecmaVersion: 2018,
7+
sourceType: 'module',
8+
},
9+
env: {
10+
node: true,
11+
},
12+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
lib/
3+
db/

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"semi": false
5+
}

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
notifications:
3+
email: false
4+
services:
5+
- postgresql
6+
addons:
7+
postgresql: '9.6'
8+
node_js:
9+
- 8
10+
- 9

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2018 Smooth Code
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Knex Scripts
2+
3+
Knex utilities to interact with Postgres database.
4+
5+
```
6+
npm install knex-scripts
7+
```
8+
9+
## Command Line Usage
10+
11+
```
12+
Usage: knex-scripts [options] [command]
13+
14+
15+
Options:
16+
17+
-V, --version output the version number
18+
--docker Use docker.
19+
--knexfile [path] Specify the knexfile path.
20+
--cwd [path] Specify the working directory.
21+
--env [name] environment, default: process.env.NODE_ENV || development
22+
-h, --help output usage information
23+
24+
25+
Commands:
26+
27+
create Create database.
28+
drop Drop database.
29+
dump Dump database.
30+
load Load database.
31+
truncate Truncate all tables.
32+
```
33+
34+
## Node API Usage
35+
36+
```js
37+
import knex from 'knex'
38+
import { truncate } from 'knex-scripts'
39+
import config from './knexfile'
40+
41+
// Truncate all database
42+
truncate({ getKnex: () => knex(config) })
43+
.then(() => console.log('Truncated'))
44+
.catch(console.error)
45+
```
46+
47+
## Configuration
48+
49+
```js
50+
// knexfile.js
51+
const config = {
52+
knexScripts: {
53+
docker: false,
54+
structurePath: 'db/structure.sql',
55+
},
56+
development: {
57+
client: 'postgresql',
58+
connection: {
59+
user: 'postgres',
60+
database: 'development',
61+
timezone: 'utc',
62+
},
63+
},
64+
}
65+
66+
module.exports = config
67+
```
68+
69+
## License
70+
71+
MIT

bin/knex-scripts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require('../lib/cli')

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2'
2+
services:
3+
postgres:
4+
image: postgres:9.6
5+
ports:
6+
- '5432:5432'
7+
volumes:
8+
- ${PWD}/db:${PWD}/db
9+
- ${PWD}/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d

0 commit comments

Comments
 (0)