mevn-orm 3.2.2 → 4.0.1

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/changelog.md DELETED
@@ -1,135 +0,0 @@
1
- ## [unreleased]
2
-
3
- ### 💼 Other
4
-
5
- - Use Node 16 until I figure out what is going on
6
- ## [3.2.0] - 2025-09-29
7
-
8
- ### 🐛 Bug Fixes
9
-
10
- - *(deps)* Bump actions/checkout from 4 to 5
11
- - *(deps)* Bump actions/setup-node from 4 to 5
12
-
13
- ### 💼 Other
14
-
15
- - Support the latest versions of node
16
- - Only use Node 20 for tests
17
-
18
- ### ⚙️ Miscellaneous Tasks
19
-
20
- - Upgrade deps
21
- ## [3.0.0] - 2025-07-02
22
-
23
- ### 🐛 Bug Fixes
24
-
25
- - *(deps)* Bump actions/checkout from 3 to 4
26
- - *(deps)* Bump actions/setup-node from 3 to 4
27
-
28
- ### ⚙️ Miscellaneous Tasks
29
-
30
- - Upgrade deps
31
- ## [2.4.7-1] - 2023-03-08
32
-
33
- ### ⚙️ Miscellaneous Tasks
34
-
35
- - Update the default peer dep
36
- ## [2.4.6] - 2023-03-08
37
-
38
- ### ⚙️ Miscellaneous Tasks
39
-
40
- - Add auto publish to npm
41
- ## [2.4.5] - 2023-03-06
42
-
43
- ### 💼 Other
44
-
45
- - Update npm dependencies
46
-
47
- ### ⚙️ Miscellaneous Tasks
48
-
49
- - *(ci)* Drop support for node 14
50
- - *(version)* Release patch version 2.4.5
51
- ## [2.4.4] - 2023-01-04
52
-
53
- ### ⚙️ Miscellaneous Tasks
54
-
55
- - *(version)* Release patch version 2.4.4
56
- ## [2.4.3] - 2023-01-04
57
-
58
- ### ⚙️ Miscellaneous Tasks
59
-
60
- - *(version)* Release patch version 2.4.3
61
- ## [2.4.2] - 2023-01-03
62
-
63
- ### 🐛 Bug Fixes
64
-
65
- - *(deps)* Bump actions/checkout from 2 to 3 (#60)
66
-
67
- ### ⚙️ Miscellaneous Tasks
68
-
69
- - *(version)* Release patch version 2.4.2
70
- ## [2.4.1] - 2022-07-21
71
-
72
- ### ⚙️ Miscellaneous Tasks
73
-
74
- - *(version)* Release patch version 2.4.1
75
- ## [2.4.0] - 2022-07-20
76
-
77
- ### ⚙️ Miscellaneous Tasks
78
-
79
- - *(version)* Release minor version 2.4.0
80
- ## [2.3.7] - 2022-07-20
81
-
82
- ### 🐛 Bug Fixes
83
-
84
- - *(deps)* Bump actions/setup-node from 2 to 3 (#59)
85
- - *(dev)* Throwing error in the init db command that is used for setup
86
-
87
- ### ⚙️ Miscellaneous Tasks
88
-
89
- - *(dev)* The default database in .env.example is now mysql
90
- - *(dev)* Using sqlite 3 instead of @vscode/sqlite3
91
- - *(version)* Release patch version 2.3.7
92
- ## [2.3.6] - 2022-02-03
93
-
94
- ### 🐛 Bug Fixes
95
-
96
- - *(config)* Error when reolving config from the user defined config. file not found
97
- - *(knexfile)* The path of the knex file was still not updated to use either of the 2 .js or .cjs
98
-
99
- ### ⚙️ Miscellaneous Tasks
100
-
101
- - *(version)* Release patch version 2.3.2
102
- - *(version)* Release patch version 2.3.3
103
- - *(version)* Release patch version 2.3.4
104
- - *(version)* Release patch version 2.3.5
105
- - *(version)* Release patch version 2.3.6
106
- ## [2.3.1] - 2022-02-01
107
-
108
- ### ⚙️ Miscellaneous Tasks
109
-
110
- - *(version)* Release minor version 2.3.1
111
- ## [2.3.0] - 2022-02-01
112
-
113
- ### 🚀 Features
114
-
115
- - *(find)* Added the static find method
116
- - *(model)* Added the create method
117
- - *(update)* Added the instance update method
118
- - *(delete)* Added a delete method
119
-
120
- ### 🐛 Bug Fixes
121
-
122
- - *(deps)* Bump knex from 0.21.17 to 0.95.11 (#12)
123
- - *(exports)* Breaking changes were pushed with the previous change. the changes has been fixed
124
- - *(tableName)* Not hiding the table by default
125
- - *(first)* Fixed the first method
126
- - *(knexfile)* Loading knexfile from the current working dir instead of the root of the package
127
- - *(deps)* The latest knex version removed as a peer dep.
128
-
129
- ### ⚙️ Miscellaneous Tasks
130
-
131
- - *(package)* Updated package.json
132
- - *(es6)* Using .cjs for knexfile
133
- - *(version)* Release 2.2.13
134
- - *(version)* Release minor version 2.2.14
135
- - *(version)* Release minor version 2.3.0
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- require('dotenv').config()
2
- const {Model, DB} = require('./lib/model')
3
- module.exports = { Model, DB }
package/knexfile.js DELETED
@@ -1,46 +0,0 @@
1
- module.exports = {
2
-
3
- development: {
4
- client: 'sqlite3',
5
- connection: {
6
- filename: './dev.sqlite'
7
- },
8
- useNullAsDefault: true,
9
- migrations: {
10
- tableName: 'migrations',
11
- }
12
- },
13
-
14
- staging: {
15
- client: process.env.DB_CLIENT || 'mysql2',
16
- connection: {
17
- database: process.env.DB_DATABASE || 'my_db',
18
- user: process.env.DB_USER || 'username',
19
- password: process.env.DB_PASSWORD || 'password'
20
- },
21
- pool: {
22
- min: 2,
23
- max: 10
24
- },
25
- migrations: {
26
- tableName: 'migrations'
27
- }
28
- },
29
-
30
- production: {
31
- client: process.env.DB_CLIENT || 'mysql2',
32
- connection: {
33
- database: process.env.DB_DATABASE || 'my_db',
34
- user: process.env.DB_USER || 'username',
35
- password: process.env.DB_PASSWORD || 'password'
36
- },
37
- pool: {
38
- min: 2,
39
- max: 10
40
- },
41
- migrations: {
42
- tableName: 'migrations'
43
- }
44
- }
45
-
46
- }
package/lib/model.js DELETED
@@ -1,252 +0,0 @@
1
- const fs = require('fs')
2
- const knex = require('knex').knex
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
-
13
- const pluralize = require('pluralize')
14
- let config
15
- switch (process.env.NODE_ENV) {
16
- case 'testing':
17
- config = development
18
- break
19
- case 'development':
20
- config = development
21
- break
22
- case 'staging':
23
- config = staging
24
- break
25
- default:
26
- config = production
27
- break
28
- }
29
- const DB = knex(config)
30
- class Model {
31
- #private
32
- static currentTable = pluralize(this.name.toLowerCase())
33
- static currentQuery
34
- constructor(properties) {
35
- for (const key in properties) {
36
- this[key] = properties[key]
37
- }
38
- this.fillable = []
39
- this.hidden = []
40
- this.#private = ['fillable', 'hidden']
41
- this.modelName = this.constructor.name.toLowerCase()
42
- this.table = pluralize(this.constructor.name.toLowerCase())
43
- }
44
-
45
- /**
46
- * Save a model to the database
47
- */
48
- async save() {
49
- try {
50
- let rows = {}
51
- this.fillable.forEach((f) => {
52
- rows[f] = this[f]
53
- })
54
- const [id] = await DB(this.table)
55
- .insert(rows)
56
- const fields = await DB(this.table).where({ id }).first()
57
- for (const f in fields) {
58
- this[f] = fields[f]
59
- }
60
- this['id'] = id
61
- return this.stripColumns(this)
62
- } catch (error) {
63
- throw new Error(error)
64
- }
65
- }
66
-
67
- /**
68
- * Update a model
69
- * @param {*} properties
70
- * @returns this
71
- */
72
- async update(properties) {
73
- try {
74
- const id = await DB(this.table)
75
- .where({ id: this.id })
76
- .update(properties)
77
- const fields = await DB(this.table).where({ id }).first()
78
- // console.log(fields)
79
- return this.stripColumns(new this.constructor(fields))
80
- } catch (error) {
81
- throw new Error(error)
82
- }
83
- }
84
-
85
- /**
86
- * Delete a model
87
- * @returns this
88
- */
89
- async delete() {
90
- try {
91
- await DB(this.table)
92
- .where({ id: this.id })
93
- .del()
94
- return
95
- } catch (error) {
96
- throw new Error(error)
97
- }
98
- }
99
-
100
-
101
- /**
102
- * Update a model
103
- * @param {*} properties
104
- * @returns
105
- */
106
- static async update(properties) {
107
- try {
108
- if (!this.currentQuery) {
109
- const rows = await DB(this.table).update(properties)
110
- return rows
111
- }
112
- } catch (error) {
113
- throw new Error(error)
114
- }
115
- }
116
-
117
- /**
118
- * Delete a model
119
- * @returns
120
- */
121
- static async destroy() {
122
- try {
123
- if (!this.currentQuery) {
124
- const rows = await DB(this.table).delete()
125
- return rows
126
- }
127
- } catch (error) {
128
- throw new Error(error)
129
- }
130
- }
131
-
132
- /**
133
- * Find a model
134
- * @param {*} id
135
- * @param {*} columns
136
- * @returns this
137
- */
138
- static async find(id, columns = '*') {
139
- const table = pluralize(this.name.toLowerCase())
140
- try {
141
- const fields = await DB(table)
142
- .where({ id })
143
- .first(columns)
144
- if (fields) {
145
- return new this(fields)
146
- }
147
- return null
148
- } catch (error) {
149
- throw new Error(error)
150
- }
151
- }
152
-
153
- /**
154
- * Create a new model
155
- * @param {*} properties
156
- * @returns this
157
- */
158
- static async create(properties) {
159
- const table = pluralize(this.name.toLowerCase())
160
- try {
161
- const fields = await DB(table)
162
- .insert(properties)
163
- const record = await DB(table).where({ id: fields[0] }).first()
164
- const model = new this(record)
165
- return model.stripColumns(model)
166
- } catch (error) {
167
- throw new Error(error)
168
- }
169
- }
170
-
171
- /**
172
- * --------------|
173
- * Relationships |
174
- * --------------|
175
- */
176
-
177
- /**
178
- * One to one relationship
179
- * @param {*} related
180
- */
181
- async hasOne(Related, localKey, foreignKey) {
182
- const table = new Related().table
183
- const relation = {}
184
- if (!localKey) {
185
- localKey = this.id
186
- }
187
- if (!foreignKey) {
188
- foreignKey = `${this.modelName}_id`
189
- }
190
-
191
- if (localKey) {
192
- relation[foreignKey] = localKey
193
- const res = await DB(table).where(relation).first()
194
- if (res) {
195
- return this.stripColumns(new Related(res))
196
- }
197
- }
198
- return null
199
- }
200
- // hasMany(related) {}
201
- // hasManyThrough(related) {}
202
- // belongsTo(related) {}
203
- // belongsToMany(related) {}
204
-
205
- /**
206
- * Where condition
207
- * @param {*} conditions
208
- * @returns
209
- */
210
- static where(conditions = {}) {
211
- const table = pluralize(this.name.toLowerCase())
212
- this.currentQuery = DB(table).where(conditions)
213
- return this
214
- }
215
-
216
- /*ß
217
- * Return the first model
218
- * @param {*} columns
219
- */
220
- static async first(columns = '*') {
221
- try {
222
- if (!this.currentQuery) {
223
- const rows = await DB(this.table).first(columns)
224
- if (rows) {
225
- return new this(rows)
226
- }
227
- return null
228
- }
229
- const rows = await this.currentQuery.first(columns)
230
- if (rows) {
231
- return new this(rows)
232
- }
233
- return null
234
- } catch (error) {
235
- throw new Error(error)
236
- }
237
- }
238
-
239
-
240
- /**
241
- * Delete columns that are not needed
242
- *
243
- */
244
- stripColumns(model) {
245
- this.#private.concat(this.hidden).forEach((h) => {
246
- delete model[h]
247
- })
248
- return model
249
- }
250
-
251
- }
252
- module.exports = { Model, DB }
@@ -1,8 +0,0 @@
1
- onlyBuiltDependencies:
2
- - sqlite3
3
-
4
- overrides:
5
- diff@>=6.0.0 <8.0.3: '>=8.0.3'
6
- tar@<7.5.7: '>=7.5.7'
7
- tar@<=7.5.2: '>=7.5.3'
8
- tar@<=7.5.3: '>=7.5.4'