Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit a91a0f3c
authored
Dec 17, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5061 from jasonku/5051-fix_sqlite_default_value
5051 fix sqlite default value
2 parents
838d596c
f86987aa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
5 deletions
lib/dialects/sqlite/query.js
test/integration/dialects/sqlite/query-generator.test.js
test/integration/query-interface.test.js
lib/dialects/sqlite/query.js
View file @
a91a0f3
...
@@ -174,11 +174,22 @@ Query.prototype.run = function(sql, parameters) {
...
@@ -174,11 +174,22 @@ Query.prototype.run = function(sql, parameters) {
// this is the sqlite way of getting the metadata of a table
// this is the sqlite way of getting the metadata of a table
result
=
{};
result
=
{};
var
defaultValue
;
results
.
forEach
(
function
(
_result
)
{
results
.
forEach
(
function
(
_result
)
{
if
(
_result
.
dflt_value
===
null
)
{
// Column schema omits any "DEFAULT ..."
defaultValue
=
undefined
;
}
else
if
(
_result
.
dflt_value
===
'NULL'
)
{
// Column schema is a "DEFAULT NULL"
defaultValue
=
null
;
}
else
{
defaultValue
=
_result
.
dflt_value
;
}
result
[
_result
.
name
]
=
{
result
[
_result
.
name
]
=
{
type
:
_result
.
type
,
type
:
_result
.
type
,
allowNull
:
(
_result
.
notnull
===
0
),
allowNull
:
(
_result
.
notnull
===
0
),
defaultValue
:
_result
.
dflt_v
alue
,
defaultValue
:
defaultV
alue
,
primaryKey
:
(
_result
.
pk
===
1
)
primaryKey
:
(
_result
.
pk
===
1
)
};
};
...
@@ -186,10 +197,6 @@ Query.prototype.run = function(sql, parameters) {
...
@@ -186,10 +197,6 @@ Query.prototype.run = function(sql, parameters) {
result
[
_result
.
name
].
defaultValue
=
{
'0'
:
false
,
'1'
:
true
}[
result
[
_result
.
name
].
defaultValue
];
result
[
_result
.
name
].
defaultValue
=
{
'0'
:
false
,
'1'
:
true
}[
result
[
_result
.
name
].
defaultValue
];
}
}
if
(
result
[
_result
.
name
].
defaultValue
===
undefined
)
{
result
[
_result
.
name
].
defaultValue
=
null
;
}
if
(
typeof
result
[
_result
.
name
].
defaultValue
===
'string'
)
{
if
(
typeof
result
[
_result
.
name
].
defaultValue
===
'string'
)
{
result
[
_result
.
name
].
defaultValue
=
result
[
_result
.
name
].
defaultValue
.
replace
(
/'/g
,
''
);
result
[
_result
.
name
].
defaultValue
=
result
[
_result
.
name
].
defaultValue
.
replace
(
/'/g
,
''
);
}
}
...
...
test/integration/dialects/sqlite/query-generator.test.js
View file @
a91a0f3
...
@@ -50,6 +50,10 @@ if (dialect === 'sqlite') {
...
@@ -50,6 +50,10 @@ if (dialect === 'sqlite') {
expectation
:
{
id
:
'INTEGER DEFAULT 0'
}
expectation
:
{
id
:
'INTEGER DEFAULT 0'
}
},
},
{
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
defaultValue
:
undefined
}}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
unique
:
true
}}],
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
unique
:
true
}}],
expectation
:
{
id
:
'INTEGER UNIQUE'
}
expectation
:
{
id
:
'INTEGER UNIQUE'
}
},
},
...
...
test/integration/query-interface.test.js
View file @
a91a0f3
...
@@ -150,6 +150,10 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
...
@@ -150,6 +150,10 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
var
self
=
this
;
var
self
=
this
;
var
Users
=
self
.
sequelize
.
define
(
'_Users'
,
{
var
Users
=
self
.
sequelize
.
define
(
'_Users'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
city
:
{
type
:
DataTypes
.
STRING
,
defaultValue
:
null
},
isAdmin
:
DataTypes
.
BOOLEAN
,
isAdmin
:
DataTypes
.
BOOLEAN
,
enumVals
:
DataTypes
.
ENUM
(
'hello'
,
'world'
)
enumVals
:
DataTypes
.
ENUM
(
'hello'
,
'world'
)
},
{
freezeTableName
:
true
});
},
{
freezeTableName
:
true
});
...
@@ -161,6 +165,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
...
@@ -161,6 +165,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
var
id
=
metadata
.
id
;
var
id
=
metadata
.
id
;
var
username
=
metadata
.
username
;
var
username
=
metadata
.
username
;
var
city
=
metadata
.
city
;
var
isAdmin
=
metadata
.
isAdmin
;
var
isAdmin
=
metadata
.
isAdmin
;
var
enumVals
=
metadata
.
enumVals
;
var
enumVals
=
metadata
.
enumVals
;
...
@@ -177,7 +182,20 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
...
@@ -177,7 +182,20 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}
}
expect
(
username
.
type
).
to
.
equal
(
assertVal
);
expect
(
username
.
type
).
to
.
equal
(
assertVal
);
expect
(
username
.
allowNull
).
to
.
be
.
true
;
expect
(
username
.
allowNull
).
to
.
be
.
true
;
switch
(
dialect
)
{
case
'sqlite'
:
expect
(
username
.
defaultValue
).
to
.
be
.
undefined
;
break
;
default
:
expect
(
username
.
defaultValue
).
to
.
be
.
null
;
expect
(
username
.
defaultValue
).
to
.
be
.
null
;
}
switch
(
dialect
)
{
case
'sqlite'
:
expect
(
city
.
defaultValue
).
to
.
be
.
null
;
break
;
}
assertVal
=
'TINYINT(1)'
;
assertVal
=
'TINYINT(1)'
;
switch
(
dialect
)
{
switch
(
dialect
)
{
...
@@ -190,7 +208,13 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
...
@@ -190,7 +208,13 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}
}
expect
(
isAdmin
.
type
).
to
.
equal
(
assertVal
);
expect
(
isAdmin
.
type
).
to
.
equal
(
assertVal
);
expect
(
isAdmin
.
allowNull
).
to
.
be
.
true
;
expect
(
isAdmin
.
allowNull
).
to
.
be
.
true
;
switch
(
dialect
)
{
case
'sqlite'
:
expect
(
isAdmin
.
defaultValue
).
to
.
be
.
undefined
;
break
;
default
:
expect
(
isAdmin
.
defaultValue
).
to
.
be
.
null
;
expect
(
isAdmin
.
defaultValue
).
to
.
be
.
null
;
}
if
(
dialect
===
'postgres'
||
dialect
===
'postgres-native'
)
{
if
(
dialect
===
'postgres'
||
dialect
===
'postgres-native'
)
{
expect
(
enumVals
.
special
).
to
.
be
.
instanceof
(
Array
);
expect
(
enumVals
.
special
).
to
.
be
.
instanceof
(
Array
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment