tspace-mysql 1.0.5 → 1.0.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.
Files changed (45) hide show
  1. package/README.md +310 -192
  2. package/dist/cli/index.js +10 -6
  3. package/dist/cli/migrate/make.d.ts +1 -1
  4. package/dist/cli/migrate/make.js +5 -18
  5. package/dist/cli/models/make.d.ts +1 -1
  6. package/dist/cli/models/make.js +2 -2
  7. package/dist/cli/models/model.js +1 -1
  8. package/dist/cli/tables/make.d.ts +2 -2
  9. package/dist/cli/tables/make.js +2 -7
  10. package/dist/cli/tables/table.js +1 -1
  11. package/dist/lib/config/env.js +13 -6
  12. package/dist/lib/connection/index.d.ts +27 -0
  13. package/dist/lib/connection/index.js +79 -0
  14. package/dist/lib/constants/index.d.ts +3 -3
  15. package/dist/lib/constants/index.js +89 -8
  16. package/dist/lib/tspace/AbstractDB.d.ts +1 -1
  17. package/dist/lib/tspace/AbstractDB.js +2 -0
  18. package/dist/lib/tspace/AbstractDatabase.d.ts +20 -16
  19. package/dist/lib/tspace/AbstractDatabase.js +9 -19
  20. package/dist/lib/tspace/AbstractModel.d.ts +5 -4
  21. package/dist/lib/tspace/AbstractModel.js +2 -0
  22. package/dist/lib/tspace/Blueprint.d.ts +65 -0
  23. package/dist/lib/tspace/Blueprint.js +195 -0
  24. package/dist/lib/tspace/DB.d.ts +15 -10
  25. package/dist/lib/tspace/DB.js +41 -105
  26. package/dist/lib/tspace/Database.d.ts +568 -100
  27. package/dist/lib/tspace/Database.js +1629 -394
  28. package/dist/lib/tspace/Interface.d.ts +63 -9
  29. package/dist/lib/tspace/Logger.d.ts +8 -1
  30. package/dist/lib/tspace/Logger.js +46 -30
  31. package/dist/lib/tspace/Model.d.ts +392 -119
  32. package/dist/lib/tspace/Model.js +1351 -745
  33. package/dist/lib/tspace/ProxyHandler.d.ts +5 -4
  34. package/dist/lib/tspace/ProxyHandler.js +15 -11
  35. package/dist/lib/tspace/Schema.d.ts +4 -41
  36. package/dist/lib/tspace/Schema.js +12 -137
  37. package/dist/lib/tspace/index.d.ts +2 -1
  38. package/dist/lib/tspace/index.js +6 -5
  39. package/dist/lib/utils/index.d.ts +1 -3
  40. package/dist/lib/utils/index.js +4 -85
  41. package/package.json +4 -3
  42. package/dist/lib/connections/index.d.ts +0 -2
  43. package/dist/lib/connections/index.js +0 -42
  44. package/dist/lib/connections/options.d.ts +0 -4
  45. package/dist/lib/connections/options.js +0 -32
package/README.md CHANGED
@@ -1,9 +1,10 @@
1
- # tspace-mysql
1
+ ## tspace-mysql
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/tspace-mysql.svg)](https://www.npmjs.com)
4
4
  [![NPM downloads](https://img.shields.io/npm/dm/tspace-mysql.svg)](https://www.npmjs.com)
5
5
 
6
- Query builder object relation mapping
6
+ TspaceMySQL is an ORM that can run in NodeJs and can be used with TypeScript.
7
+ Its goal is to always support the latest TypeScript and JavaScript features and provide additional features that help you to develop.
7
8
 
8
9
  ## Install
9
10
 
@@ -13,8 +14,18 @@ Install with [npm](https://www.npmjs.com/):
13
14
  npm install tspace-mysql --save
14
15
 
15
16
  ```
16
- ## Setup
17
- .env
17
+ ## Basic Usage
18
+ - [Configuration](#configuration)
19
+ - [Running Queries](#running-queryies)
20
+ - [Database Transactions](#database-transactions)
21
+ - [Accessing Connections](#accessing-connections)
22
+ - [Query Logging](#query-logging)
23
+ - [Generating Model Classes](#generating-model-classes)
24
+ - [Model Conventions](#model-conventions)
25
+ - [Relationships](#relationships)
26
+
27
+ ## Configuration
28
+ Created your environment variables is to use a .env file, you may establish a connection is this:
18
29
  ```js
19
30
  DB_HOST = localhost
20
31
  DB_PORT = 3306
@@ -22,174 +33,276 @@ DB_USERNAME = root
22
33
  DB_PASSWORD = password
23
34
  DB_DATABASE = database
24
35
  ```
25
- ## Getting Started
26
- queries data
36
+ ## Running Queries
37
+ Once you have configured your database connection, you may run queries is this :
27
38
  ```js
39
+ +-------------+--------------+----------------------------+
40
+ | table users |
41
+ +-------------+--------------+----------------------------+
42
+ | id | username | email |
43
+ |-------------|--------------|----------------------------|
44
+ | 1 | tspace | tspace@gmail.com |
45
+ | 2 | tspace2 | tspace2@gmail.com |
46
+ +-------------+--------------+----------------------------+
47
+
28
48
  import { DB } from 'tspace-mysql'
29
49
  (async () => {
30
- await new DB().raw('SELECT * FROM users')
31
- await new DB().table('users').findMany()
32
- await new DB().table('users').select('id').where('id',1).findOne()
33
- await new DB().table('users').select('id').whereIn('id',[1,2,3]).findMany()
50
+ await new DB('users').findMany() // SELECT * FROM users => Array
51
+ await new DB('users').findOne() // SELECT * FROM users LIMIT 1 => Object
34
52
  })()
35
53
  ```
36
- create data
37
-
54
+ Running A Select Query
38
55
  ```js
39
- import { DB } from 'tspace-mysql'
40
- (async () => {
41
- *ex pattern 1
42
- const user = await new DB().table('users').create({
43
- name : 'tspace',
44
- email : 'tspace@gmail.com'
45
- }).save()
46
-
47
- console.log(user)
48
-
49
- *ex pattern 2
50
- const u = new DB().table('users')
51
- u.name = 'tspace'
52
- u.email = 'tspace@gmail.com'
53
- await u.save()
54
- const { result : user } = u
55
- /* or const user = await u.save() */
56
- console.log(user)
57
- })()
56
+ const selectQuery = await new DB('users').select('id','username').findOne()
57
+ // selectQuery => { id : 1, username : 'tspace'}
58
+ const selectQueries = await new DB('users').select('id','username').findMany()
59
+ // selectQueries => [{ id : 1, username : 'tspace' } , { id : 2, username : 'tspace2'}]
58
60
  ```
59
-
60
- update data
61
+ Running A Where Query
61
62
  ```js
62
- import { DB } from 'tspace-mysql'
63
- (async () => {
64
- *ex pattern 1
65
- const user = await new DB().table('users').update({
66
- name : 'tspace',
67
- email : 'tspace@gmail.com'
68
- })
69
- .where('id',1)
70
- .save()
71
-
72
- console.log(user)
73
-
74
- *ex pattern 2
75
- const u = new DB().table('users').where('id',1)
76
- u.name = 'tspace'
77
- u.email = 'tspace@gmail.com'
78
- await u.save()
79
- const { result : user } = u
80
- /* or const user = await u.save() */
81
- console.log(user)
82
- })()
63
+ const user = await new DB('users').where('id',1).findOne()
64
+ // user => { id : 1 , username : 'tspace', email : 'tspace@gmail.com'}
65
+ const users = await new DB('users').where('id','!=',1).findMany()
66
+ // users => [{ id : 2 , username : 'tspace2' , email : 'tspace2@gmail.com' }]
67
+ ```
68
+ Running A Insert Query
69
+ ```js
70
+ const user = await new DB('users').create({
71
+ name : 'tspace3',
72
+ email : 'tspace3@gmail.com'
73
+ }).save()
74
+ // user => { id : 3 , username : 'tspace3', email : 'tspace3@gmail.com'}
75
+ +----------------------------------------------------------------------------------+
76
+ const reposity = new DB('users')
77
+ reposity.name = 'tspace4'
78
+ reposity.email = 'tspace4@gmail.com'
79
+ await reposity.save()
80
+ const { result } = reposity
81
+ // result => { id : 4 , username : 'tspace4', email : 'tspace4@gmail.com'}
82
+ ```
83
+ Running A Update Query
84
+ ```js
85
+ const user = await new DB('users').where('id',1)
86
+ .update({
87
+ name : 'tspace1**',
88
+ email : 'tspace1@gmail.com'
89
+ }).save()
90
+ // user => { id : 1 , username : 'tspace1**', email : 'tspace1@gmail.com'}
91
+ +----------------------------------------------------------------------------------+
92
+ const reposity = new DB('users').where('id',1)
93
+ reposity.name = 'tspace1++'
94
+ reposity.email = 'tspace1++@gmail.com'
95
+ await reposity.save()
96
+ const { result } = reposity
97
+ // result => { id : 1 , username : 'tspace1++', email : 'tspace1++@gmail.com'}
83
98
  ```
84
- delete data
99
+ Running A Delete Query
85
100
  ```js
86
- import { DB } from 'tspace-mysql'
87
- (async () => {
88
- await new User().where('id',1).delete()
89
- })()
101
+ const deleted = await new DB('users').where('id',1).delete()
102
+ // deleted => true
90
103
  ```
91
-
92
- ## Transactions & Rollback
104
+ ## Database Transactions
105
+ Within a database transaction, you may use the:
93
106
  ```js
94
- import { DB } from 'tspace-mysql'
95
- (async () => {
96
- const transaction = await new DB().beginTransaction()
97
- try {
98
- const user = await new User().create({
99
- name : 'tspace',
100
- email : 'tspace@gmail.com'
101
- })
102
- .save(transaction)
103
-
104
- const posts = await new Post().createMultiple([
105
- {
106
- user_id : user.id,
107
- title : 'tspace post'
108
- },
109
- {
110
- user_id : user.id,
111
- title : 'tspace post second'
112
- }
113
- ])
114
- .save(transaction)
115
-
116
- throw new Error('try to transaction')
117
-
118
- } catch (err) {
119
- const rollback = await transaction.rollback()
120
- console.log(rollback ,'rollback !')
121
- }
122
- })()
107
+ const transaction = await new DB().beginTransaction()
108
+ try {
109
+ const user = await new DB('users').create({
110
+ name : 'tspace5',
111
+ email : 'tspace5@gmail.com'
112
+ })
113
+ .save(transaction)
114
+ // user => { id : 5 , username : 'tspace5', email : 'tspace5@gmail.com'}
115
+
116
+ const userSecond = await new DB('users').create({
117
+ name : 'tspace6',
118
+ email : 'tspace6@gmail.com'
119
+ })
120
+ .save(transaction)
121
+ // userSecond => { id : 6 , username : 'tspace6', email : 'tspace6@gmail.com'}
122
+
123
+ throw new Error('try to using transaction')
124
+
125
+ } catch (err) {
126
+ const rollback = await transaction.rollback()
127
+ // rollback => true
128
+ // * rollback data user, userSecond in your database
129
+ }
130
+ ```
131
+ ## Generating Model Classes
132
+ To get started, let's install npm install tspace-mysql -g
133
+ you may use the make:model command to generate a new model:
134
+
135
+ ```sh
136
+ npm install tspace-mysql -g
137
+ tspace-mysql make:model <model name> --dir=<directory>
138
+
139
+ # tspace-mysql make:model User --dir=App/Models
140
+ # => App/Models/User.ts
123
141
  ```
124
-
125
142
  ## Model Conventions
126
- basic model class and discuss some relations:
143
+ Models generated by the make:model command will be placed in the specific directory.
144
+ Let's examine a basic model class:
127
145
 
128
146
  ```js
129
147
  import { Model } from 'tspace-mysql'
130
- import Post from '../Post'
131
- import Comment from '../Comment'
132
- import User from '../User'
133
-
134
- Folder directory example
135
- - App
136
- - Model
137
- Post.ts
138
- User.ts
139
- Comment.ts
140
-
141
- (async () => {
142
- const users = await new User()
143
- .with('posts','comments') /* relations -> hasMany: posts & comments */
144
- .withQuery('posts', (query) => query.with('user')) /* relation -> belongsTo: post by user */
145
- .withQuery('comments', (query) => query.with('user','post')) /* relation -> belongsTo: comment by user? & comment in post*/
146
- .findMany()
147
-
148
- console.log(users)
149
- })()
148
+ class User extends Model {
149
+ constructor(){
150
+ super()
151
+ this.useTimestamp()
152
+ /*
153
+ * the "snake case", plural name of the class will be used as the table name
154
+ *
155
+ * @param {string} name The table associated with the model.
156
+ */
157
+ this.useTable('users')
158
+ }
159
+ }
160
+ export { User }
161
+ export default User
150
162
  ```
151
- *User.ts
163
+ ## Relationships
164
+ Relationships are defined as methods on your Model classes
165
+ Let's examine a basic relations :
166
+
167
+ ## One To One
168
+ A one-to-one relationship is used to define relationships where a single model is the parent to one child models
152
169
  ```js
153
170
  import { Model } from 'tspace-mysql'
171
+ import Phone from '../Phone'
154
172
  class User extends Model {
155
173
  constructor(){
156
174
  super()
157
- this.hasMany({name : 'posts', model: Post })
158
- this.hasMany({name : 'comments', model: Comment })
175
+ this.useTimestamp()
176
+ /**
177
+ *
178
+ * @hasOne Get the phone associated with the user.
179
+ * @relationship users.id -> phones.user_id
180
+ */
181
+ this.hasOne({ name : 'phone' , model : Phone })
159
182
  }
160
- }
183
+ /**
184
+ * @hasOneQuery Get the phone associated with the user. using function callback
185
+ * @function
186
+ */
187
+ phone (callback ?: Function) {
188
+ return this.hasOneQuery({ model : Phone }, (query) => {
189
+ return callback ? callback(query) : query
190
+ })
191
+ }
192
+ }
161
193
  export default User
194
+ +----------------------------------------------------------------------------------+
195
+ import User from '../User'
196
+ const user = await new User().with('brand').findOne()
197
+ // user?.phone => {...}
198
+ const userUsingFunction = await new User().phone().findOne()
199
+ // userUsingFunction?.phone => {...}
162
200
  ```
163
201
 
164
- *Post.ts
202
+ ## One To Many
203
+ A one-to-many relationship is used to define relationships where a single model is the parent to one or more child models.
165
204
  ```js
166
205
  import { Model } from 'tspace-mysql'
167
-
206
+ import Comment from '../Comment'
168
207
  class Post extends Model {
169
208
  constructor(){
170
209
  super()
171
- this.belongsTo({name : 'user', model: User })
210
+ this.useTimestamp()
211
+ /**
212
+ *
213
+ * @hasMany Get the comments for the post.
214
+ * @relationship posts.id -> comments.post_id
215
+ */
172
216
  this.hasMany({ name : 'comments' , model : Comment })
173
217
  }
174
- }
218
+ /**
219
+ * @hasManyQuery Get the comments for the post. using function callback
220
+ * @function
221
+ */
222
+ comments (callback ?: Function) {
223
+ return this.hasManyQuery({ model : Comment }, (query) => {
224
+ return callback ? callback(query) : query
225
+ })
226
+ }
227
+ }
175
228
  export default Post
229
+ +----------------------------------------------------------------------------------+
230
+ import Post from '../Post'
231
+ const posts = await new Post().with('comments').findOne()
232
+ // posts?.comments => [{...}]
233
+ const postsUsingFunction = await new Post().comments().findOne()
234
+ // postsUsingFunction?.comments => [{...}]
176
235
  ```
177
236
 
178
- *Comment.ts
237
+ ## One To One & One To Many (Inverse) / Belongs To
179
238
  ```js
180
239
  import { Model } from 'tspace-mysql'
181
-
182
- class Comment extends Model {
240
+ import User from '../User'
241
+ class Phone extends Model {
183
242
  constructor(){
184
243
  super()
185
- this.belongsTo({name : 'user', model: User })
186
- this.belongsTo({name : 'post', model: Post })
244
+ this.useTimestamp()
245
+ /**
246
+ *
247
+ * @belongsTo Get the user that owns the phone.
248
+ * @relationship phones.user_id -> users.id
249
+ */
250
+ this.belognsTo({ name : 'user' , model : User })
187
251
  }
188
- }
189
- export default Comment
252
+ /**
253
+ * @belongsToQuery Get the user that owns the phone.. using function callback
254
+ * @function
255
+ */
256
+ user (callback ?: Function) {
257
+ return this.belongsToQuery({ model : User }, (query) => {
258
+ return callback ? callback(query) : query
259
+ })
260
+ }
261
+ }
262
+ export default Phone
263
+ +----------------------------------------------------------------------------------+
264
+ import Phone from '../Phone'
265
+ const phone = await new Phone().with('user').findOne()
266
+ // phone?.user => {...}
267
+ const phoneUsingFunction = await new Phone().user().findOne()
268
+ // phoneUsingFunction?.user => {...}
190
269
  ```
191
270
 
192
- ## Method chaining
271
+ ## Many To Many
272
+ Many-to-many relations are slightly more complicated than hasOne and hasMany relationships.
273
+ ```js
274
+ import { Model } from 'tspace-mysql'
275
+ import Role from '../Role'
276
+ class User extends Model {
277
+ constructor(){
278
+ super()
279
+ this.useTimestamp()
280
+ /**
281
+ *
282
+ * @belongsToMany Get The roles that belong to the user.
283
+ * @relationship users.id , roles.id => role_user.user_id , role_user.role_id
284
+ */
285
+ this.belognsToMany({ name : 'roles' , model : Role })
286
+ }
287
+ /**
288
+ * @belongsToQuery Get the user that owns the phone.. using function callback
289
+ * @function
290
+ */
291
+ roles (callback ?: Function) {
292
+ return this.belongsToManyQuery({ model : Role }, (query) => {
293
+ return callback ? callback(query) : query
294
+ })
295
+ }
296
+ }
297
+ export default User
298
+ +----------------------------------------------------------------------------------+
299
+ import User from '../User'
300
+ const user = await new User().with('roles').findOne()
301
+ // user?.roles => [{...}]
302
+ const userUsingFunction = await new User().roles().findOne()
303
+ // user?.roles => [{...}]
304
+ ```
305
+ ## Query Builder Chaining
193
306
  method chaining for queries
194
307
  ```js
195
308
  where(column , operator , value)
@@ -209,7 +322,7 @@ select(column1 ,column2 ,...N)
209
322
  except(column1 ,column2 ,...N)
210
323
  only(column1 ,column2 ,...N)
211
324
  hidden(column1 ,column2 ,...N)
212
- join (primary key , table.foreign key)
325
+ join(primary key , table.foreign key)
213
326
  rightJoin (primary key , table.foreign key)
214
327
  leftJoin (primary key , table.foreign key)
215
328
  limit (limit)
@@ -219,33 +332,40 @@ latest (column)
219
332
  oldest (column)
220
333
  groupBy (column)
221
334
 
222
- insert(objects)
223
335
  create(objects)
224
336
  createMultiple(array objects)
225
337
  update (objects)
226
- insertNotExists(objects)
227
338
  createNotExists(objects)
228
- updateOrInsert (objects)
229
339
  updateOrCreate (objects)
340
+
230
341
  /**
231
- * relationship
232
- *
233
- * @Relation setup name in model
342
+ * registry relation in your models
343
+ * @relationship
344
+ */
345
+ hasOne({ name , model , localKey , foreignKey , freezeTable , as }
346
+ hasMany({ name , model , localKey , foreignKey , freezeTable , as }
347
+ belongsTo({ name , model , localKey , foreignKey , freezeTable , as }
348
+ belongsToMany({ name , model , localKey , foreignKey , freezeTable , as }
349
+ /**
350
+ * @relation using registry in your models
234
351
  */
235
352
  with(name1 , name2,...nameN)
353
+ /**
354
+ * @relation using registry in your models. if exists child data remove this parent data
355
+ */
236
356
  withExists(name1 , name2,...nameN)
237
- withQuery('relation registry',(callback queries))
357
+ /**
358
+ * @relation call a relation in registry, callback query of parent data
359
+ */
360
+ withQuery('relation registry',(callback query))
238
361
 
239
362
  /**
240
363
  * queries statements
241
- *
242
- * @exec statements
364
+ * @exec statements
243
365
  */
244
366
  findMany()
245
367
  findOne()
246
368
  find(id)
247
- first()
248
- get()
249
369
  delelte()
250
370
  exists ()
251
371
  onlyTrashed()
@@ -263,61 +383,64 @@ save() /*for action statements insert update or delete */
263
383
  ```
264
384
 
265
385
  ## Cli
266
- npm install tspace-mysql -g
267
- ```js
268
-
269
- tspace-mysql make:model <MODEL NAME> --m --dir=... --js
270
- * optional
271
- --m /* created table for migrate */
272
- --dir=directory /* created model in directory */
273
- --type=js /* extension js default ts */
386
+ To get started, let's install npm install tspace-mysql -g
387
+ you may use a basic cli :
274
388
 
275
- tspace-mysql make:migration <TABLE NAME>
276
- * optional
277
- --type=js /* extension js default ts */
278
- --dir=directory /* created table in directory */
279
-
280
- tspace-mysql migrate <FOLDER> --js
281
- * optional
282
- --type=js /* extension js default ts */
283
- --dir=directory /* find migrate in directory */
284
- ```
285
-
286
- tspace-mysql make:model User --m --dir=App/Models
287
- ```js
288
- /* Ex folder
389
+ ## Make Model
390
+ Command will be placed Model in the specific directory
391
+ ```sh
392
+ tspace-mysql make:model <MODEL NAME> --m --dir=.... --type=....
393
+ /**
394
+ * @options
395
+ * --m // created scheme table for migrate
396
+ * --dir=directory // created model in directory
397
+ * --type=js // extension js default ts
398
+ */
399
+
400
+ tspace-mysql make:model User --m --dir=app/Models
401
+ // =>
289
402
  - node_modules
290
- - App
403
+ - app
291
404
  - Models
292
405
  User.ts
293
406
  */
294
-
295
- /* in App/Models/User.ts */
296
- import { Model } from 'tspace-mysql'
297
- class User extends Model{
298
- constructor(){
299
- super()
300
- this.useDebug() /* default false *debug sql */
301
- this.useTimestamp() /* default false * case created_at & updated_at*/
302
- this.useSoftDelete() /* default false * case where deleted_at is null */
303
- this.useTable('users') /* default users */
304
- this.usePattern('camelCase') /* default snake_case */
305
- this.useUUID()
306
- }
307
- }
308
- export default User
309
407
  ```
310
- tspace-mysql make:migration users --dir=App/Models/Migrations
311
- ```js
312
- /* Ex folder
408
+
409
+ ## Make Migration
410
+ Command will be placed Migration in the specific directory
411
+ ```sh
412
+ tspace-mysql make:migration <TABLE NAME>
413
+ /**
414
+ * @options
415
+ * --type=js /* extension js default ts */
416
+ * --dir=directory /* created table in directory */
417
+ */
418
+ tspace-mysql make:migration users --dir=app/Models/Migrations
419
+ // =>
313
420
  - node_modules
314
- - App
421
+ - app
315
422
  - Models
316
- - migrations
423
+ - Migrations
317
424
  create_users_table.ts
318
425
  User.ts
319
426
  */
320
- /* in App/Models/Migrations/create_users_table.ts */
427
+ ```
428
+ ## Migrate
429
+ ```sh
430
+ tspace-mysql migrate <FOLDER> --type=...
431
+ /**
432
+ * @options
433
+ *--type=js /* extension js default ts */
434
+ *--dir=directory /* find migrate in directory */
435
+ */
436
+
437
+ tspace-mysql migrate --dir=App/Models/Migrations
438
+ // => migrate all schema table in folder into database
439
+ ```
440
+
441
+ ## Blueprint method
442
+ Schema table created by command make:migration, you may use the:
443
+ ```js
321
444
  import { Schema , Blueprint , DB } from 'tspace-mysql'
322
445
  (async () => {
323
446
  await new Schema().table('users',{
@@ -330,16 +453,11 @@ import { Schema , Blueprint , DB } from 'tspace-mysql'
330
453
  updated_at : new Blueprint().null().timestamp()
331
454
  })
332
455
  /**
333
- *
334
- * @Faker data
456
+ *
457
+ * @Faker fake data 5 raw
335
458
  * await new DB().table('users').faker(5)
336
459
  */
337
460
  })()
338
- ```
339
- tspace-mysql migrate Migrations --dir=App/Models
340
- /* migrate all table in folder into database */
341
- ```js
342
- * Blueprint method
343
461
  /**
344
462
  *
345
463
  * @Types
@@ -373,4 +491,4 @@ primary()
373
491
  default (string)
374
492
  defaultTimestamp ()
375
493
  autoIncrement ()
376
- ```
494
+ ```
package/dist/cli/index.js CHANGED
@@ -16,12 +16,16 @@ var commands = {
16
16
  'migrate': make_3.default
17
17
  };
18
18
  try {
19
- var name = (_c = (_b = (_a = process.argv.slice(2)) === null || _a === void 0 ? void 0 : _a.find(function (data) { return data === null || data === void 0 ? void 0 : data.includes('--name='); })) === null || _b === void 0 ? void 0 : _b.replace('--name=', '')) !== null && _c !== void 0 ? _c : null;
19
+ var name = (_c = (_b = (_a = process.argv.slice(2)) === null || _a === void 0 ? void 0 : _a.find(function (data) {
20
+ return data === null || data === void 0 ? void 0 : data.includes('--name=');
21
+ })) === null || _b === void 0 ? void 0 : _b.replace('--name=', '')) !== null && _c !== void 0 ? _c : null;
20
22
  var migrate = (_e = (_d = process.argv.slice(2)) === null || _d === void 0 ? void 0 : _d.includes('--m')) !== null && _e !== void 0 ? _e : false;
21
- var dir = (_h = (_g = (_f = process.argv.slice(2)) === null || _f === void 0 ? void 0 : _f.find(function (data) { return data === null || data === void 0 ? void 0 : data.includes('--dir='); })) === null || _g === void 0 ? void 0 : _g.replace('--dir=', '/')) !== null && _h !== void 0 ? _h : null;
22
- // const migrateFolder = process.argv.slice(2)?.find(data => data?.includes('--f='))?.replace('--f=','/') ?? null
23
- // const type = process.argv.slice(2)?.includes('--js') ?? false ? '.js' : '.ts'
24
- var type = (_l = (_k = (_j = process.argv.slice(2)) === null || _j === void 0 ? void 0 : _j.find(function (data) { return data === null || data === void 0 ? void 0 : data.includes('--type='); })) === null || _k === void 0 ? void 0 : _k.replace('--type=', '.')) !== null && _l !== void 0 ? _l : '.ts';
23
+ var dir = (_h = (_g = (_f = process.argv.slice(2)) === null || _f === void 0 ? void 0 : _f.find(function (data) {
24
+ return data === null || data === void 0 ? void 0 : data.includes('--dir=');
25
+ })) === null || _g === void 0 ? void 0 : _g.replace('--dir=', '/')) !== null && _h !== void 0 ? _h : null;
26
+ var type = (_l = (_k = (_j = process.argv.slice(2)) === null || _j === void 0 ? void 0 : _j.find(function (data) {
27
+ return data === null || data === void 0 ? void 0 : data.includes('--type=');
28
+ })) === null || _k === void 0 ? void 0 : _k.replace('--type=', '.')) !== null && _l !== void 0 ? _l : '.ts';
25
29
  type = ['.js', '.ts'].includes(type) ? type : '.ts';
26
30
  var file = (_o = (_m = process.argv.slice(3)) === null || _m === void 0 ? void 0 : _m.shift()) !== null && _o !== void 0 ? _o : '';
27
31
  var cmd = {
@@ -37,5 +41,5 @@ try {
37
41
  commands[process.argv[2]](cmd);
38
42
  }
39
43
  catch (err) {
40
- console.log("\n use make:model <folder/...folder/model name> --m\n use make:table <folder/folder/...folder> --name=<name>\n use migrate <folder/folder/...folder> \n");
44
+ console.log("readme https://www.npmjs.com/package/tspace-mysql");
41
45
  }
@@ -1,4 +1,4 @@
1
- declare const _default: (_ref: {
1
+ declare const _default: (formCommand: {
2
2
  [x: string]: any;
3
3
  }) => void;
4
4
  export default _default;