-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
/
index.js
64 lines (50 loc) 路 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const { Dialect } = require('../dialect');
const MysqlSchemaInspector = require('./schema-inspector');
class MysqlDialect extends Dialect {
constructor(db) {
super(db);
this.schemaInspector = new MysqlSchemaInspector(db);
}
configure() {
this.db.config.connection.connection.supportBigNumbers = true;
this.db.config.connection.connection.bigNumberStrings = true;
this.db.config.connection.connection.typeCast = (field, next) => {
if (field.type === 'DECIMAL' || field.type === 'NEWDECIMAL') {
var value = field.string();
return value === null ? null : Number(value);
}
if (field.type === 'TINY' && field.length === 1) {
let value = field.string();
return value ? value === '1' : null;
}
if (field.type === 'DATE') {
return field.string();
}
return next();
};
}
async initialize() {
try {
await this.db.connection.raw(`set session sql_require_primary_key = 0;`);
} catch (err) {
// Ignore error due to lack of session permissions
}
}
async startSchemaUpdate() {
await this.db.connection.raw(`set foreign_key_checks = 0;`);
}
async endSchemaUpdate() {
await this.db.connection.raw(`set foreign_key_checks = 1;`);
}
supportsUnsigned() {
return true;
}
usesForeignKeys() {
return true;
}
transformErrors(error) {
super.transformErrors(error);
}
}
module.exports = MysqlDialect;