mevn-orm 2.3.5 → 2.4.0

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/.env.example CHANGED
@@ -4,6 +4,6 @@ DB_HOST=localhost
4
4
  DB_USER=root
5
5
  DB_PASSWORD=
6
6
  DB_DATABASE=mevn_orm
7
- DB_CLIENT=mysql2
7
+ DB_CLIENT=mysql
8
8
 
9
9
  TESTING_DB=sqlite3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mevn-orm",
3
- "version": "2.3.5",
3
+ "version": "2.4.0",
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.0",
15
+ "knex": "^2.2.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,14 +47,14 @@
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.2.0",
52
55
  "mocha": "^9.1.2",
53
- "mysql2": "^2.3.0"
56
+ "mysql2": "^2.3.0",
57
+ "sqlite3": "^5.0.9"
54
58
  },
55
59
  "directories": {
56
60
  "lib": "lib",
@@ -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,118 +0,0 @@
1
- #!/bin/env node
2
- const fs = require('fs')
3
- require('dotenv').config()
4
- const Knex = require('knex')
5
-
6
- let knexfilePath
7
-
8
- if (fs.existsSync(process.cwd() + '/knexfile.js')) {
9
- knexfilePath = process.cwd() + '/knexfile.js'
10
- } else {
11
- knexfilePath = process.cwd() + '/knexfile.cjs'
12
- }
13
- const { development, staging, production } = require(knexfilePath)
14
- let config
15
-
16
- switch (process.env.NODE_ENV) {
17
- case 'testing':
18
- config = development
19
- break
20
- case 'development':
21
- config = development
22
- break
23
- case 'staging':
24
- config = staging
25
- break
26
- default:
27
- config = production
28
- break
29
- }
30
- async function initDatabase() {
31
- const DB = Knex(config)
32
-
33
- try {
34
- await DB.schema.dropTableIfExists('farmers')
35
- await DB.schema.dropTableIfExists('farms')
36
- await DB.schema.dropTableIfExists('profiles')
37
- await DB.schema.dropTableIfExists('articles')
38
- await DB.schema.createTable('farmers', (table) => {
39
- table.bigIncrements('id')
40
- table.string('name')
41
- table.string('email').unique()
42
- table.string('password')
43
- })
44
- await DB.schema.createTable('farms', (table) => {
45
- table.bigIncrements('id')
46
- table.bigInteger('farmer_id')
47
- table.string('name')
48
- })
49
-
50
- await DB.schema.createTable('profiles', (table) => {
51
- table.bigIncrements('id')
52
- table.bigInteger('farmer_id')
53
- table.string('bio')
54
- })
55
-
56
- await DB.schema.createTable('articles', (table) => {
57
- table.bigIncrements('id')
58
- table.string('title')
59
- table.text('body')
60
- table.bigInteger('postable_id')
61
- table.string('postable_type')
62
- })
63
-
64
- await DB.table('Farmers').insert([
65
- {
66
- name: 'Jane Doe',
67
- email: 'jane@mail.com',
68
- password: 'pasword'
69
- },
70
- {
71
- name: 'Ashley Doe',
72
- email: 'ashley@mail.com',
73
- password: 'pasword'
74
- },
75
- {
76
- name: 'Alice Doe',
77
- email: 'alice@mail.com',
78
- password: 'pasword'
79
- }
80
- ])
81
-
82
- await DB.table('farms').insert([
83
- {
84
- farmer_id: 1,
85
- name: 'Awesome Farm'
86
- },
87
- {
88
- farmer_id: 1,
89
- name: 'Awesome Farm two'
90
- },
91
- {
92
- farmer_id: 1,
93
- name: 'Awesome Farm three'
94
- }
95
- ])
96
-
97
- await DB.table('profiles').insert([
98
- {
99
- farmer_id: 1,
100
- bio: 'Profile for farmer one'
101
- }
102
- ])
103
-
104
- await DB.table('articles').insert([
105
- {
106
- title: 'Awesome Post',
107
- body: 'fffgjdfjdbdb something #1',
108
- postable_id: 1,
109
- postable_type: 'Farmer'
110
- }
111
- ])
112
-
113
- process.exit(0)
114
- } catch (error) {
115
- process.exit(1)
116
- }
117
- }
118
- 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
- })