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 8f4f2f12
authored
Aug 02, 2014
by
Sascha Depold
Committed by
Matt Broadstone
Dec 09, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add first steps for createTableQuery
1 parent
438cea4e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
lib/dialects/mssql/query-generator.js
lib/dialects/mssql/query-generator.js
View file @
8f4f2f1
...
@@ -6,6 +6,11 @@ module.exports = (function() {
...
@@ -6,6 +6,11 @@ module.exports = (function() {
var
QueryGenerator
=
{
var
QueryGenerator
=
{
dialect
:
'mssql'
,
dialect
:
'mssql'
,
quoteIdentifier
:
function
(
identifier
,
force
)
{
if
(
identifier
===
'*'
)
return
identifier
;
return
Utils
.
addTicks
(
identifier
,
'"'
);
},
showTablesQuery
:
function
()
{
showTablesQuery
:
function
()
{
return
'SELECT * FROM sys.Tables'
;
return
'SELECT * FROM sys.Tables'
;
},
},
...
@@ -18,6 +23,39 @@ module.exports = (function() {
...
@@ -18,6 +23,39 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)({
return
Utils
.
_
.
template
(
query
)({
tableName
:
tableName
tableName
:
tableName
});
});
},
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
var
query
=
"IF OBJECT_ID('<%= unquotedTable %>', N'U') IS NULL CREATE TABLE <%= table %> (<%= attributes%>)"
,
attrStr
=
[]
,
self
=
this
,
primaryKeys
=
Utils
.
_
.
keys
(
Utils
.
_
.
pick
(
attributes
,
function
(
dataType
){
return
dataType
.
indexOf
(
'PRIMARY KEY'
)
>=
0
;
}));
for
(
var
attr
in
attributes
)
{
if
(
attributes
.
hasOwnProperty
(
attr
))
{
var
dataType
=
attributes
[
attr
];
if
(
primaryKeys
.
length
>
1
){
dataType
=
dataType
.
replace
(
/ PRIMARY KEY/
,
''
);
}
attrStr
.
push
(
self
.
quote
(
attr
)
+
" "
+
dataType
);
}
}
if
(
primaryKeys
.
length
>
1
)
{
attrStr
.
push
(
'PRIMARY KEY('
+
primaryKeys
.
map
(
function
(
column
){
return
self
.
quote
(
column
);
}).
join
(
', '
)
+
')'
);
}
var
values
=
{
unquotedTable
:
tableName
,
table
:
self
.
quote
(
tableName
),
attributes
:
attrStr
.
join
(
", "
)
};
return
Utils
.
_
.
template
(
query
)(
values
).
trim
()
+
";"
;
}
}
};
};
...
...
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