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 8f861533
authored
Apr 30, 2013
by
Martin Aspeli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests + fixes for attributesToSQL
1 parent
644f6eff
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
175 additions
and
16 deletions
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
lib/dialects/sqlite/query-generator.js
spec-jasmine/mysql/query-generator.spec.js
spec-jasmine/postgres/query-generator.spec.js
spec-jasmine/sqlite/query-generator.spec.js
lib/dialects/mysql/query-generator.js
View file @
8f86153
...
@@ -451,14 +451,14 @@ module.exports = (function() {
...
@@ -451,14 +451,14 @@ module.exports = (function() {
}
}
if
(
dataType
.
references
)
{
if
(
dataType
.
references
)
{
template
+=
" REFERENCES "
+
Utils
.
escape
(
dataType
.
references
)
template
+=
" REFERENCES "
+
Utils
.
addTicks
(
dataType
.
references
)
if
(
dataType
.
referencesKeys
)
{
if
(
dataType
.
referencesKeys
)
{
// TODO: This isn't really right - for composite primary keys we need a different approach
// TODO: This isn't really right - for composite primary keys we need a different approach
template
+=
"("
+
dataType
.
referencesKeys
.
map
(
Utils
.
escape
).
join
(
', '
)
+
")"
template
+=
"("
+
dataType
.
referencesKeys
.
map
(
Utils
.
addTicks
).
join
(
', '
)
+
")"
}
else
{
}
else
{
template
+=
"("
+
Utils
.
escape
(
'id'
)
+
")"
template
+=
"("
+
Utils
.
addTicks
(
'id'
)
+
")"
}
}
if
(
dataType
.
onDelete
)
{
if
(
dataType
.
onDelete
)
{
...
...
lib/dialects/postgres/query-generator.js
View file @
8f86153
...
@@ -558,23 +558,23 @@ module.exports = (function() {
...
@@ -558,23 +558,23 @@ module.exports = (function() {
if
(
dataType
.
references
)
{
if
(
dataType
.
references
)
{
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKeys %>)"
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKeys %>)"
replacements
.
referencesTable
=
dataType
.
references
replacements
.
referencesTable
=
QueryGenerator
.
addQuotes
(
dataType
.
references
)
if
(
dataType
.
referencesKeys
)
{
if
(
dataType
.
referencesKeys
)
{
// TODO: This isn't really right - for composite primary keys we need a different approach
// TODO: This isn't really right - for composite primary keys we need a different approach
replacements
.
referencesKeys
=
dataType
.
referencesKeys
.
map
(
Utils
.
escape
).
join
(
', '
)
replacements
.
referencesKeys
=
dataType
.
referencesKeys
.
map
(
QueryGenerator
.
addQuotes
).
join
(
', '
)
}
else
{
}
else
{
replacements
.
referencesKeys
=
Utils
.
escape
(
'id'
)
replacements
.
referencesKeys
=
QueryGenerator
.
addQuotes
(
'id'
)
}
}
if
(
dataType
.
onDelete
)
{
if
(
dataType
.
onDelete
)
{
template
+=
" ON DELETE <%= onDeleteAction %>"
template
+=
" ON DELETE <%= onDeleteAction %>"
replacements
.
onDeleteAction
=
dataType
.
onDelete
Action
.
toUpperCase
()
replacements
.
onDeleteAction
=
dataType
.
onDelete
.
toUpperCase
()
}
}
if
(
dataType
.
onUpdate
)
{
if
(
dataType
.
onUpdate
)
{
template
+=
" ON UPDATE <%= onUpdateAction %>"
template
+=
" ON UPDATE <%= onUpdateAction %>"
replacements
.
onUpdateAction
=
dataType
.
onUpdate
Action
.
toUpperCase
()
replacements
.
onUpdateAction
=
dataType
.
onUpdate
.
toUpperCase
()
}
}
}
}
...
...
lib/dialects/sqlite/query-generator.js
View file @
8f86153
...
@@ -219,23 +219,23 @@ module.exports = (function() {
...
@@ -219,23 +219,23 @@ module.exports = (function() {
if
(
dataType
.
references
)
{
if
(
dataType
.
references
)
{
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKeys %>)"
template
+=
" REFERENCES <%= referencesTable %> (<%= referencesKeys %>)"
replacements
.
referencesTable
=
dataType
.
references
replacements
.
referencesTable
=
Utils
.
addTicks
(
dataType
.
references
)
if
(
dataType
.
referencesKeys
)
{
if
(
dataType
.
referencesKeys
)
{
// TODO: This isn't really right - for composite primary keys we need a different approach
// TODO: This isn't really right - for composite primary keys we need a different approach
replacements
.
referencesKeys
=
dataType
.
referencesKeys
.
map
(
Utils
.
escape
).
join
(
', '
)
replacements
.
referencesKeys
=
dataType
.
referencesKeys
.
map
(
Utils
.
addTicks
).
join
(
', '
)
}
else
{
}
else
{
replacements
.
referencesKeys
=
Utils
.
escape
(
'id'
)
replacements
.
referencesKeys
=
Utils
.
addTicks
(
'id'
)
}
}
if
(
dataType
.
onDelete
)
{
if
(
dataType
.
onDelete
)
{
template
+=
" ON DELETE <%= onDeleteAction %>"
template
+=
" ON DELETE <%= onDeleteAction %>"
replacements
.
onDeleteAction
=
dataType
.
onDelete
Action
.
toUpperCase
()
replacements
.
onDeleteAction
=
dataType
.
onDelete
.
toUpperCase
()
}
}
if
(
dataType
.
onUpdate
)
{
if
(
dataType
.
onUpdate
)
{
template
+=
" ON UPDATE <%= onUpdateAction %>"
template
+=
" ON UPDATE <%= onUpdateAction %>"
replacements
.
onUpdateAction
=
dataType
.
onUpdate
Action
.
toUpperCase
()
replacements
.
onUpdateAction
=
dataType
.
onUpdate
.
toUpperCase
()
}
}
}
}
...
...
spec-jasmine/mysql/query-generator.spec.js
View file @
8f86153
...
@@ -11,7 +11,60 @@ describe('QueryGenerator', function() {
...
@@ -11,7 +11,60 @@ describe('QueryGenerator', function() {
var
suites
=
{
var
suites
=
{
// TODO: Test attributesToSQL
attributesToSQL
:
[
{
arguments
:
[{
id
:
'INTEGER'
}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
'INTEGER'
,
foo
:
'VARCHAR(255)'
}],
expectation
:
{
id
:
'INTEGER'
,
foo
:
'VARCHAR(255)'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
}}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
false
}}],
expectation
:
{
id
:
'INTEGER NOT NULL'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
true
}}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
primaryKey
:
true
,
autoIncrement
:
true
}}],
expectation
:
{
id
:
'INTEGER auto_increment PRIMARY KEY'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
defaultValue
:
0
}}],
expectation
:
{
id
:
'INTEGER DEFAULT 0'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
unique
:
true
}}],
expectation
:
{
id
:
'INTEGER UNIQUE'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`id`)'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
referencesKeys
:
[
'pk'
]}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`pk`)'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
onDelete
:
'CASCADE'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`id`) ON DELETE CASCADE'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
onUpdate
:
'RESTRICT'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`id`) ON UPDATE RESTRICT'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
false
,
autoIncrement
:
true
,
defaultValue
:
1
,
references
:
'Bar'
,
onDelete
:
'CASCADE'
,
onUpdate
:
'RESTRICT'
}}],
expectation
:
{
id
:
'INTEGER NOT NULL auto_increment DEFAULT 1 REFERENCES `Bar` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT'
}
},
],
createTableQuery
:
[
createTableQuery
:
[
{
{
...
...
spec-jasmine/postgres/query-generator.spec.js
View file @
8f86153
...
@@ -15,7 +15,60 @@ describe('QueryGenerator', function() {
...
@@ -15,7 +15,60 @@ describe('QueryGenerator', function() {
var
suites
=
{
var
suites
=
{
// TODO: Test attributesToSQL
attributesToSQL
:
[
{
arguments
:
[{
id
:
'INTEGER'
}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
'INTEGER'
,
foo
:
'VARCHAR(255)'
}],
expectation
:
{
id
:
'INTEGER'
,
foo
:
'VARCHAR(255)'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
}}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
false
}}],
expectation
:
{
id
:
'INTEGER NOT NULL'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
true
}}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
primaryKey
:
true
,
autoIncrement
:
true
}}],
expectation
:
{
id
:
'INTEGER SERIAL PRIMARY KEY'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
defaultValue
:
0
}}],
expectation
:
{
id
:
'INTEGER DEFAULT 0'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
unique
:
true
}}],
expectation
:
{
id
:
'INTEGER UNIQUE'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES "Bar" ("id")'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
referencesKeys
:
[
'pk'
]}}],
expectation
:
{
id
:
'INTEGER REFERENCES "Bar" ("pk")'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
onDelete
:
'CASCADE'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES "Bar" ("id") ON DELETE CASCADE'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
onUpdate
:
'RESTRICT'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES "Bar" ("id") ON UPDATE RESTRICT'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
false
,
defaultValue
:
1
,
references
:
'Bar'
,
onDelete
:
'CASCADE'
,
onUpdate
:
'RESTRICT'
}}],
expectation
:
{
id
:
'INTEGER NOT NULL DEFAULT 1 REFERENCES "Bar" ("id") ON DELETE CASCADE ON UPDATE RESTRICT'
}
},
],
createTableQuery
:
[
createTableQuery
:
[
{
{
...
...
spec-jasmine/sqlite/query-generator.spec.js
View file @
8f86153
...
@@ -10,7 +10,60 @@ describe('QueryGenerator', function() {
...
@@ -10,7 +10,60 @@ describe('QueryGenerator', function() {
var
suites
=
{
var
suites
=
{
// TODO: Test attributesToSQL
attributesToSQL
:
[
{
arguments
:
[{
id
:
'INTEGER'
}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
'INTEGER'
,
foo
:
'VARCHAR(255)'
}],
expectation
:
{
id
:
'INTEGER'
,
foo
:
'VARCHAR(255)'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
}}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
false
}}],
expectation
:
{
id
:
'INTEGER NOT NULL'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
true
}}],
expectation
:
{
id
:
'INTEGER'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
primaryKey
:
true
,
autoIncrement
:
true
}}],
expectation
:
{
id
:
'INTEGER PRIMARY KEY AUTOINCREMENT'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
defaultValue
:
0
}}],
expectation
:
{
id
:
'INTEGER DEFAULT 0'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
unique
:
true
}}],
expectation
:
{
id
:
'INTEGER UNIQUE'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`id`)'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
referencesKeys
:
[
'pk'
]}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`pk`)'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
onDelete
:
'CASCADE'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`id`) ON DELETE CASCADE'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
,
onUpdate
:
'RESTRICT'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`id`) ON UPDATE RESTRICT'
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
allowNull
:
false
,
defaultValue
:
1
,
references
:
'Bar'
,
onDelete
:
'CASCADE'
,
onUpdate
:
'RESTRICT'
}}],
expectation
:
{
id
:
'INTEGER NOT NULL DEFAULT 1 REFERENCES `Bar` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT'
}
},
],
createTableQuery
:
[
createTableQuery
:
[
{
{
...
...
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