Example #1
0
    _.defaultsDeep(connection, Adapter.defaults)

    let knex = Knex({
      client: 'pg',
      connection: connection.url || connection.connection,
      pool: connection.pool,
      debug: process.env.WATERLINE_DEBUG_SQL || connection.debug
    })
    let cxn = {
      identity: connection.identity,
      schema: Adapter.buildSchema(connection, collections),
      collections: collections,
      config: connection,
      knex: knex,
      st: KnexPostgis(knex)
    }

    return Util.initializeConnection(cxn)
      .then(() => {
        Adapter.connections.set(connection.identity, cxn)
        cb()
      })
      .catch(cb)
  },

  /**
   * Construct the waterline schema for the given connection.
   *
   * @param connection
   * @param collections[]
Example #2
0
		if (!is_object(where))
		{
			where = { [this.id]: where }
		}

		if (!where)
		{
			throw new Error(`No argument supplied for SQL .delete()`)
		}

		return knex(this.table).where(where).del()
	}
}

const knex = Knex(knexfile)
const knex_postgis = knex_postgis_plugin(knex)

knex.postgisDefineExtras(function(knex, formatter)
{
	const extras =
	{
		longitude_latitude(longitude, latitude)
		{
			return knex.raw('ST_SetSRID(ST_MakePoint(?, ?), 4326)', [longitude, latitude])
		}
	}

	return extras
})

Sql.knex_postgis = () => knex_postgis