2.2.1 • Published 7 years ago

yepql v2.2.1

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

yepql - Javascript & SQL rethought

Yepql is a javascript library for using SQL.

It is heavily inspired by yesql

Install

$ yarn add yepql

Driver

You'll need a database driver

Databasenpm install --save package
PostgreSQLpg
SQL Servermssql

Use

-- get-users-by-id.sql

select *
from Users
where Users.ID = @ID
// db.js
var mssql = require("mssql");
var yepql = require("yepql")(mssql);

var getUsersByID = yepql.makeQuery("./get-users-by-id.sql");

module.exports = { getUsersByID };
// env.js
module.exports = {
  connectionString: process.env.CONNECTION_STRING || "Server=localhost,1433;Database=database;User Id=username;Password=password;Encrypt=true";
}
var db = require("./db");
var env = require("./env");

db
.getUsersByID(env.connectionString, { ID: 1 })
.then((rows) => {
  /*
    rows === [{
      ID: 1,
      Username: 'username',
      Email: 'email@example.com',
      ...
    }]
  */
})
.catch(/* handle error */)

Have a lot of sql files?

-- sql/getUsersByID.sql

select *
from Users
where Users.ID = @ID
-- sql/getUsersByEmail.sql

select *
from Users
where Users.Email = @Email
// db.js
var yepql = require("yepql");

var queries = yepql.makeQueries("./sql");

/*
  queries === {
    getUsersByID: function(connectionString, params),
    getUsersByEmail: function(connectionString, params)
  }
*/

module.exports = queries;
2.2.1

7 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago