All Projects → typicode → Lodash Id

typicode / Lodash Id

Licence: mit
Makes it easy to manipulate id-based resources with lodash or lowdb

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Lodash Id

Performance
⏱ PHP performance tool analyser your script on time, memory usage and db query. Support Laravel and Composer for web, web console and command line interfaces.
Stars: ✭ 429 (-1.15%)
Mutual labels:  query, database
underscore.haz
🔍 _.haz() is like _.has() but this underscore and/or lodash mixin lets you do deep object key existence checking with a dot denoted string, for example 'a.b.c'
Stars: ✭ 13 (-97%)
Mutual labels:  lodash, underscore
rudash
Rudash - Lodash for Ruby Apps
Stars: ✭ 27 (-93.78%)
Mutual labels:  lodash, underscore
Query Exporter
Export Prometheus metrics from SQL queries
Stars: ✭ 166 (-61.75%)
Mutual labels:  query, database
Semanticmediawiki
🔗 Semantic MediaWiki turns MediaWiki into a knowledge management platform with query and export capabilities
Stars: ✭ 359 (-17.28%)
Mutual labels:  query, database
Aresdb
A GPU-powered real-time analytics storage and query engine.
Stars: ✭ 2,814 (+548.39%)
Mutual labels:  query, database
eslint-plugin-lodash-template
ESLint plugin for John Resig-style micro template, Lodash's template, Underscore's template and EJS.
Stars: ✭ 15 (-96.54%)
Mutual labels:  lodash, underscore
Pecee Pixie
Lightweight, easy-to-use querybuilder for PHP inspired by Laravel Eloquent - but with less overhead.
Stars: ✭ 19 (-95.62%)
Mutual labels:  query, database
Preql
An interpreted relational query language that compiles to SQL.
Stars: ✭ 257 (-40.78%)
Mutual labels:  query, database
Gulp Template
Render/precompile Lodash templates
Stars: ✭ 276 (-36.41%)
Mutual labels:  lodash, underscore
Sqldb Logger
A logger for Go SQL database driver without modify existing *sql.DB stdlib usage.
Stars: ✭ 160 (-63.13%)
Mutual labels:  query, database
Arquero
Query processing and transformation of array-backed data tables.
Stars: ✭ 384 (-11.52%)
Mutual labels:  query, database
Laravel Db Profiler
Database Profiler for Laravel Web and Console Applications.
Stars: ✭ 141 (-67.51%)
Mutual labels:  query, database
php-lodash
php-lodash is a PHP utility library, similar to Underscore/Lodash.
Stars: ✭ 35 (-91.94%)
Mutual labels:  lodash, underscore
Pumpkindb
Immutable Ordered Key-Value Database Engine
Stars: ✭ 1,219 (+180.88%)
Mutual labels:  query, database
underwater
~2kb - ES6 Collection of helper functions. Lodash like
Stars: ✭ 18 (-95.85%)
Mutual labels:  lodash, underscore
Laravel Eloquent Query Cache
Adding cache on your Laravel Eloquent queries' results is now a breeze.
Stars: ✭ 529 (+21.89%)
Mutual labels:  query, database
Opencypher
Specification of the Cypher property graph query language
Stars: ✭ 534 (+23.04%)
Mutual labels:  query, database
Inquiry Deprecated
[DEPRECATED]: Prefer Room by Google, or SQLDelight by Square.
Stars: ✭ 264 (-39.17%)
Mutual labels:  query, database
Nspl
Non-Standard PHP Library - functional primitives toolbox and more
Stars: ✭ 365 (-15.9%)
Mutual labels:  lodash, underscore

lodash-id Build Status NPM version

lodash-id makes it easy to manipulate id-based resources with lodash or lowdb

  • getById
  • insert
  • upsert
  • updateById
  • updateWhere
  • replaceById
  • removeById
  • removeWhere
  • createId

Install

# with lodash
npm install lodash lodash-id --save

# with lowdb
npm install lowdb lodash-id --save

Note lodash-id is also compatible with underscore

API

In the API examples, we're assuming db to be:

const db = {
  posts: [
    {id: 1, body: 'one', published: false},
    {id: 2, body: 'two', published: true}
  ],
  comments: [
    {id: 1, body: 'foo', postId: 1},
    {id: 2, body: 'bar', postId: 2}
  ]
}

getById(collection, id)

Finds and returns document by id or undefined.

const post = _.getById(db.posts, 1)

insert(collection, document)

Adds document to collection, sets an id and returns created document.

const post = _.insert(db.posts, { body: 'New post' })

If the document already has an id, and it is the same as an existing document in the collection, an error is thrown.

_.insert(db.posts, { id: 1, body: 'New post' })
_.insert(db.posts, { id: 1, title: 'New title' }) // Throws an error

upsert(collection, document)

Adds document to collection, sets an id and returns created document.

const post = _.upsert(db.posts, { body: 'New post' })

If the document already has an id, it will be used to insert or replace.

_.upsert(db.posts, { id: 1, body: 'New post' })
_.upsert(db.posts, { id: 1, title: 'New title' })
_.getById(db.posts, 1) // { id: 1, title: 'New title' }

updateById(collection, id, attrs)

Finds document by id, copies properties to it and returns updated document or undefined.

const post = _.updateById(db.posts, 1, { body: 'Updated body' })

updateWhere(collection, whereAttrs, attrs)

Finds documents using _.where, updates documents and returns updated documents or an empty array.

// Publish all unpublished posts
const posts = _.updateWhere(db.posts, { published: false }, { published: true })

replaceById(collection, id, attrs)

Finds document by id, replaces properties and returns document or undefined.

const post = _.replaceById(db.posts, 1, { foo: 'bar' })

removeById(collection, id)

Removes document from collection and returns it or undefined.

const comment = _.removeById(db.comments, 1)

removeWhere(collection, whereAttrs)

Removes documents from collection using _.where and returns removed documents or an empty array.

const comments = _.removeWhere(db.comments, { postId: 1 })

id

Overwrite it if you want to use another id property.

_.id = '_id'

createId(collectionName, doc)

Called by lodash-id when a document is inserted. Overwrite it if you want to change id generation algorithm.

_.createId = (collectionName, item) => `${collectionName}-${item.prop}-${Date.now()}`

Changelog

See details changes for each version in the release notes.

License

MIT - Typicode 🌵

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].