@@ -499,7 +499,15 @@ DataSource.prototype.setup = function(dsName, settings) {
499499 debug ( 'Connection fails: %s\nIt will be retried for the next request.' , err ) ;
500500 } else {
501501 g . error ( 'Connection fails: %s\nIt will be retried for the next request.' , err ) ;
502- this . emit ( 'error' , err ) ;
502+ if ( settings . catchFailure ) {
503+ try {
504+ this . emit ( 'error' , err ) ;
505+ } catch ( error ) {
506+ console . log ( error ) ;
507+ }
508+ } else {
509+ this . emit ( 'error' , err ) ;
510+ }
503511 }
504512 } else {
505513 // Either lazyConnect or connector initialize() defers the connection
@@ -1162,6 +1170,24 @@ DataSource.prototype.autoupdate = function(models, cb) {
11621170 return cb . promise ;
11631171} ;
11641172
1173+ /**
1174+ * Discover if database in strict mode.
1175+ * This method returns 0 or 1
1176+ *
1177+ * @param {Function } Callback function. Optional.
1178+ */
1179+ DataSource . prototype . discoverIsStrict = function ( cb ) {
1180+ this . freeze ( ) ;
1181+ cb = cb || utils . createPromiseCallback ( ) ;
1182+
1183+ if ( this . connector . discoverIsStrict ) {
1184+ this . connector . discoverIsStrict ( cb ) ;
1185+ } else if ( cb ) {
1186+ process . nextTick ( cb ) ;
1187+ }
1188+ return cb . promise ;
1189+ } ;
1190+
11651191/**
11661192 * Discover existing database tables.
11671193 * This method returns an array of model objects, including {type, name, onwer}
@@ -1625,6 +1651,7 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
16251651 if ( followingRelations ) {
16261652 tasks . push ( this . discoverForeignKeys . bind ( this , tableName , options ) ) ;
16271653 }
1654+ tasks . push ( this . discoverIsStrict . bind ( this ) ) ;
16281655
16291656 async . parallel ( tasks , function ( err , results ) {
16301657 if ( err ) {
@@ -1633,6 +1660,10 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
16331660 }
16341661
16351662 const columns = results [ 0 ] ;
1663+ let isStrict = results [ 2 ] ;
1664+ if ( isStrict && isStrict [ 0 ] ) {
1665+ isStrict = isStrict [ 0 ] [ 'strictMode' ] ;
1666+ }
16361667 if ( ! columns || columns . length === 0 ) {
16371668 cb ( new Error ( g . f ( 'Table \'%s\' does not exist.' , tableName ) ) ) ;
16381669 return cb . promise ;
@@ -1664,11 +1695,19 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
16641695
16651696 columns . forEach ( function ( item ) {
16661697 const propName = nameMapper ( 'column' , item . columnName ) ;
1698+ const jsonSchema = {
1699+ nullable : item . nullable === 'Y' || item . nullable === 'YES' ||
1700+ item . nullable === 1 || item . nullable === true ,
1701+ } ;
1702+ if ( isStrict && item . dataLength ) {
1703+ jsonSchema . maxLength = item . columns . forEachdataLength ;
1704+ }
16671705 schema . properties [ propName ] = {
16681706 type : item . type ,
16691707 required : ! item . generated && ( item . nullable === 'N' || item . nullable === 'NO' ||
16701708 item . nullable === 0 || item . nullable === false ) ,
16711709 length : item . dataLength ,
1710+ jsonSchema,
16721711 precision : item . dataPrecision ,
16731712 scale : item . dataScale ,
16741713 generated : item . generated ,
0 commit comments