
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
eloquent-query-builder
Advanced tools
eloquent-query-builder is promise-base query builder for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server, it features solid transaction support, relations and more
eloquent-query-builder is a promise-based Node.js query builder for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid query building methods like eloquent queries in php Laravel framework
using yarn
$ yarn add eloquent-query-builder
using npm
$ npm install --save eloquent-query-builder
#install sequelize
$ npm install --save sequelize
# And one of the following:
$ npm install --save pg pg-hstore # Postgres
$ npm install --save mysql2
$ npm install --save mariadb
$ npm install --save sqlite3
$ npm install --save tedious # Microsoft SQL Server
const Sequelize = require('sequelize');
var queryBuilder = require('eloquent-query-builder');
const options = {
host: '127.0.0.1',
logging: false,
dialect: 'mysql',
}
const sequelize = new Sequelize(dbName, dbUser, dbPassword, options);
const DBO = new queryBuilder(sequelize);
let result = await DBO.table('users').get();
# which executes query like
select * from `users`
The select method defines the fields to be selected for a given query.
await DBO.table('users').select('firstname','lastname').get();
//or
await DBO.table('users').select('firstname,lastname').get();
//or
await DBO.table('users').select('*').get();
Query builder offers a bunch of dynamic methods to add where clauses. Also, it supports sub-queries by passing a closure or another query instead of the actual value.
const users = await DBO.table('users').where('id', 1).get();
Also, you can define the comparison operator to the where clause.
const users = await DBO.table('users').where('age','>', 18).get();
// where with like
const users = await DBO.table('users').where('city','like', `"del%"`).get();
You can also add a callback to the where clause. Callback outputs a little different SQL query by grouping all the where clauses.
await DBO.table('users').where('id',1).where(funtion(qry){
qry.orWhere('id',4')
}).get();
// it will execute query like
select * from `users` where (`id` = 1 or `id` = 4)
const users = await DBO.table('users').where('age',18).orWhere('age', 20).get();
const users = await DBO.table('users').where('age',18).orWhereNull('age').get();
const users = await DBO.table('users').where('age',18)..orWhereNotNull('age').get();
const users = await DBO.table('users').whereNot('age', 18).get();
const users = await DBO.table('users').whereNot('age', 18).orWhereNot('age', 20).get();
const users = await DBO.table('users').whereIn('age', [16,18]).get();
const users = await DBO.table('users').whereNotIn('age', [16,18]).get();
const users = await DBO.table('users').whereNull('age').get();
const users = await DBO.table('users').whereNotNull('age').get();
const users = await DBO.table('users').whereExists(function(qry){
qry.from('address').where('users.id', 'address.user_id)
}).get();
const users = await DBO.table('users').whereNotExists(function(qry){
qry.from('address').where('users.id', 'address.user_id)
}).get();
const users = await DBO.table('users').whereBetween('age',[18,20]).get();
// or
const users = await DBO.table('users').whereBetween('age',18, 20).get();
const users = await DBO.table('users').whereNotBetween('age',[18,20]).get();
// or
const users = await DBO.table('users').whereNotBetween('age',18, 20).get();
await DBO.table('users').join('accounts', 'user.id', 'accounts.user_id').get();
// this will execute
`select * from users inner join accounts on user.id=accounts.user_id`
await DBO.table('users').leftJoin('accounts', 'user.id', 'accounts.user_id').get();
await DBO.table('users').rightJoin('accounts', 'user.id', 'accounts.user_id').get();
await DBO.table('users').leftOuterJoin('accounts', 'user.id', 'accounts.user_id').get();
await DBO.table('users').rightOuterJoin('accounts', 'user.id', 'accounts.user_id').get();
await DBO.table('users').outerJoin('accounts', 'user.id', 'accounts.user_id').get();
await DBO.table('users').fullOuterJoin('accounts', 'user.id', 'accounts.user_id').get();
await DBO.table('users').crossJoin('accounts', 'user.id', 'accounts.user_id').get();
await DBO.table('users').distinct('age').get();
await DBO.table('users').groupBy('age').get();
// or
await DBO.table('users').groupBy('age','city').get();
await DBO.table('users').orderBy('age').get();
//or
await DBO.table('users').orderBy('age','desc').get();
await DBO.table('users').groupBy('age').having('age', '>', 18).get();
await DBO.table('users').offset(11).limit(10).get();
await DBO.table('users').paginate(1, 10);
#results
{
pages: {
pages: 20,
currentPage: 1,
perPage: 10,
lastPage: 20,
},
result: [{...}]
}
await DBO.table('users').count();
await DBO.table('users').countDistinct('age');
await DBO.table('users').min('age');
await DBO.table('users').max('age');
await DBO.table('cart').sum('total');
await DBO.table('users').avg('age');
await DBO.table('users').list('email');
await DBO.table('users').first();
await DBO.rawQuery('select * from users');
const subquery = Database
.table('accounts')
.where('account_name', 'somename')
.select('account_name').getRaw();
const users = DBO.table('users').whereIn('id',subquery).get();
FAQs
eloquent-query-builder is promise-base query builder for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server, it features solid transaction support, relations and more
The npm package eloquent-query-builder receives a total of 0 weekly downloads. As such, eloquent-query-builder popularity was classified as not popular.
We found that eloquent-query-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.