Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qubui

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qubui

make flexible query

  • 1.0.22
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

qubui

QuBui is flexible query builder.

Version

1.0.22

Change Log

  • Supports arrays in the form of 'where'
  • Ignore when there is no binding value of 'where'

Installation

$ npm i qubui

Example

Initialize (in Express)

var qubui = require('qubui');
var DB = mysql.createConnection(~~);

var qb = qubui(DB);

Initialize (in Koajs)

var qubui = require('qubui');
app.use(function* (next){
    this.qubui=function(){
        return new qubui(this.db, {co:true});
    }
    yield next;
 });

Select:

// SELECT * FROM TEST
var express = qubui(DB).select().from('TEST').getList( HANDLER );
var koajs = yield this.qubui().select().from('TEST').getList();

// And...
var qb = qubui(DB).select().from('TEST');
if(req.use){ qb.where('use<?', req.id); }
if(req.zip){ qb.where('zip=?', req.zip); }
if(req.cnt){ qb.limit(req.cnt); }
if(req.srt){ qb.order(req.srt); }
qb.getList( HANDLER );

Insert:

// INSERT INTO TEST SET ?
var data = {foo:'bar',today:'NOW()',tomorrow:'NOW()+INTERVAL 1 DAY'};

var express = qubui(DB).insert().into('TEST').set(data).run( HANDLER );
var koajs = yield this.qubui().insert().into('TEST').set(data).run();

Update:

// UPDATE TEST SET ? WHERE foo=?
var data = {foo:'bar',today:'NOW()',tomorrow:'NOW()+INTERVAL 1 DAY'};

var express = qubui(DB).update().from('TEST').set(data).where('foo=?','bar').run( HANDLER );
var koajs = yield this.qubui().update().from('TEST').set(data).where('foo=?','bar').run();

Delete:

// DELETE FROM TEST WHERE foo=?
var express = qubui(DB).delete().from('TEST').where('foo=?','bar').run( HANDLER );
var koajs = yield this.qubui().delete().from('TEST').where('foo=?','bar').run();

SubQuery:

// SELECT id,(select name FROM OTHERS WHERE OTHERS.id=TEST.id) otherName FROM TEST WHERE foo=?
var qubui = require('qubui');
var bracket = qubui.bracket;

var subQuery = qubui().select().field('name').from('OTHERS').where('OTHERS.id=TEST.id');
var express = qubui(DB).select().field(['id',bracket(subQuery,'otherName')]).from('TEST').where('foo=?','bar').run( HANDLER );

var koajs = yield this.qubui().select().field(['id',bracket(subQuery,'otherName')]).from('TEST').where('foo=?','bar').run();

License

MIT

Keywords

FAQs

Package last updated on 24 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc