Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Index query type #117

Open
jrf0110 opened this issue Jun 8, 2015 · 2 comments
Open

Create Index query type #117

jrf0110 opened this issue Jun 8, 2015 · 2 comments
Labels

Comments

@jrf0110
Copy link
Member

jrf0110 commented Jun 8, 2015

http://www.postgresql.org/docs/9.3/static/sql-createindex.html

@Meaglin
Copy link

Meaglin commented Jun 8, 2015

don't forget the 'drop-index', i have been using the following in my current code base:

mosql.registerQueryType('create-index', 'create {unique} index {name} ON {table} ({fields})');
mosql.registerQueryType('drop-index', 'drop index {ifExists} {name} ON {table}');
mosql.registerQueryHelper('unique', function(unique, values, query) {
    return unique ? 'unique' : '';
});
mosql.registerQueryHelper('name', function(name, values, query) {
    return require('mongo-sql/lib/utils').quoteObject(name);
});
mosql.registerQueryHelper('fields', function(fields, values, query) {
    return fields.map(function(name) { return require('mongo-sql/lib/utils').quoteObject(name); }).join(', ');
});
mosql.registerQueryHelper('index', function(index, values, query) {
    var util = require('mongo-sql/lib/utils');
    if(!index || !index.length) {
        return '';
    }
    return index.map(function(index) {
        var rt = ', ';
        if(index.unique) {
            rt += 'unique';
        } else {
            rt += 'key';
        }
        rt += ' ' + util.quoteObject(index.name);
        rt += ' (' + index.fields.map(function(field) { return util.quoteObject(field); }).join(', ') + ')';
        return rt;
    }).join('');
});

@jrf0110
Copy link
Member Author

jrf0110 commented Jun 8, 2015

Beautiful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants