{"id":19940896,"url":"https://github.com/missive/ndex","last_synced_at":"2026-02-28T18:35:46.030Z","repository":{"id":24219797,"uuid":"27611893","full_name":"missive/ndex","owner":"missive","description":"Ndex is an indexedDB wrapper","archived":false,"fork":false,"pushed_at":"2025-05-13T14:18:33.000Z","size":581,"stargazers_count":3,"open_issues_count":8,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-22T16:22:39.200Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/missive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-12-05T21:56:21.000Z","updated_at":"2025-05-13T14:18:36.000Z","dependencies_parsed_at":"2025-05-03T15:42:27.562Z","dependency_job_id":null,"html_url":"https://github.com/missive/ndex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/missive/ndex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missive%2Fndex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missive%2Fndex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missive%2Fndex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missive%2Fndex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/missive","download_url":"https://codeload.github.com/missive/ndex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missive%2Fndex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29946912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T18:21:26.597Z","status":"ssl_error","status_checked_at":"2026-02-28T18:19:38.892Z","response_time":90,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T00:07:18.581Z","updated_at":"2026-02-28T18:35:45.998Z","avatar_url":"https://github.com/missive.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ndex — An indexedDB wrapper\nIt will automatically handle transactions and reuse them as many times as possible within the same event loop. You can therefore `Ndex.get` in a loop and Ndex will still only create a single transaction for maximum performance.\n\n## Table of Content\n- [API](#API)\n  - [connect](#connect)\n  - [get](#get)\n  - [getAll](#getall)\n  - [add](#add)\n  - [update](#update)\n  - [increment](#increment)\n  - [decrement](#decrement)\n  - [delete](#delete)\n  - [deleteWhere](#deletewhere)\n  - [clear](#clear)\n  - [clearAll](#clearall)\n  - [index](#index)\n  - [where](#where)\n- [Migrations](#Migrations)\n- [Logging](#Logging)\n- [Specs](#Specs)\n\n## API\nNdex methods return a [Promise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), which means you can chain them or call them concurrently with `Promise.all`.\n\n```js\n// Result is accessible via .then\nNdex.users.get(1).then(function(data) {\n  console.log(data) // =\u003e { id: 1 }\n})\n\n// All you can chain™\nNdex.open('test', migrations)\n  .then(function() {\n    return Promise.all([\n      Ndex.users.add({ id: 1, name: 'e' })\n      Ndex.users.add({ id: 2, name: 'r' })\n    ])\n  })\n  .then(function() {\n    return Ndex.users.get(1)\n  })\n  .then(function() {\n    console.log('done')\n  })\n```\n\nCoffeeScript sweetness\n```coffee\n# Haters gonna hate\nNdex.open('test', migrations)\n  .then -\u003e Promise.all([\n    Ndex.users.add(id: 1, name: 'e')\n    Ndex.users.add(id: 2, name: 'r')\n   ])\n  .then -\u003e Ndex.users.get(1)\n  .then -\u003e console.log('done')\n```\n\n### connect\nBefore using Ndex, you must always open a connection with the database. You must provide a name and a migrations object. You don’t have to provide a database version, Ndex will take care of that for you. See the [migrations](#Migrations) section.\n```js\nNdex.connect('test', migrations).then(function(connection) {\n  connection.users.get(1).then(function(userData) {\n    console.log(userData)\n  })\n})\n```\n\n### get\n`Connection#get` returns a single item (unless an array of keys is passed) even if multiple items match the search for it doesn’t use a cursor. If you want all results (`i.e. Connection.users.index('job').get('developer')`) use [`Connection#where`](#where).\n```js\nconnection.users.get(1)\nconnection.users.get([1, 4])\n```\n\n### getAll\n```js\nconnection.users.getAll()\n```\n\n### add\n`Connection#add` overwrites the entry with the data passed.\n```js\n// Don’t provide a key for objectStores with a keyPath\nconnection.users.add({ id: 1, name: 'e', job: 'developer' })\nconnection.users.add([\n  { id: 1, name: 'e', job: 'developer' },\n  { id: 2, name: 'r', job: 'developer' },\n])\n\n// Provide a key for objectStores without keyPath\nconnection.organizations.add('missive', { name: 'missive', est: 2014 })\nconnection.organizations.add(\n  ['missive', 'heliom'],\n  [\n    { name: 'missive', est: 2014 },\n    { name: 'heliom',  est: 2012 },\n  ]\n)\n```\n\n### update\n`Connection#update` only updates passed data without overwriting the entry. It will also insert the entry when non-existent.\n```\nconnection.users.get(1) // { id: 1, name: 'e' }\n\n// Waiting for the update success is required for the get to be accurate\nconnection.users.update(1, { name: 'r' }).then(function() {\n  connection.users.get(1) // { id: 1, name: 'r' }\n})\n```\n\n### increment\n`Connection#increment` initializes attribute to zero if null and adds the value passed (default is 1). Only makes sense for number-based attributes.\n```js\n// For objectStores without keyPath\nconnection.stats.increment('visits')    // Increments visits entry by 1\nconnection.stats.increment('visits', 4) // Increments visits entry by 4\n\n// For objectStores with a keyPath\nconnection.stats.increment(1, { count: 1 })            // Increments id 1’s count attribute by 1\nconnection.stats.increment(1, { visits: { count: 4 }}) // Increments id 1’s visits.count by 4\n```\n\n### decrement\n`Ndex#decrement` is an alias for `Ndex#increment` where the value passed is changed to a negative.\n```js\nconnection.stats.decrement('visits')    // Increments visits entry by -1\nconnection.stats.decrement('visits', 4) // Increments visits entry by -4\n```\n\n### delete\n```js\nconnection.users.delete(1)\nconnection.users.delete([1, 4])\n```\n\n### deleteWhere\n`connection#deleteWhere` is an alias for `Ndex#where:remove`, see [`Ndex#where`](#where).\n```js\nconnection.users.deleteWhere({ gteq: 3 })\nconnection.users.index('job').deleteWhere({ eq: 'developer' })\n```\n\n### clear\nClear the given object store. Note that if the object store has an `autoIncrement: true` key, the key won’t be reseted.\n```js\nconnection.users.clear()\n```\n\n### clearAll\n```js\nconnection.clearAll()\n```\n\n### index\nIndexes can be used with `get`, `getAll` and `where`.\n```js\nconnection.users.index('job').get('developer')\n```\n\n### where\n`Connection#where` uses a cursor to iterate on a given range. Use the keyPath predicates to narrow down your range and the keys predicates to filter items in your range. For maximum performance, you really want to be as precise as possible with the range.\n\n```js\n// keyPath predicates\n// These will be applied to your objectStore’s key\nconnection.users.where({ lt: 3 })\nconnection.users.where({ lteq: 3 })\nconnection.users.where({ gt: 3 })\nconnection.users.where({ gteq: 3 })\nconnection.users.where({ eq: 3 })\n\n// :eq also supports arrays. It will create a range between min (1) and max (3) (both inclusive) and filter out any results that aren’t 1 or 3 (2)\n// Depending on the range it creates (i.e. `eq: [1, 1000]`), `Ndex.get([1, 1000])` will definitely be much more performant\nconnection.users.where({ eq: [1, 3] })\n\n// When using an index, the predicate is applied to the index’s key\nconnection.users.index('job').where({ eq: 'developer' })\n\n// Any keys predicates\n// These can be used on any keys, even the non-indexed ones\nconnection.users.where({ only: { job: ['developer'] } })\nconnection.users.where({ except: { job: ['developer'] } })\nconnection.users.where({ uniq: 'job' })\n\n// Pagination\nconnection.users.where({ limit: 3 })\nconnection.users.where({ offset: 2 })\nconnection.users.where({ order: 'desc' })\n\n// By adding the :remove key, Ndex will delete found items from indexedDB\nconnection.users.where({ gteq: 3, remove: true }) // Is equivalent to `connection.users.deleteWhere({ gteq: 3 })`\n```\n\n## Migrations\nWith Ndex, you don’t have handle the database version. It will always increase on each reload. Fear not! Ndex is aware of its migrations and will never run the same migration twice. We haven’t experienced any performance issue with that checkup (that is done with the existing transaction when opening the database).\n\n- [createObjectStore#Parameters](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase.createObjectStore#Parameters)\n- [deleteObjectStore#Parameters](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase.deleteObjectStore#Parameters)\n- [createIndex#Parameters](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.createIndex#Parameters)\n- [deleteIndex#Parameters](https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.deleteIndex#Parameters)\n\n```js\nmigrations = {\n  '201412041358_CreateUsersObjectStore': {\n    type: 'createObjectStore',\n    args: ['users', { keyPath: 'id', autoIncrement: true }],\n  },\n\n  '201412041527_CreateOrganizationsObjectStore': [\n    { type: 'createObjectStore', args: ['organizations'] },\n    { type: 'createIndex', args: ['organizations', 'est', 'est'] },\n  ],\n\n  '201412041527_AddJobIndexToUsers': {\n    type: 'createIndex',\n    args: ['users', 'job', 'job'],\n  },\n}\n```\n![](http://f.cl.ly/items/3D1k1g1J0Z29381w2f3s/Screen%20Shot%202014-12-08%20at%2010.18.22%20PM.png)\n\n## Logging\nNdex has a logging system that will group requests by transaction. Gives you a pretty accurate idea of what Ndex does for you and where you can refactor your requests.\nYou can implement your own handler of use the built-in console one.\n```js\nconnection.handleLogging(console)\n\nconnection.users.add({ id: 1, name: 'e', job: 'developer' })\nconnection.users.add({ id: 2, name: 'r', job: 'developer' })\nconnection.users.add({ id: 3, name: 'p', job: 'developer' })\nconnection.users.add({ id: 4, name: 't', job: 'designer'  })\n\nsetTimeout(function() {\n  connection.users.get(1)\n  connection.users.get(3)\n}, 100)\n```\n![](http://f.cl.ly/items/021l173X1b451J2B3E2A/Screen%20Shot%202014-12-08%20at%209.58.25%20PM.png)\n\nWithout the timeout, Ndex will reuse the same transaction\n```js\nconnection.handleLogging(console)\n\nconnection.users.add({ id: 1, name: 'e', job: 'developer' })\nconnection.users.add({ id: 2, name: 'r', job: 'developer' })\nconnection.users.add({ id: 3, name: 'p', job: 'developer' })\nconnection.users.add({ id: 4, name: 't', job: 'designer'  })\n\nconnection.users.get(1)\nconnection.users.get(3)\n```\n![](http://f.cl.ly/items/2G2R0L2h311U2M2L3M08/Screen%20Shot%202014-12-08%20at%2010.09.03%20PM.png)\n\n## Dist\n```sh\n$ gulp dist\n```\n\n## Specs\n```sh\n$ gulp\n$ open http://localhost:8080/spec\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmissive%2Fndex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmissive%2Fndex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmissive%2Fndex/lists"}