1
- [ ![ wercker status] ( https://app.wercker.com/status/74461495df913d3524f2a11c9db4cd9b/s/master " wercker status ")] ( https://app.wercker.com/project/bykey/74461495df913d3524f2a11c9db4cd9b )
2
- [ ![ Code Climate] ( https://codeclimate.com/github/node-modli/modli-postgres/badges/gpa.svg )] ( https://codeclimate.com/github/node-modli/modli-postgres )
3
- [ ![ Test Coverage] ( https://codeclimate.com/github/node-modli/modli-postgres/badges/coverage.svg )] ( https://codeclimate.com/github/node-modli/modli-postgres/coverage )
4
-
5
1
# Modli - PostgreSQL Adapter
6
2
7
3
This module provides adapter for the [ PostgreSQL] ( http://www.postgresql.org/ )
@@ -19,20 +15,20 @@ When defining a property which will utilize the adapter it is required that a
19
15
` tableName ` be supplied:
20
16
21
17
``` javascript
22
- import { model , adapter , Joi , use } from ' modli' ;
23
- import postgres from ' modli-postgres' ;
18
+ const { model , adapter , obey , use } = require ( ' modli' )
19
+ const postgres from require ( 'modli -postgres ')
24
20
25
21
model .add ({
26
22
name: ' foo' ,
27
23
version: 1 ,
28
24
tableName: ' tblFoo'
29
- schema: {
30
- id: Joi . number (). integer () ,
31
- fname: Joi . string (). min ( 3 ). max ( 30 ) ,
32
- lname: Joi . string (). min ( 3 ). max ( 30 ) ,
33
- email: Joi . string (). email (). min ( 3 ). max ( 254 ). required ()
34
- }
35
- });
25
+ schema: obey . model ( {
26
+ id: { type : ' number' } ,
27
+ fname: { type : ' string' , min: 3 , max: 30 } ,
28
+ lname: { type : ' string' , min: 3 , max: 30 } ,
29
+ email: { type : ' email' , min: 3 , max: 254 , required: true }
30
+ })
31
+ })
36
32
```
37
33
38
34
Then add the adapter as per usual with the following config object structure:
@@ -43,18 +39,18 @@ adapter.add({
43
39
source: postgres
44
40
config: {
45
41
host: {HOST_IP },
46
- username : {USERNAME },
42
+ user : {USERNAME },
47
43
password: {PASSWORD },
48
44
database: {DATABASE }
49
45
}
50
- });
46
+ })
51
47
```
52
48
53
49
You can then use the adapter with a model via:
54
50
55
51
``` javascript
56
52
// Use(MODEL, ADAPTER)
57
- const postgresTest = use (' foo' , ' postgresFoo' );
53
+ const postgresTest = use (' foo' , ' postgresFoo' )
58
54
```
59
55
60
56
## Methods
@@ -68,7 +64,7 @@ Allows for passing standard PostgreSQL queries:
68
64
``` javascript
69
65
postgresTest .query (' SELECT * FROM tblFoo' )
70
66
.then (/* ...*/ )
71
- .catch (/* ...*/ );
67
+ .catch (/* ...*/ )
72
68
```
73
69
74
70
### ` createTable `
@@ -83,7 +79,7 @@ postgresTest.createTable({
83
79
' email' : [ ' varchar(255)' ]
84
80
})
85
81
.then (/* ...*/ )
86
- .catch (/* ...*/ );
82
+ .catch (/* ...*/ )
87
83
```
88
84
89
85
### ` create `
@@ -97,7 +93,7 @@ postgresTest.create({
97
93
email: ' jsmith@gmail.com'
98
94
})
99
95
.then (/* ...*/ )
100
- .catch (/* ...*/ );
96
+ .catch (/* ...*/ )
101
97
```
102
98
103
99
### ` read `
@@ -107,7 +103,7 @@ Runs a `SELECT` with optional `WHERE`:
107
103
``` javascript
108
104
postgresTest .read (' fname=\' John\' ' )
109
105
.then (/* ...*/ )
110
- .catch (/* ...*/ );
106
+ .catch (/* ...*/ )
111
107
```
112
108
113
109
### ` update `
@@ -120,7 +116,7 @@ postgresTest.update('fname=\'John\'', {
120
116
email: ' bsmith@gmail.com'
121
117
})
122
118
.then (/* ...*/ )
123
- .catch (/* ...*/ );
119
+ .catch (/* ...*/ )
124
120
```
125
121
126
122
### ` delete `
@@ -130,7 +126,7 @@ Deletes record(s) based on query:
130
126
``` javascript
131
127
postgresTest .delete (' fname=\' Bob\' ' )
132
128
.then (/* ...*/ )
133
- .catch (/* ...*/ );
129
+ .catch (/* ...*/ )
134
130
```
135
131
136
132
### ` extend `
@@ -140,12 +136,12 @@ Extends the adapter to allow for custom methods:
140
136
``` javascript
141
137
postgresTest .extend (' myMethod' , () => {
142
138
/* ...*/
143
- });
139
+ })
144
140
```
145
141
146
142
## Development
147
143
148
- The PostgreSQL adapter requires the following enviroment variables to be set for
144
+ The PostgreSQL adapter requires the following environment variables to be set for
149
145
running the tests. These should be associated with the PostgreSQL instance running
150
146
locally.
151
147
@@ -159,51 +155,10 @@ MODLI_POSTGRES_DATABASE
159
155
This repository includes a base container config for running locally which is
160
156
located in the [ /docker] ( /docker ) directory.
161
157
162
- ## Makefile and Scripts
163
-
164
- A ` Makefile ` is included for managing build and install tasks. The commands are
165
- then referenced in the ` package.json ` ` scripts ` if that is the preferred
166
- task method:
167
-
168
- * ` all ` (default) will run all build tasks
169
- * ` start ` will run the main script
170
- * ` clean ` will remove the ` /node_modules ` directories
171
- * ` build ` will transpile ES2015 code in ` /src ` to ` /build `
172
- * ` test ` will run all spec files in ` /test/src `
173
- * ` test-cover ` will run code coverage on all tests
174
- * ` lint ` will lint all files in ` /src `
175
-
176
- ## Testing
177
-
178
- Running ` make test ` will run the full test suite. Since adapters require a data
179
- source if one is not configured the tests will fail. To counter this tests are
180
- able to be broken up.
181
-
182
- ** Test Inidividual File**
183
-
184
- An individual spec can be run by specifying the ` FILE ` . This is convenient when
185
- working on an individual adapter.
186
-
187
- ```
188
- make test FILE=some.spec.js
189
- ```
190
-
191
- The ` FILE ` is relative to the ` test/src/ ` directory.
192
-
193
- ** Deploys**
194
-
195
- For deploying releases, the ` deploy TAG={VERSION} ` can be used where ` VERSION ` can be:
196
-
197
- ```
198
- <newversion> | major | minor | patch | premajor
199
- ```
200
-
201
- Both ` make {COMMAND} ` and ` npm run {COMMAND} ` work for any of the above commands.
202
-
203
158
## License
204
159
205
160
Modli-Postgres is licensed under the MIT license. Please see ` LICENSE.txt ` for full details.
206
161
207
162
## Credits
208
163
209
- Modli-Postgres was designed and created at [ TechnologyAdvice] ( http://www.technologyadvice.com ) .
164
+ Modli-Postgres was designed and created at [ TechnologyAdvice] ( http://www.technologyadvice.com ) .
0 commit comments