Skip to content

Commit e7b1025

Browse files
authored
Merge pull request #428 from strongloop/rdme-def
docs: update column default value setup section
2 parents b06a8b8 + f6c0f1d commit e7b1025

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ supported by [`node-mysql`](https://github.com/felixge/node-mysql).
158158

159159
## Type mappings
160160

161-
See [LoopBack types](http://loopback.io/doc/en/lb3/LoopBack-types.html) for
161+
See [LoopBack 4 types](http://loopback.io/doc/en/lb4/LoopBack-types.html) (or [LoopBack 3 types](http://loopback.io/doc/en/lb3/LoopBack-types.html)) for
162162
details on LoopBack's data types.
163163

164164
### LoopBack to MySQL types
@@ -253,6 +253,8 @@ _NOTE_ as of v3.0.0 of MySQL Connector, the following flags were introduced:
253253

254254
## Data mapping properties
255255

256+
Except the common database-specific properties we introduce in [How LoopBack Models Map To Database Tables/Collections](https://loopback.io/doc/en/lb4/Model.html#how-loopback-models-map-to-database-tablescollections), the following are more detailed examples and MySQL-specific settings.
257+
256258
### Table/Column Names
257259

258260
Besides the basic LoopBack types, as we introduced above, you can also specify
@@ -452,14 +454,15 @@ export class User extends Entity {
452454
453455
### Default Clause/Constant
454456
455-
Use the `default` property to have MySQL handle setting column `DEFAULT` value.
457+
Use the `default` and `dataType` properties to have MySQL handle **setting column `DEFAULT` value**.
456458
457459
<details><summary markdown="span"><strong>Example</strong></summary>
458460
459461
```ts
460462
@property({
461463
type: 'String',
462464
mysql: {
465+
dataType: 'varchar',
463466
default: 'pending'
464467
}
465468
})
@@ -468,10 +471,20 @@ status: String;
468471
@property({
469472
type: 'Number',
470473
mysql: {
474+
dataType: 'int',
471475
default: 42
472476
}
473477
})
474478
maxDays: Number;
479+
480+
@property({
481+
type: 'boolean',
482+
mysql: {
483+
dataType: 'tinyint',
484+
default: 1
485+
}
486+
})
487+
isDone: Boolean;
475488
```
476489
477490
</details>
@@ -484,6 +497,7 @@ For the date or timestamp types use `CURRENT_TIMESTAMP` or `now`.
484497
@property({
485498
type: 'Date',
486499
mysql: {
500+
dataType: 'datetime',
487501
default: 'CURRENT_TIMESTAMP'
488502
}
489503
})

0 commit comments

Comments
 (0)