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 f3910991
authored
Dec 11, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added implementation of remove index query
1 parent
e21579b8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
36 deletions
lib/connectors/mysql/query-generator.js
lib/connectors/query-generator.js
lib/connectors/mysql/query-generator.js
View file @
f391099
...
@@ -3,10 +3,6 @@ var Utils = require("../../utils")
...
@@ -3,10 +3,6 @@ var Utils = require("../../utils")
module
.
exports
=
(
function
()
{
module
.
exports
=
(
function
()
{
var
QueryGenerator
=
{
var
QueryGenerator
=
{
/*
Returns a query for creating a table.
Attributes should have the format: {attributeName: type, attr2: type2} --> {title: 'VARCHAR(255)'}
*/
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
...
@@ -121,9 +117,6 @@ module.exports = (function() {
...
@@ -121,9 +117,6 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
options
)
return
Utils
.
_
.
template
(
query
)(
options
)
},
},
/*
Returns an insert into command. Parameters: table name + hash of attribute-value-pairs.
*/
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
...
@@ -138,16 +131,6 @@ module.exports = (function() {
...
@@ -138,16 +131,6 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
},
/*
Returns an update query.
Parameters:
- tableName -> Name of the table
- values -> A hash with attribute-value-pairs
- where -> A hash with conditions (e.g. {name: 'foo'})
OR an ID as integer
OR a string with conditions (e.g. 'name="foo"').
If you use a string, you have to escape it on your own.
*/
updateQuery
:
function
(
tableName
,
values
,
where
)
{
updateQuery
:
function
(
tableName
,
values
,
where
)
{
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
var
replacements
=
{
var
replacements
=
{
...
@@ -161,17 +144,6 @@ module.exports = (function() {
...
@@ -161,17 +144,6 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
},
/*
Returns a deletion query.
Parameters:
- tableName -> Name of the table
- where -> A hash with conditions (e.g. {name: 'foo'})
OR an ID as integer
OR a string with conditions (e.g. 'name="foo"').
If you use a string, you have to escape it on your own.
Options:
- limit -> Maximaum count of lines to delete
*/
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
options
.
limit
=
options
.
limit
||
1
options
.
limit
=
options
.
limit
||
1
...
@@ -234,9 +206,16 @@ module.exports = (function() {
...
@@ -234,9 +206,16 @@ module.exports = (function() {
})
})
},
},
/*
removeIndexQuery
:
function
(
tableName
,
indexNameOrAttributes
)
{
Takes something and transforms it into values of a where condition.
var
sql
=
"DROP INDEX <%= indexName %> ON <%= tableName %>"
*/
,
indexName
=
indexNameOrAttributes
if
(
typeof
indexName
==
'string'
)
indexName
=
Utils
.
_
.
underscored
(
tableName
+
'_'
+
indexNameOrAttributes
.
join
(
'_'
))
return
Utils
.
_
.
template
(
sql
)({
tableName
:
tableName
,
indexName
:
indexName
})
},
getWhereConditions
:
function
(
smth
)
{
getWhereConditions
:
function
(
smth
)
{
var
result
=
null
var
result
=
null
...
@@ -252,10 +231,6 @@ module.exports = (function() {
...
@@ -252,10 +231,6 @@ module.exports = (function() {
return
result
return
result
},
},
/*
Takes a hash and transforms it into a mysql where condition: {key: value, key2: value2} ==> key=value AND key2=value2
The values are transformed by the relevant datatype.
*/
hashToWhereConditions
:
function
(
hash
)
{
hashToWhereConditions
:
function
(
hash
)
{
return
Utils
.
_
.
map
(
hash
,
function
(
value
,
key
)
{
return
Utils
.
_
.
map
(
hash
,
function
(
value
,
key
)
{
var
_key
=
Utils
.
addTicks
(
key
)
var
_key
=
Utils
.
addTicks
(
key
)
...
...
lib/connectors/query-generator.js
View file @
f391099
...
@@ -159,7 +159,13 @@ module.exports = (function() {
...
@@ -159,7 +159,13 @@ module.exports = (function() {
throwMethodUndefined
(
'showIndexQuery'
)
throwMethodUndefined
(
'showIndexQuery'
)
},
},
removeIndexQuery
:
function
(
tableName
,
options
)
{
/*
Returns a remove index query.
Parameters:
- tableName: Name of an existing table.
- indexNameOrAttributes: The name of the index as string or an array of attribute names.
*/
removeIndexQuery
:
function
(
tableName
,
indexNameOrAttributes
)
{
throwMethodUndefined
(
'removeIndexQuery'
)
throwMethodUndefined
(
'removeIndexQuery'
)
},
},
...
...
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