mevn-orm 2.3.3 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/knexfile.js CHANGED
@@ -12,7 +12,7 @@ module.exports = {
12
12
  },
13
13
 
14
14
  staging: {
15
- client: process.env.DB_CLIENT || 'mysql2',
15
+ client: process.env.DB_CLIENT || 'mysql',
16
16
  connection: {
17
17
  database: process.env.DB_DATABASE || 'my_db',
18
18
  user: process.env.DB_USER || 'username',
@@ -28,7 +28,7 @@ module.exports = {
28
28
  },
29
29
 
30
30
  production: {
31
- client: process.env.DB_CLIENT || 'mysql2',
31
+ client: process.env.DB_CLIENT || 'mysql',
32
32
  connection: {
33
33
  database: process.env.DB_DATABASE || 'my_db',
34
34
  user: process.env.DB_USER || 'username',
package/lib/model.js CHANGED
@@ -1,5 +1,15 @@
1
+ const fs = require('fs')
1
2
  const knex = require('knex').knex
2
- const { development, staging, production } = require(process.cwd() + '/knexfile.js')
3
+
4
+ let fileName
5
+
6
+ if (fs.existsSync(process.cwd() + '/knexfile.js')) {
7
+ fileName = process.cwd() + '/knexfile.js'
8
+ } else {
9
+ fileName = process.cwd() + '/knexfile.cjs'
10
+ }
11
+ const { development, staging, production } = require(fileName)
12
+
3
13
  const pluralize = require('pluralize')
4
14
  let config
5
15
  switch (process.env.NODE_ENV) {
@@ -178,7 +188,7 @@ class Model {
178
188
  foreignKey = `${this.modelName}_id`
179
189
  }
180
190
 
181
- if(localKey) {
191
+ if (localKey) {
182
192
  relation[foreignKey] = localKey
183
193
  const res = await DB(table).where(relation).first()
184
194
  if (res) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mevn-orm",
3
- "version": "2.3.3",
3
+ "version": "2.3.7",
4
4
  "description": "simple ORM for express js",
5
5
  "type": "commonjs",
6
6
  "scripts": {
@@ -11,8 +11,8 @@
11
11
  "lint": "eslint --ext .js ./"
12
12
  },
13
13
  "peerDependencies": {
14
- "dotenv": "^15.0.0",
15
- "knex": "^1.0.1",
14
+ "dotenv": "^16.0.1",
15
+ "knex": "^2.1.0",
16
16
  "mysql": "^2.18.1"
17
17
  },
18
18
  "peerDependenciesMeta": {
@@ -27,7 +27,11 @@
27
27
  "ORM",
28
28
  "express",
29
29
  "Mysql",
30
- "mevn"
30
+ "mevn",
31
+ "database",
32
+ "orm",
33
+ "orm-express",
34
+ "orm-mysql"
31
35
  ],
32
36
  "author": "Stanley Masinde <stanmasinde@gmail.com> (https://stanleymasinde.github.io)",
33
37
  "contributors": [
@@ -43,21 +47,24 @@
43
47
  "@babel/eslint-parser": "^7.13.14",
44
48
  "@babel/eslint-plugin": "^7.13.16",
45
49
  "@babel/plugin-proposal-class-properties": "^7.14.5",
46
- "@vscode/sqlite3": "^5.0.7",
47
50
  "chai": "^4.2.0",
48
51
  "dotenv": "^15.0.0",
49
52
  "eslint": "^7.25.0",
50
53
  "faker": "^5.5.3",
51
- "knex": "^1.0.1",
54
+ "knex": "^2.1.0",
52
55
  "mocha": "^9.1.2",
53
- "mysql2": "^2.3.0"
56
+ "mysql2": "^2.3.0",
57
+ "sqlite3": "^5.0.8"
54
58
  },
55
59
  "directories": {
56
60
  "lib": "lib",
57
61
  "test": "test"
58
62
  },
59
63
  "private": false,
60
- "repository": "git+https://github.com/StanleyMasinde/mevn-orm.git",
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "git+https://github.com/StanleyMasinde/mevn-orm.git"
67
+ },
61
68
  "bugs": {
62
69
  "url": "https://github.com/StanleyMasinde/mevn-orm/issues",
63
70
  "email": "stanmasinde@gmail.com"
@@ -1,38 +0,0 @@
1
- ---
2
- name: Bug report
3
- about: Create a report to help us improve
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Describe the bug**
11
- A clear and concise description of what the bug is.
12
-
13
- **To Reproduce**
14
- Steps to reproduce the behavior:
15
- 1. Go to '...'
16
- 2. Click on '....'
17
- 3. Scroll down to '....'
18
- 4. See error
19
-
20
- **Expected behavior**
21
- A clear and concise description of what you expected to happen.
22
-
23
- **Screenshots**
24
- If applicable, add screenshots to help explain your problem.
25
-
26
- **Desktop (please complete the following information):**
27
- - OS: [e.g. iOS]
28
- - Browser [e.g. chrome, safari]
29
- - Version [e.g. 22]
30
-
31
- **Smartphone (please complete the following information):**
32
- - Device: [e.g. iPhone6]
33
- - OS: [e.g. iOS8.1]
34
- - Browser [e.g. stock browser, safari]
35
- - Version [e.g. 22]
36
-
37
- **Additional context**
38
- Add any other context about the problem here.
@@ -1,20 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Suggest an idea for this project
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Is your feature request related to a problem? Please describe.**
11
- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
-
13
- **Describe the solution you'd like**
14
- A clear and concise description of what you want to happen.
15
-
16
- **Describe alternatives you've considered**
17
- A clear and concise description of any alternative solutions or features you've considered.
18
-
19
- **Additional context**
20
- Add any other context or screenshots about the feature request here.
@@ -1,30 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: npm
4
- directory: '/'
5
- schedule:
6
- interval: daily
7
- time: '00:00'
8
- open-pull-requests-limit: 10
9
- reviewers:
10
- - stanleymasinde
11
- assignees:
12
- - stanleymasinde
13
- commit-message:
14
- prefix: fix
15
- prefix-development: chore
16
- include: scope
17
- - package-ecosystem: github-actions
18
- directory: '/'
19
- schedule:
20
- interval: daily
21
- time: '00:00'
22
- open-pull-requests-limit: 10
23
- reviewers:
24
- - stanleymasinde
25
- assignees:
26
- - stanleymasinde
27
- commit-message:
28
- prefix: fix
29
- prefix-development: chore
30
- include: scope
@@ -1,31 +0,0 @@
1
- # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
-
4
- name: Node.js CI
5
-
6
- on:
7
- push:
8
- branches: [ main ]
9
- pull_request:
10
- branches: [ main ]
11
-
12
- jobs:
13
- build:
14
-
15
- runs-on: ubuntu-latest
16
-
17
- strategy:
18
- matrix:
19
- node-version: [12.x, 14.x, 15.x]
20
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
-
22
- steps:
23
- - uses: actions/checkout@v2
24
- - name: Use Node.js ${{ matrix.node-version }}
25
- uses: actions/setup-node@v2
26
- with:
27
- node-version: ${{ matrix.node-version }}
28
- - run: cp .env.example .env
29
- - run: npm ci
30
- - run: npm run build --if-present
31
- - run: npm test
package/initDb DELETED
@@ -1,109 +0,0 @@
1
- #!/bin/env node
2
- require('dotenv').config()
3
- const Knex = require('knex')
4
- const { development, staging, production } = require('./knexfile.js')
5
- let config
6
-
7
- switch (process.env.NODE_ENV) {
8
- case 'testing':
9
- config = development
10
- break
11
- case 'development':
12
- config = development
13
- break
14
- case 'staging':
15
- config = staging
16
- break
17
- default:
18
- config = production
19
- break
20
- }
21
- async function initDatabase() {
22
- const DB = Knex(config)
23
-
24
- try {
25
- await DB.schema.dropTableIfExists('farmers')
26
- await DB.schema.dropTableIfExists('farms')
27
- await DB.schema.dropTableIfExists('profiles')
28
- await DB.schema.dropTableIfExists('articles')
29
- await DB.schema.createTable('farmers', (table) => {
30
- table.bigIncrements('id')
31
- table.string('name')
32
- table.string('email').unique()
33
- table.string('password')
34
- })
35
- await DB.schema.createTable('farms', (table) => {
36
- table.bigIncrements('id')
37
- table.bigInteger('farmer_id')
38
- table.string('name')
39
- })
40
-
41
- await DB.schema.createTable('profiles', (table) => {
42
- table.bigIncrements('id')
43
- table.bigInteger('farmer_id')
44
- table.string('bio')
45
- })
46
-
47
- await DB.schema.createTable('articles', (table) => {
48
- table.bigIncrements('id')
49
- table.string('title')
50
- table.text('body')
51
- table.bigInteger('postable_id')
52
- table.string('postable_type')
53
- })
54
-
55
- await DB.table('Farmers').insert([
56
- {
57
- name: 'Jane Doe',
58
- email: 'jane@mail.com',
59
- password: 'pasword'
60
- },
61
- {
62
- name: 'Ashley Doe',
63
- email: 'ashley@mail.com',
64
- password: 'pasword'
65
- },
66
- {
67
- name: 'Alice Doe',
68
- email: 'alice@mail.com',
69
- password: 'pasword'
70
- }
71
- ])
72
-
73
- await DB.table('farms').insert([
74
- {
75
- farmer_id: 1,
76
- name: 'Awesome Farm'
77
- },
78
- {
79
- farmer_id: 1,
80
- name: 'Awesome Farm two'
81
- },
82
- {
83
- farmer_id: 1,
84
- name: 'Awesome Farm three'
85
- }
86
- ])
87
-
88
- await DB.table('profiles').insert([
89
- {
90
- farmer_id: 1,
91
- bio: 'Profile for farmer one'
92
- }
93
- ])
94
-
95
- await DB.table('articles').insert([
96
- {
97
- title: 'Awesome Post',
98
- body: 'fffgjdfjdbdb something #1',
99
- postable_id: 1,
100
- postable_type: 'Farmer'
101
- }
102
- ])
103
-
104
- process.exit(0)
105
- } catch (error) {
106
- process.exit(1)
107
- }
108
- }
109
- initDatabase()
@@ -1,87 +0,0 @@
1
- /* eslint-disable no-undef */
2
- const { Model, DB } = require('../index')
3
- const faker = require('faker')
4
- const { expect } = require('chai')
5
- class Profile extends Model {
6
- fillable = ['farmer_id', 'bio']
7
- }
8
- class Farmer extends Model {
9
- fillable = ['name', 'email', 'password']
10
- hidden = ['password']
11
-
12
- profile() {
13
- return this.hasOne(Profile)
14
- }
15
- }
16
-
17
- DB(Farmer)
18
-
19
- describe('#Model tests', () => {
20
- it('#Model instance', async () => {
21
- const farmer = new Farmer({
22
- name: faker.name.findName(),
23
- email: faker.internet.email(),
24
- password: faker.internet.password()
25
- })
26
- await farmer.save()
27
- expect(farmer).to.an('Object')
28
- })
29
-
30
- it('#find a model', async () => {
31
- const farmer = await Farmer.find(1)
32
- expect(farmer).to.an('Object')
33
- })
34
-
35
- it('#create a model', async () => {
36
- const farmer = await Farmer.create({
37
- name: faker.name.findName(),
38
- email: faker.internet.email(),
39
- password: faker.internet.password()
40
- })
41
- expect(farmer).to.an('Object')
42
- expect(farmer.id).to.be.a('number')
43
- })
44
-
45
- it('#Update a model with a new instance', async () => {
46
- const farmer = await Farmer.find(1)
47
- await farmer.update({
48
- name: 'new name',
49
- email: faker.internet.email(),
50
- password: faker.internet.password()
51
- })
52
- expect(farmer).to.an('Object')
53
- })
54
-
55
- it('#chain where and first', async () => {
56
- const farmer = await Farmer.where({ id: 1 }).first()
57
- expect(farmer).to.an('Object')
58
- })
59
-
60
- it('#Return null when not found', async () => {
61
- const farmer = await Farmer.where({ id: 'ggggggg' }).first()
62
- expect(farmer).to.be.null
63
- })
64
-
65
- it('#Delete a model', async () => {
66
- const farmer = await Farmer.find(1)
67
- await farmer.delete()
68
- expect(await Farmer.find(1)).to.be.null
69
- })
70
-
71
- it('#Has one relationship', async () => {
72
- const farmer = new Farmer({
73
- name: faker.name.findName(),
74
- email: faker.internet.email(),
75
- password: faker.internet.password()
76
- })
77
- await farmer.save()
78
- await new Profile({
79
- farmer_id: farmer.id,
80
- bio: faker.lorem.sentence()
81
- }).save()
82
-
83
- expect(farmer).to.an('Object')
84
- const farmerProfile = await farmer.profile()
85
- expect(farmerProfile).to.haveOwnProperty('farmer_id', farmer.id)
86
- })
87
- })