@@ -1162,6 +1162,24 @@ DataSource.prototype.autoupdate = function(models, cb) {
1162
1162
return cb . promise ;
1163
1163
} ;
1164
1164
1165
+ /**
1166
+ * Discover if database in strict mode.
1167
+ * This method returns 0 or 1
1168
+ *
1169
+ * @param {Function } Callback function. Optional.
1170
+ */
1171
+ DataSource . prototype . discoverIsStrict = function ( cb ) {
1172
+ this . freeze ( ) ;
1173
+ cb = cb || utils . createPromiseCallback ( ) ;
1174
+
1175
+ if ( this . connector . discoverIsStrict ) {
1176
+ this . connector . discoverIsStrict ( cb ) ;
1177
+ } else if ( cb ) {
1178
+ process . nextTick ( cb ) ;
1179
+ }
1180
+ return cb . promise ;
1181
+ } ;
1182
+
1165
1183
/**
1166
1184
* Discover existing database tables.
1167
1185
* This method returns an array of model objects, including {type, name, onwer}
@@ -1625,6 +1643,7 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
1625
1643
if ( followingRelations ) {
1626
1644
tasks . push ( this . discoverForeignKeys . bind ( this , tableName , options ) ) ;
1627
1645
}
1646
+ tasks . push ( this . discoverIsStrict . bind ( this ) ) ;
1628
1647
1629
1648
async . parallel ( tasks , function ( err , results ) {
1630
1649
if ( err ) {
@@ -1633,6 +1652,10 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
1633
1652
}
1634
1653
1635
1654
const columns = results [ 0 ] ;
1655
+ let isStrict = results [ 2 ] ;
1656
+ if ( isStrict && isStrict [ 0 ] ) {
1657
+ isStrict = isStrict [ 0 ] [ 'globalStrictMode' ] | isStrict [ 0 ] [ 'sessionStrictMode' ] ;
1658
+ }
1636
1659
if ( ! columns || columns . length === 0 ) {
1637
1660
cb ( new Error ( g . f ( 'Table \'%s\' does not exist.' , tableName ) ) ) ;
1638
1661
return cb . promise ;
@@ -1664,11 +1687,19 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
1664
1687
1665
1688
columns . forEach ( function ( item ) {
1666
1689
const propName = nameMapper ( 'column' , item . columnName ) ;
1690
+ const jsonSchema = {
1691
+ nullable : item . nullable === 'Y' || item . nullable === 'YES' ||
1692
+ item . nullable === 1 || item . nullable === true ,
1693
+ } ;
1694
+ if ( isStrict && item . dataLength ) {
1695
+ jsonSchema . maxLength = item . dataLength ;
1696
+ }
1667
1697
schema . properties [ propName ] = {
1668
1698
type : item . type ,
1669
1699
required : ! item . generated && ( item . nullable === 'N' || item . nullable === 'NO' ||
1670
1700
item . nullable === 0 || item . nullable === false ) ,
1671
1701
length : item . dataLength ,
1702
+ jsonSchema,
1672
1703
precision : item . dataPrecision ,
1673
1704
scale : item . dataScale ,
1674
1705
generated : item . generated ,
0 commit comments