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 5db3a650
authored
Sep 24, 2014
by
Joel Trost
Committed by
Matt Broadstone
Dec 09, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More separation and a template file for abstract
1 parent
65df6b4f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
802 additions
and
21 deletions
lib/dialects/mssql/query-generator.js
lib/dialects/mssql/sql-generator.js
lib/dialects/templates/query-generator.js
lib/dialects/mssql/query-generator.js
View file @
5db3a65
...
...
@@ -11,7 +11,24 @@ var Utils = require('../../utils')
module
.
exports
=
(
function
()
{
var
QueryGenerator
=
{
dialect
:
'mssql'
,
get
options
(){
return
SqlGenerator
.
options
;
},
set
options
(
opt
)
{
SqlGenerator
.
options
=
opt
;
},
get
dialect
(){
return
SqlGenerator
.
dialect
;
},
set
dialect
(
dial
)
{
SqlGenerator
.
dialect
=
dial
;
},
get
sequelize
(){
return
SqlGenerator
.
sequelize
;
},
set
sequelize
(
seq
)
{
SqlGenerator
.
sequelize
=
seq
;
},
addSchema
:
function
(
param
)
{
var
self
=
this
...
...
@@ -48,10 +65,22 @@ module.exports = (function() {
return
SqlGenerator
.
getCreateTableSql
(
tableName
,
attributes
,
options
);
},
renameTableQuery
:
function
(
before
,
after
)
{
throwMethodUndefined
(
'renameTableQuery'
);
},
showTablesQuery
:
function
()
{
return
SqlGenerator
.
showTableSql
();
},
/*
Returns a rename table query.
Parameters:
- originalTableName: Name of the table before execution.
- futureTableName: Name of the table after execution.
*/
dropTableQuery
:
function
(
tableName
,
options
)
{
return
SqlGenerator
.
dropTableSql
(
tableName
,
options
);
},
...
...
@@ -102,13 +131,85 @@ module.exports = (function() {
return
SqlGenerator
.
insertSql
(
table
,
valueHash
,
modelAttributes
,
options
);
},
showIndexQuery
:
function
(
tableName
,
options
)
{
return
SqlGenerator
.
showIndexSql
(
tableName
,
options
);
/*
Returns an insert into command for multiple values.
Parameters: table name + list of hashes of attribute-value-pairs.
*/
/* istanbul ignore next */
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
)
{
throwMethodUndefined
(
'bulkInsertQuery'
);
},
/*
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
,
attrValueHash
,
where
,
options
,
attributes
)
{
throwMethodUndefined
(
'updateQuery'
);
},
/*
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
- truncate -> boolean - whether to use an 'optimized' mechanism (i.e. TRUNCATE) if available,
note that this should not be the default behaviour because TRUNCATE does not
always play nicely (e.g. InnoDB tables with FK constraints)
(@see http://dev.mysql.com/doc/refman/5.6/en/truncate-table.html).
Note that truncate must ignore limit and where
*/
/* istanbul ignore next */
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
throwMethodUndefined
(
'deleteQuery'
);
},
/*
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.
*/
incrementQuery
:
function
(
tableName
,
attrValueHash
,
where
,
options
)
{
throwMethodUndefined
(
'incrementQuery'
);
},
nameIndexes
:
function
(
indexes
,
rawTablename
)
{
return
Utils
.
_
.
map
(
indexes
,
function
(
index
)
{
if
(
!
index
.
hasOwnProperty
(
'name'
))
{
var
onlyAttributeNames
=
index
.
fields
.
map
(
function
(
attribute
)
{
return
(
typeof
attribute
===
'string'
)
?
attribute
:
attribute
.
attribute
;
}.
bind
(
this
));
index
.
name
=
Utils
.
inflection
.
underscore
(
rawTablename
+
'_'
+
onlyAttributeNames
.
join
(
'_'
));
}
return
index
;
});
},
addIndexQuery
:
function
(
tableName
,
attributes
,
options
,
rawTablename
)
{
return
SqlGenerator
.
addIndexSql
(
tableName
,
attributes
,
options
,
rawTablename
);
},
showIndexQuery
:
function
(
tableName
,
options
)
{
return
SqlGenerator
.
showIndexSql
(
tableName
,
options
);
},
removeIndexQuery
:
function
(
tableName
,
indexNameOrAttributes
)
{
return
SqlGenerator
.
removeIndexSql
(
tableName
,
indexNameOrAttributes
);
},
...
...
@@ -128,10 +229,109 @@ module.exports = (function() {
return
result
;
},
/*
Returns all auto increment fields of a factory.
*/
/* istanbul ignore next */
findAutoIncrementField
:
function
(
factory
)
{
var
fields
=
[];
for
(
var
name
in
factory
.
attributes
)
{
if
(
factory
.
attributes
.
hasOwnProperty
(
name
))
{
var
definition
=
factory
.
attributes
[
name
];
if
(
definition
&&
definition
.
autoIncrement
)
{
fields
.
push
(
name
);
}
}
}
return
fields
;
},
quoteTable
:
function
(
param
,
as
)
{
throwMethodUndefined
(
'quoteTable'
);
},
quote
:
function
(
obj
,
parent
,
force
)
{
throwMethodUndefined
(
'quote'
);
},
/*
Create a trigger
*/
/* istanbul ignore next */
createTrigger
:
function
(
tableName
,
triggerName
,
timingType
,
fireOnArray
,
functionName
,
functionParams
,
optionsArray
)
{
throwMethodUndefined
(
'createTrigger'
);
},
/*
Drop a trigger
*/
/* istanbul ignore next */
dropTrigger
:
function
(
tableName
,
triggerName
)
{
throwMethodUndefined
(
'dropTrigger'
);
},
/*
Rename a trigger
*/
/* istanbul ignore next */
renameTrigger
:
function
(
tableName
,
oldTriggerName
,
newTriggerName
)
{
throwMethodUndefined
(
'renameTrigger'
);
},
/*
Create a function
*/
/* istanbul ignore next */
createFunction
:
function
(
functionName
,
params
,
returnType
,
language
,
body
,
options
)
{
throwMethodUndefined
(
'createFunction'
);
},
describeTableQuery
:
function
(
tableName
,
schema
,
schemaDelimiter
)
{
return
SqlGenerator
.
describeTableSql
(
tableName
,
schema
,
schemaDelimiter
);
},
/*
Drop a function
*/
/* istanbul ignore next */
dropFunction
:
function
(
functionName
,
params
)
{
throwMethodUndefined
(
'dropFunction'
);
},
/*
Rename a function
*/
/* istanbul ignore next */
renameFunction
:
function
(
oldFunctionName
,
params
,
newFunctionName
)
{
throwMethodUndefined
(
'renameFunction'
);
},
/*
Escape an identifier (e.g. a table or attribute name)
*/
/* istanbul ignore next */
quoteIdentifier
:
function
(
identifier
,
force
)
{
throwMethodUndefined
(
'quoteIdentifier'
);
},
/*
Split an identifier into .-separated tokens and quote each part
*/
quoteIdentifiers
:
function
(
identifiers
,
force
)
{
throwMethodUndefined
(
'quoteIdentifiers'
);
},
/*
Escape a value (e.g. a string, number or date)
*/
escape
:
function
(
value
,
field
)
{
throwMethodUndefined
(
'escape'
);
},
/**
* Generates an SQL query that returns all foreign keys of a table.
*
...
...
@@ -667,8 +867,59 @@ module.exports = (function() {
}
}
return
query
;
},
/*
Takes something and transforms it into values of a where condition.
*/
getWhereConditions
:
function
(
smth
,
tableName
,
factory
,
options
,
prepend
)
{
throwMethodUndefined
(
'getWhereConditions'
);
},
prependTableNameToHash
:
function
(
tableName
,
hash
)
{
throwMethodUndefined
(
'prependTableNameToHash'
);
},
findAssociation
:
function
(
attribute
,
dao
)
{
throwMethodUndefined
(
'findAssociation'
);
},
getAssociationFilterDAO
:
function
(
filterStr
,
dao
)
{
throwMethodUndefined
(
'getAssociationFilterDAO'
);
},
isAssociationFilter
:
function
(
filterStr
,
dao
,
options
)
{
throwMethodUndefined
(
'isAssociationFilter'
);
},
getAssociationFilterColumn
:
function
(
filterStr
,
dao
,
options
)
{
throwMethodUndefined
(
'getAssociationFilterColumn'
);
},
getConditionalJoins
:
function
(
options
,
originalDao
)
{
throwMethodUndefined
(
'getConditionalJoins'
);
},
arrayValue
:
function
(
value
,
key
,
_key
,
factory
,
logicResult
)
{
throwMethodUndefined
(
'arrayValue'
);
},
/*
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
,
dao
,
options
)
{
throwMethodUndefined
(
'hashToWhereConditions'
);
},
booleanValue
:
function
(
value
)
{
return
value
;
}
};
return
Utils
.
_
.
extend
(
Utils
.
_
.
clone
(
require
(
'../mysql/query-generator'
)),
QueryGenerator
);
/* istanbul ignore next */
var
throwMethodUndefined
=
function
(
methodName
)
{
throw
new
Error
(
'The method "'
+
methodName
+
'" is not defined! Please add it to your sql dialect.'
);
};
return
QueryGenerator
;
})();
lib/dialects/mssql/sql-generator.js
View file @
5db3a65
...
...
@@ -2,7 +2,10 @@
var
Utils
=
require
(
'../../utils'
)
,
SqlString
=
require
(
'../../sql-string'
)
,
DataTypes
=
require
(
'./data-types'
);
,
DataTypes
=
require
(
'./data-types'
)
,
options
,
dialect
,
sequelize
;
/*
Escape a value (e.g. a string, number or date)
...
...
@@ -21,14 +24,7 @@ var attributeMap = {
onUpdate
:
"ON UPDATE"
,
default
:
"DEFAULT"
};
//mssql doesnt support time zone
function
escape
(
value
,
field
)
{
if
(
value
&&
value
.
_isSequelizeMethod
)
{
return
value
.
toString
();
}
else
{
return
SqlString
.
escape
(
value
,
false
,
null
,
dialect
,
field
);
}
}
function
quoteIdentifier
(
identifier
,
force
)
{
if
(
identifier
===
'*'
)
return
identifier
;
return
Utils
.
addTicks
(
identifier
,
'"'
);
...
...
@@ -93,6 +89,31 @@ function addTableExistsWrapper(tableName, query, exists){
module
.
exports
=
{
get
options
(){
return
options
;
},
set
options
(
opt
)
{
options
=
opt
;
},
get
dialect
(){
return
dialect
;
},
set
dialect
(
dial
)
{
dialect
=
dial
;
},
get
sequelize
(){
return
sequelize
;
},
set
sequelize
(
seq
)
{
sequelize
=
seq
;
},
escape
:
function
(
value
,
field
)
{
if
(
value
&&
value
.
_isSequelizeMethod
)
{
return
value
.
toString
();
}
else
{
return
SqlString
.
escape
(
value
,
false
,
options
.
timezone
,
dialect
,
field
);
}
},
showTableSql
:
function
(){
return
'SELECT name FROM sys.Tables;'
;
},
...
...
@@ -143,12 +164,8 @@ module.exports = {
,
value
,
modelAttributeMap
=
{};
if
(
this
.
_dialect
.
supports
[
'RETURNING'
]
&&
options
.
returning
)
{
valueQuery
+=
' OUTPUT <%= selFields %> VALUES (<%= values %>)'
;
emptyQuery
+=
' OUTPUT <%= selFields %> VALUES ()'
;
}
else
{
valueQuery
+=
' VALUES (<%= values %>)'
;
}
valueHash
=
Utils
.
removeNullValuesFromHash
(
valueHash
,
this
.
options
.
omitNull
);
...
...
@@ -162,11 +179,11 @@ module.exports = {
valueQuery
=
'SET IDENTITY_INSERT <%= table %> ON;'
+
valueQuery
+
'; SET IDENTITY_INSERT <%= table %> OFF'
;
values
.
push
(
escape
(
value
,
(
modelAttributeMap
&&
modelAttributeMap
[
key
])
||
undefined
));
values
.
push
(
this
.
escape
(
value
,
(
modelAttributeMap
&&
modelAttributeMap
[
key
])
||
undefined
));
}
else
if
(
value
)
{
fields
.
push
(
quoteIdentifier
(
key
));
selFields
.
push
(
wrapSingleQuote
(
key
));
values
.
push
(
escape
(
value
,
(
modelAttributeMap
&&
modelAttributeMap
[
key
])
||
undefined
));
values
.
push
(
this
.
escape
(
value
,
(
modelAttributeMap
&&
modelAttributeMap
[
key
])
||
undefined
));
}
}
}
...
...
@@ -271,7 +288,7 @@ module.exports = {
var
template
=
'VARCHAR(10) NOT NULL CHECK ("'
+
attribute
.
field
+
'" IN('
+
Utils
.
_
.
map
(
attribute
.
values
,
function
(
value
)
{
return
escape
(
value
);
return
this
.
escape
(
value
);
}.
bind
(
this
)).
join
(
', '
)
+
'))'
;
return
template
;
},
...
...
@@ -310,7 +327,7 @@ module.exports = {
if
(
attribute
.
type
!==
'TEXT'
&&
attribute
.
type
.
_binary
===
false
&&
Utils
.
defaultValueSchemable
(
attribute
.
defaultValue
))
{
if
(
options
&&
escape
(
attribute
.
defaultValue
)){
if
(
options
&&
this
.
escape
(
attribute
.
defaultValue
)){
template
.
push
(
attributeMap
.
default
+
wrapSingleQuote
(
attribute
.
defaultValue
));
}
}
...
...
lib/dialects/templates/query-generator.js
0 → 100644
View file @
5db3a65
'use strict'
;
module
.
exports
=
(
function
()
{
var
QueryGenerator
=
{
get
options
(){
throwMethodUndefined
(
'get options'
);
},
set
options
(
opt
)
{
throwMethodUndefined
(
'set options'
);
},
get
dialect
(){
throwMethodUndefined
(
'get dialect'
);
},
set
dialect
(
dial
)
{
throwMethodUndefined
(
'set dialect'
);
},
get
sequelize
(){
throwMethodUndefined
(
'get sequelize'
);
},
set
sequelize
(
seq
)
{
throwMethodUndefined
(
'set sequelize'
);
},
addSchema
:
function
(
param
)
{
throwMethodUndefined
(
'addSchema'
);
},
/*
Returns a query for creating a table.
Parameters:
- tableName: Name of the new table.
- attributes: An object with containing attribute-attributeType-pairs.
Attributes should have the format:
{attributeName: type, attr2: type2}
--> e.g. {title: 'VARCHAR(255)'}
- options: An object with options.
Defaults: { engine: 'InnoDB', charset: null }
*/
/* istanbul ignore next */
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
throwMethodUndefined
(
'createTableQuery'
);
},
describeTableQuery
:
function
(
tableName
,
schema
,
schemaDelimiter
)
{
throwMethodUndefined
(
'describeTableQuery'
);
},
/*
Returns a query for dropping a table.
*/
dropTableQuery
:
function
(
tableName
,
options
)
{
throwMethodUndefined
(
'dropTableQuery'
);
},
/*
Returns a rename table query.
Parameters:
- originalTableName: Name of the table before execution.
- futureTableName: Name of the table after execution.
*/
renameTableQuery
:
function
(
before
,
after
)
{
throwMethodUndefined
(
'renameTableQuery'
);
},
/*
Returns a query, which gets all available table names in the database.
*/
/* istanbul ignore next */
showTablesQuery
:
function
()
{
throwMethodUndefined
(
'showTablesQuery'
);
},
/*
Returns a query, which adds an attribute to an existing table.
Parameters:
- tableName: Name of the existing table.
- attributes: A hash with attribute-attributeOptions-pairs.
- key: attributeName
- value: A hash with attribute specific options:
- type: DataType
- defaultValue: A String with the default value
- allowNull: Boolean
*/
/* istanbul ignore next */
addColumnQuery
:
function
(
tableName
,
attributes
)
{
throwMethodUndefined
(
'addColumnQuery'
);
},
/*
Returns a query, which removes an attribute from an existing table.
Parameters:
- tableName: Name of the existing table
- attributeName: Name of the obsolete attribute.
*/
/* istanbul ignore next */
removeColumnQuery
:
function
(
tableName
,
attributeName
)
{
throwMethodUndefined
(
'removeColumnQuery'
);
},
/*
Returns a query, which modifies an existing attribute from a table.
Parameters:
- tableName: Name of the existing table.
- attributes: A hash with attribute-attributeOptions-pairs.
- key: attributeName
- value: A hash with attribute specific options:
- type: DataType
- defaultValue: A String with the default value
- allowNull: Boolean
*/
/* istanbul ignore next */
changeColumnQuery
:
function
(
tableName
,
attributes
)
{
throwMethodUndefined
(
'changeColumnQuery'
);
},
/*
Returns a query, which renames an existing attribute.
Parameters:
- tableName: Name of an existing table.
- attrNameBefore: The name of the attribute, which shall be renamed.
- attrNameAfter: The name of the attribute, after renaming.
*/
/* istanbul ignore next */
renameColumnQuery
:
function
(
tableName
,
attrNameBefore
,
attrNameAfter
)
{
throwMethodUndefined
(
'renameColumnQuery'
);
},
/*
Returns an insert into command. Parameters: table name + hash of attribute-value-pairs.
*/
insertQuery
:
function
(
table
,
valueHash
,
modelAttributes
,
options
)
{
throwMethodUndefined
(
'insertQuery'
);
},
/*
Returns an insert into command for multiple values.
Parameters: table name + list of hashes of attribute-value-pairs.
*/
/* istanbul ignore next */
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
)
{
throwMethodUndefined
(
'bulkInsertQuery'
);
},
/*
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
,
attrValueHash
,
where
,
options
,
attributes
)
{
throwMethodUndefined
(
'updateQuery'
);
},
/*
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
- truncate -> boolean - whether to use an 'optimized' mechanism (i.e. TRUNCATE) if available,
note that this should not be the default behaviour because TRUNCATE does not
always play nicely (e.g. InnoDB tables with FK constraints)
(@see http://dev.mysql.com/doc/refman/5.6/en/truncate-table.html).
Note that truncate must ignore limit and where
*/
/* istanbul ignore next */
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
throwMethodUndefined
(
'deleteQuery'
);
},
/*
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.
*/
incrementQuery
:
function
(
tableName
,
attrValueHash
,
where
,
options
)
{
throwMethodUndefined
(
'incrementQuery'
);
},
nameIndexes
:
function
(
indexes
,
rawTablename
)
{
throwMethodUndefined
(
'nameIndexes'
);
},
/*
Returns an add index query.
Parameters:
- tableName -> Name of an existing table, possibly with schema.
- attributes:
An array of attributes as string or as hash.
If the attribute is a hash, it must have the following content:
- attribute: The name of the attribute/column
- length: An integer. Optional
- order: 'ASC' or 'DESC'. Optional
- options:
- indicesType: UNIQUE|FULLTEXT|SPATIAL
- indexName: The name of the index. Default is <tableName>_<attrName1>_<attrName2>
- parser
- rawTablename, the name of the table, without schema. Used to create the name of the index
*/
addIndexQuery
:
function
(
tableName
,
attributes
,
options
,
rawTablename
)
{
throwMethodUndefined
(
'addIndexQuery'
);
},
/*
Returns an show index query.
Parameters:
- tableName: Name of an existing table.
- options:
- database: Name of the database.
*/
/* istanbul ignore next */
showIndexQuery
:
function
(
tableName
,
options
)
{
throwMethodUndefined
(
'showIndexQuery'
);
},
/*
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.
*/
/* istanbul ignore next */
removeIndexQuery
:
function
(
tableName
,
indexNameOrAttributes
)
{
throwMethodUndefined
(
'removeIndexQuery'
);
},
/*
This method transforms an array of attribute hashes into equivalent
sql attribute definition.
*/
/* istanbul ignore next */
attributesToSQL
:
function
(
attributes
)
{
throwMethodUndefined
(
'attributesToSQL'
);
},
/*
Returns all auto increment fields of a factory.
*/
/* istanbul ignore next */
findAutoIncrementField
:
function
(
factory
)
{
throwMethodUndefined
(
'findAutoIncrementField'
);
},
quoteTable
:
function
(
param
,
as
)
{
throwMethodUndefined
(
'quoteTable'
);
},
/*
Quote an object based on its type. This is a more general version of quoteIdentifiers
Strings: should proxy to quoteIdentifiers
Arrays:
* Expects array in the form: [<model> (optional), <model> (optional),... String, String (optional)]
Each <model> can be a model or an object {model: Model, as: String}, matching include
* Zero or more models can be included in the array and are used to trace a path through the tree of
included nested associations. This produces the correct table name for the ORDER BY/GROUP BY SQL
and quotes it.
* If a single string is appended to end of array, it is quoted.
If two strings appended, the 1st string is quoted, the 2nd string unquoted.
Objects:
* If raw is set, that value should be returned verbatim, without quoting
* If fn is set, the string should start with the value of fn, starting paren, followed by
the values of cols (which is assumed to be an array), quoted and joined with ', ',
unless they are themselves objects
* If direction is set, should be prepended
Currently this function is only used for ordering / grouping columns and Sequelize.col(), but it could
potentially also be used for other places where we want to be able to call SQL functions (e.g. as default values)
*/
quote
:
function
(
obj
,
parent
,
force
)
{
throwMethodUndefined
(
'quote'
);
},
/*
Create a trigger
*/
/* istanbul ignore next */
createTrigger
:
function
(
tableName
,
triggerName
,
timingType
,
fireOnArray
,
functionName
,
functionParams
,
optionsArray
)
{
throwMethodUndefined
(
'createTrigger'
);
},
/*
Drop a trigger
*/
/* istanbul ignore next */
dropTrigger
:
function
(
tableName
,
triggerName
)
{
throwMethodUndefined
(
'dropTrigger'
);
},
/*
Rename a trigger
*/
/* istanbul ignore next */
renameTrigger
:
function
(
tableName
,
oldTriggerName
,
newTriggerName
)
{
throwMethodUndefined
(
'renameTrigger'
);
},
/*
Create a function
*/
/* istanbul ignore next */
createFunction
:
function
(
functionName
,
params
,
returnType
,
language
,
body
,
options
)
{
throwMethodUndefined
(
'createFunction'
);
},
/*
Drop a function
*/
/* istanbul ignore next */
dropFunction
:
function
(
functionName
,
params
)
{
throwMethodUndefined
(
'dropFunction'
);
},
/*
Rename a function
*/
/* istanbul ignore next */
renameFunction
:
function
(
oldFunctionName
,
params
,
newFunctionName
)
{
throwMethodUndefined
(
'renameFunction'
);
},
/*
Escape an identifier (e.g. a table or attribute name)
*/
/* istanbul ignore next */
quoteIdentifier
:
function
(
identifier
,
force
)
{
throwMethodUndefined
(
'quoteIdentifier'
);
},
/*
Split an identifier into .-separated tokens and quote each part
*/
quoteIdentifiers
:
function
(
identifiers
,
force
)
{
throwMethodUndefined
(
'quoteIdentifiers'
);
},
/*
Escape a value (e.g. a string, number or date)
*/
escape
:
function
(
value
,
field
)
{
throwMethodUndefined
(
'escape'
);
},
/**
* Generates an SQL query that returns all foreign keys of a table.
*
* @param {String} tableName The name of the table.
* @param {String} schemaName The name of the schema.
* @return {String} The generated sql query.
*/
/* istanbul ignore next */
getForeignKeysQuery
:
function
(
tableName
,
schemaName
)
{
throwMethodUndefined
(
'getForeignKeysQuery'
);
},
/**
* Generates an SQL query that removes a foreign key from a table.
*
* @param {String} tableName The name of the table.
* @param {String} foreignKey The name of the foreign key constraint.
* @return {String} The generated sql query.
*/
/* istanbul ignore next */
dropForeignKeyQuery
:
function
(
tableName
,
foreignKey
)
{
throwMethodUndefined
(
'dropForeignKeyQuery'
);
},
/*
Returns a query for selecting elements in the table <tableName>.
Options:
- attributes -> An array of attributes (e.g. ['name', 'birthday']). Default: *
- 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.
- order -> e.g. 'id DESC'
- group
- limit -> The maximum count you want to get.
- offset -> An offset value to start from. Only useable with limit!
*/
selectQuery
:
function
(
tableName
,
options
,
model
)
{
// Enter and change at your own peril -- Mick Hansen
throwMethodUndefined
(
'selectQuery'
);
},
/**
* Returns a query that starts a transaction.
*
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @return {String} The generated sql query.
*/
setAutocommitQuery
:
function
(
value
)
{
throwMethodUndefined
(
'setAutocommitQuery'
);
},
/**
* Returns a query that sets the transaction isolation level.
*
* @param {String} value The isolation level.
* @param {Object} options An object with options.
* @return {String} The generated sql query.
*/
setIsolationLevelQuery
:
function
(
value
,
options
)
{
throwMethodUndefined
(
'setIsolationLevelQuery'
);
},
/**
* Returns a query that starts a transaction.
*
* @param {Transaction} transaction
* @param {Object} options An object with options.
* @return {String} The generated sql query.
*/
startTransactionQuery
:
function
(
transaction
,
options
)
{
throwMethodUndefined
(
'startTransactionQuery'
);
},
/**
* Returns a query that commits a transaction.
*
* @param {Object} options An object with options.
* @return {String} The generated sql query.
*/
commitTransactionQuery
:
function
(
options
)
{
throwMethodUndefined
(
'commitTransactionQuery'
);
},
/**
* Returns a query that rollbacks a transaction.
*
* @param {Transaction} transaction
* @param {Object} options An object with options.
* @return {String} The generated sql query.
*/
rollbackTransactionQuery
:
function
(
transaction
,
options
)
{
throwMethodUndefined
(
'rollbackTransactionQuery'
);
},
addLimitAndOffset
:
function
(
options
,
query
)
{
throwMethodUndefined
(
'addLimitAndOffset'
);
},
/*
Takes something and transforms it into values of a where condition.
*/
getWhereConditions
:
function
(
smth
,
tableName
,
factory
,
options
,
prepend
)
{
throwMethodUndefined
(
'getWhereConditions'
);
},
prependTableNameToHash
:
function
(
tableName
,
hash
)
{
throwMethodUndefined
(
'prependTableNameToHash'
);
},
findAssociation
:
function
(
attribute
,
dao
)
{
throwMethodUndefined
(
'findAssociation'
);
},
getAssociationFilterDAO
:
function
(
filterStr
,
dao
)
{
throwMethodUndefined
(
'getAssociationFilterDAO'
);
},
isAssociationFilter
:
function
(
filterStr
,
dao
,
options
)
{
throwMethodUndefined
(
'isAssociationFilter'
);
},
getAssociationFilterColumn
:
function
(
filterStr
,
dao
,
options
)
{
throwMethodUndefined
(
'getAssociationFilterColumn'
);
},
getConditionalJoins
:
function
(
options
,
originalDao
)
{
throwMethodUndefined
(
'getConditionalJoins'
);
},
arrayValue
:
function
(
value
,
key
,
_key
,
factory
,
logicResult
)
{
throwMethodUndefined
(
'arrayValue'
);
},
/*
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
,
dao
,
options
)
{
throwMethodUndefined
(
'hashToWhereConditions'
);
},
booleanValue
:
function
(
value
)
{
return
value
;
}
};
/* istanbul ignore next */
var
throwMethodUndefined
=
function
(
methodName
)
{
throw
new
Error
(
'The method "'
+
methodName
+
'" is not defined! Please add it to your sql dialect.'
);
};
return
QueryGenerator
;
})();
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