How to use sql - 10 common examples

To help you get started, we’ve selected a few sql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brownplt / code.pyret.org / src / schema.js View on Github external
// autogenerated by sql-generate v0.3.0 on Thu May 08 2014 13:40:27 GMT-0400 (EDT)

var sql = require('sql');


/**
 * SQL definition for public.migrations
 */
exports.migrations = sql.define({
	name: 'migrations',
	columns: [
		{ name: 'id' },
		{ name: 'name' },
		{ name: 'run_on' }
	]
});


/**
 * SQL definition for public.sessions
 */
exports.sessions = sql.define({
	name: 'sessions',
	columns: [
		{ name: 'id' },
github coreyp1 / defiant / lib / plugin / orm / attribute / attribute.js View on Github external
async load(entity, path) {
    // Set up an object to load the values into.
    let parentValue = this.drilldown(entity, path.slice(0, -1));
    let value = parentValue[this.attributeName] = [];

    // We don't use the Table.load() function, because we have to give
    // special conditions to handle the revisions.
    let table = sql.define(this.schema());
    let query = table
      .select(table.star())
      .where(
        table.parentId.equals(entity.id)
        .and(table.revisionIdTo.isNull())
      ).toQuery();
    let db = this.engine.database;
    // Execute the query, then move the items into an object keyed by id.
    let rows = await new Promise((accept) => {
      db.all(query.text, ...query.values, (err, rows) => {
        if (rows) {
          return accept(rows);
        }
        return accept(err);
      });
    });
github coreyp1 / defiant / lib / plugin / orm / attribute / attribute.js View on Github external
async purge(parentIds) {
    let table = sql.define(this.schema());
    let attributes = this.attributeRegistry.getOrderedElements();
    let toBeDeleted = [];
    if (attributes) {
      // We must get a list of all ids that will be deleted, and pass that
      // list on to any sub-attributes.
      let query = table.select(table.id).where(table.parentId.in(parentIds)).toQuery();
      let db = this.engine.database;
      let rows = await new Promise((accept) => {
        db.all(query.text, ...query.values, (err, rows) => {
          if (rows) {
            return accept(rows);
          }
          return accept(err);
        });
      });
      rows.forEach(item => toBeDeleted.push(item.id));
github brianc / node-pg-query / test / index.js View on Github external
it('works', function(done) {
      var table = sql.define({
        name: 'stuff',
        columns: ['id', 'name']
      });
      query(table.insert({name: 'brian'}), ok(done, function() {
        query(table.select(), ok(done, function(rows) {
          assert.equal(rows.length, 1);
          assert.equal(rows[0].name, 'brian');
          done();
        }));
      }));
    });
  });
github tmont / node-sql-generate / tests / expected / camelize.js View on Github external
/**
 * SQL definition for node_sql_generate.bar
 */
exports.bar = sql.define({
	name: 'bar',
	columns: [
		{ name: 'id', property: 'id' },
		{ name: 'foo_id', property: 'fooId' }
	]
});


/**
 * SQL definition for node_sql_generate.foo
 */
exports.foo = sql.define({
	name: 'foo',
	columns: [
		{ name: 'id', property: 'id' },
		{ name: 'field_1', property: 'field1' },
		{ name: 'foo_bar_baz', property: 'fooBarBaz' }
	]
});
github tmont / node-sql-generate / tests / expected / defaults.js View on Github external
/**
 * SQL definition for node_sql_generate.bar
 */
exports.bar = sql.define({
	name: 'bar',
	columns: [
		{ name: 'id' },
		{ name: 'foo_id' }
	]
});


/**
 * SQL definition for node_sql_generate.foo
 */
exports.foo = sql.define({
	name: 'foo',
	columns: [
		{ name: 'id' },
		{ name: 'field_1' },
		{ name: 'foo_bar_baz' }
	]
});
github amida-tech / greyscale / backend / app / models / token.js View on Github external
var sql = require('sql');

var Token = sql.define({
    name: 'Token',
    columns: ['userID', 'body', 'issuedAt', 'realm']
});

module.exports = Token;
github amida-tech / greyscale / backend / app / models / project_user_groups.js View on Github external
var sql = require('sql');

var ProjectUserGroup = sql.define({
    name: 'ProjectUserGroups',
    columns: ['projectId', 'groupId']
});

module.exports = ProjectUserGroup;
github amida-tech / greyscale / backend / app / models / role_rights.js View on Github external
var sql = require('sql');

var columns = ['roleID', 'rightID'];

var RolesRights = sql.define({
    name: 'RolesRights',
    columns: columns
});

RolesRights.whereCol = columns;

module.exports = RolesRights;
github amida-tech / greyscale / backend / app / models / essence_roles.js View on Github external
var sql = require('sql');

var columns = ['id', 'roleId', 'userId', 'essenceId', 'entityId'];

var EssenceRole = sql.define({
    name: 'EssenceRoles',
    columns: columns
});

EssenceRole.whereCol = columns;

module.exports = EssenceRole;

sql

sql builder

MIT
Latest version published 7 years ago

Package Health Score

34 / 100
Full package analysis

Popular sql functions