Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.
/ query Public archive

Declarative and expressive database queries.

License

Notifications You must be signed in to change notification settings

netiam/query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

query

Declarative and expressive database queries.

Idea

Nested queries are awful to write in most programing languages. This query builder aims very specific needs. Imagine a case where someone has always to fetch a certain document in order to fetch another one.

We want to do this in a declarative way and also allow functional programing. In all cases, callback or any other evaluation is prohibited.

Install

npm i -S netiam-query

Adapter

import adapter from 'netiam-adapter'

const connection = adapter({})

query(connection)
  .use('groups')
  

How it works

The query builder tries to build an optimized query from what you have provided. In any case, it will not do anything until your connection is ready. You don't have to wait for a connection.on('ready') event or something similar. All commands are queued and will execute automatically after connection has been established. This is also true for temporary unavailable connections.

Examples

Query a document, populate all documents at path users, select the user level and lookup levels by id, reduce than by level value.

query()
  .use('groups')
  .find({id: 1})
  .populate('users')
  .select('users.level')
  .use('levels')
  .find({id: 'users.level'})
  .reduce((total, level) => total += level.val, 0)

Update nested document(s).

query()
  .use('groups')
  .find()
  .populate('users')
  .use('users')
  .update({id: 'users.id'}, {role: 'USER'})

Delete all nested documents that match a certain criteria.

query()
  .use('users')
  .find({role: 'EDITOR'})
  .remove()

Delete all users that match a certain criteria in a sub-document.

query()
  .use('users')
  .find({'role.name': 'EDITOR'})
  .delete()

About

Declarative and expressive database queries.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published