Skip to content

Commit 6416c6c

Browse files
committed
feat: implement custom orm on top of knex.js (#65)
* feat: implement custom orm on top of Knex.js * feat: write operations with custom orm * test: add fixutres to match new table names * feat: add model hooks * feat: use primaryKey variable instead of id * refactor: move model initializer to a private Database util * refactor: set route props in constructor * refactor: set controller props in constructor * feat: dirty checking for models and object model refactors * feat: migrations * fix: remove extra deps from test apps package.json * chore: remove empty hook from post model in test-app * feat: more db commands including seeding * refactor: replace range with literall array when small enough * feat: update all generators to use optional attrs * test: update helper to use npm linked version of lux * feat: validations * fix: change example app lux imports to point to npm package * fix: load knex and db driver from application not lux * test: test against node 4 * test: test against mysql, sqlite, and postgres test: fix broken .travis.yml syntax test: fix postgres user for test-app test env fix: don't use connection pool for tests test: another attempt to get postgres working on travis test: change DB=postgres -> DB=postgresql test: remove services section and custom pg version from travis.yml test: debug postgres travis build test: uncomment postgresql matrix test: continued postgresql build debugging test: continued postgresql build debugging test: continued postgresql build debugging test: continued postgresql build debugging test: continued postgresql build debugging test: continued postgresql build debugging test: run tests against all matrixes test: add all verion tests back to travis.yml * refactor: do not run npm install for test-app in gulp task * refactor: add config option to disable/enable logging * fix: lux d resource cmd does not remove resource from routes.js * feat: add --database option to lux new cmd * test: default to sqlite if DB is not set * chore: update dependencies * chore: bump version to 0.0.1-beta.8 * fix: move eslint version back to 2.8.0 * feat: update package.json template and test-app dependencies
1 parent d117376 commit 6416c6c

102 files changed

Lines changed: 2837 additions & 1146 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
},
88
"globals": {
99
"Map": true,
10+
"Set": true,
1011
"Promise": true,
1112
"Symbol": true,
1213
"WeakMap": true,
1314
"before": true,
15+
"after": true,
1416
"describe": true,
1517
"it": true
1618
},

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
node_modules/
88

99
# misc
10+
*.sqlite
1011
*.DS_Store
1112

1213
# logs

.travis.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,40 @@ sudo: true
33
language: node_js
44

55
node_js:
6-
- "6"
7-
- "5"
6+
- '4'
7+
- '5'
8+
- '6'
89

910
services:
1011
- mysql
12+
- postgresql
1113

1214
before_script:
13-
- cat test/fixtures/data.sql | mysql -u travis
14-
- npm install -g gulp
15+
- mysql -e 'create database lux_test;'
16+
- psql -c 'create database lux_test;' -U postgres
17+
- touch test/test-app/db/lux_test_test.sqlite
18+
- cd test/test-app && npm install && cd ../../
1519
- npm link
1620

1721
env:
1822
global:
1923
- CXX=g++-4.8
2024
- NODE_ENV=test
2125

26+
matrix:
27+
- DB=mysql
28+
- DB=sqlite
29+
- DB=postgresql
30+
2231
addons:
2332
apt:
2433
sources:
2534
- ubuntu-toolchain-r-test
2635

2736
packages:
2837
- g++-4.8
38+
- gcc-4.8
39+
- postgresql-9.4
40+
41+
notifications:
42+
email: false

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,8 @@ cat test/fixtures/data.sql | mysql -u root -p
167167
npm test
168168
```
169169

170-
*Note:* Make sure you have MySQL installed and accessible on port `3306`.
171-
172170
## Useful Links
173171

174172
* [JSON API](http://jsonapi.org/)
175-
* [node-orm2](http://dresende.github.io/node-orm2/)
173+
* [Knex.js](http://knexjs.org/)
176174
* [Chai](http://chaijs.com/) / [Mocha](http://mochajs.org/)

examples/todo/app/models/task-list.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ class TaskList extends Model {
77
defaultValue: 'To Do'
88
}
99
};
10+
11+
static hasMany = {
12+
tasks: {
13+
model: 'task',
14+
inverse: 'lists'
15+
}
16+
};
1017
}
1118

1219
export default TaskList;

examples/todo/app/models/task.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class Task extends Model {
1818
}
1919
};
2020

21-
static hasOne = {
21+
static belongsTo = {
2222
list: {
2323
model: 'task-list',
24-
reverse: 'tasks'
24+
inverse: 'tasks'
2525
}
2626
};
2727
}

gulpfile.babel.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import mocha from 'gulp-mocha';
44
import eslint from 'gulp-eslint';
55
import uglify from 'gulp-uglify';
66

7-
import exec from './src/packages/cli/utils/exec';
87
import rmrf from './src/packages/cli/utils/rmrf';
98

109
gulp.task('clean', () => {
@@ -18,20 +17,14 @@ gulp.task('build', ['lint', 'clean'], () => {
1817
.pipe(gulp.dest('dist'));
1918
});
2019

21-
gulp.task('build:test', ['build'], () => {
22-
return exec('npm install', {
23-
cwd: `${__dirname}/test/test-app`
24-
});
25-
});
26-
2720
gulp.task('lint', () => {
2821
return gulp.src('src/**/*.js')
2922
.pipe(eslint())
3023
.pipe(eslint.format())
3124
.pipe(eslint.failAfterError());
3225
});
3326

34-
gulp.task('test', ['build:test'], () => {
27+
gulp.task('test', ['build'], () => {
3528
return gulp.src([
3629
'test/helper.js',
3730
'test/unit/**/*.js',
@@ -40,7 +33,7 @@ gulp.task('test', ['build:test'], () => {
4033
.pipe(
4134
mocha({
4235
bail: true,
43-
timeout: 600000,
36+
timeout: 60000,
4437
require: [
4538
'babel-core/register'
4639
]

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lux-framework",
3-
"version": "0.0.1-beta.7",
3+
"version": "0.0.1-beta.8",
44
"description": "A MVC style Node.js framework for building lightning fast JSON APIs",
55
"repository": "https://github.com/postlight/lux",
66
"main": "dist/index.js",
@@ -24,14 +24,13 @@
2424
"commander": "2.9.0",
2525
"inflection": "1.10.0",
2626
"moment": "2.13.0",
27-
"ora": "0.2.1",
28-
"orm": "2.1.30"
27+
"ora": "0.2.1"
2928
},
3029
"devDependencies": {
31-
"babel-core": "6.7.7",
32-
"babel-eslint": "6.0.3",
30+
"babel-core": "6.8.0",
31+
"babel-eslint": "6.0.4",
3332
"babel-plugin-transform-decorators-legacy": "1.3.4",
34-
"babel-plugin-transform-runtime": "6.7.5",
33+
"babel-plugin-transform-runtime": "6.8.0",
3534
"babel-preset-es2015": "6.6.0",
3635
"babel-preset-stage-1": "6.5.0",
3736
"chai": "3.5.0",
@@ -42,7 +41,6 @@
4241
"gulp-mocha": "2.2.0",
4342
"gulp-uglify": "1.5.3",
4443
"isomorphic-fetch": "2.2.1",
45-
"mocha": "2.4.5",
46-
"mysql": "2.10.2"
44+
"mocha": "2.4.5"
4745
}
4846
}

src/decorators/nonconfigurable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function nonconfigurable(target, key, desc) {
2+
return {
3+
...desc,
4+
configurable: false
5+
};
6+
}

src/decorators/nonenumerable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function nonenumerable(target, key, desc) {
2+
return {
3+
...desc,
4+
enumerable: false
5+
};
6+
}

0 commit comments

Comments
 (0)