不要怂,就是干,撸起袖子干!

Commit f3910991 by sdepold

added implementation of remove index query

1 parent e21579b8
......@@ -3,10 +3,6 @@ var Utils = require("../../utils")
module.exports = (function() {
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) {
options = options || {}
......@@ -121,9 +117,6 @@ module.exports = (function() {
return Utils._.template(query)(options)
},
/*
Returns an insert into command. Parameters: table name + hash of attribute-value-pairs.
*/
insertQuery: function(tableName, attrValueHash) {
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
......@@ -138,16 +131,6 @@ module.exports = (function() {
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) {
var query = "UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
var replacements = {
......@@ -161,17 +144,6 @@ module.exports = (function() {
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) {
options = options || {}
options.limit = options.limit || 1
......@@ -234,9 +206,16 @@ module.exports = (function() {
})
},
/*
Takes something and transforms it into values of a where condition.
*/
removeIndexQuery: function(tableName, indexNameOrAttributes) {
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) {
var result = null
......@@ -252,10 +231,6 @@ module.exports = (function() {
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) {
return Utils._.map(hash, function(value, key) {
var _key = Utils.addTicks(key)
......
......@@ -159,7 +159,13 @@ module.exports = (function() {
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')
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!