{"id":24847379,"url":"https://github.com/luckydrq/rdb-dataloader","last_synced_at":"2025-10-11T08:33:05.429Z","repository":{"id":69949158,"uuid":"79973969","full_name":"luckydrq/rdb-dataloader","owner":"luckydrq","description":"Better dataloader for ralational database such as mysql","archived":false,"fork":false,"pushed_at":"2017-10-24T08:59:48.000Z","size":11,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-01T10:48:26.047Z","etag":null,"topics":["dataloader","rdb"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/luckydrq.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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}},"created_at":"2017-01-25T01:55:09.000Z","updated_at":"2021-04-08T21:36:46.000Z","dependencies_parsed_at":"2023-02-27T09:00:20.640Z","dependency_job_id":null,"html_url":"https://github.com/luckydrq/rdb-dataloader","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"d6c0f11ca76c05729c0d1ddcdf2087c6c913835f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/luckydrq/rdb-dataloader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydrq%2Frdb-dataloader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydrq%2Frdb-dataloader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydrq%2Frdb-dataloader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydrq%2Frdb-dataloader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luckydrq","download_url":"https://codeload.github.com/luckydrq/rdb-dataloader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydrq%2Frdb-dataloader/sbom","scorecard":{"id":602860,"data":{"date":"2025-08-11","repo":{"name":"github.com/luckydrq/rdb-dataloader","commit":"d6c0f11ca76c05729c0d1ddcdf2087c6c913835f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T00:51:03.781Z","repository_id":69949158,"created_at":"2025-08-21T00:51:03.781Z","updated_at":"2025-08-21T00:51:03.781Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006611,"owners_count":26084148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dataloader","rdb"],"created_at":"2025-01-31T11:20:10.260Z","updated_at":"2025-10-11T08:33:05.394Z","avatar_url":"https://github.com/luckydrq.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rdb-dataloader\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\nThis module targets at [relational database](https://en.wikipedia.org/wiki/Relational_database) such as MySQL, SQL Server. Heavily inspired by Facebook [DataLoader](https://github.com/facebook/dataloader/issues).\n\n[npm-image]: https://img.shields.io/npm/v/rdb-dataloader.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/rdb-dataloader\n[travis-image]: https://img.shields.io/travis/luckydrq/rdb-dataloader/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/luckydrq/rdb-dataloader\n[codecov-image]: https://codecov.io/gh/luckydrq/rdb-dataloader/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/luckydrq/rdb-dataloader\n[david-image]: https://img.shields.io/david/luckydrq/rdb-dataloader.svg?style=flat-square\n[david-url]: https://david-dm.org/luckydrq/rdb-dataloader\n[snyk-image]: https://snyk.io/test/npm/rdb-dataloader/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/rdb-dataloader\n[download-image]: https://img.shields.io/npm/dm/rdb-dataloader.svg?style=flat-square\n[download-url]: https://npmjs.org/package/rdb-dataloader\n\n## Install\n`$ npm i rdb-dataloader`\n\n## Why?\nFirst i'd like to say [DataLoader](https://github.com/facebook/dataloader/issues) is a great module that, like it's said, aims to provide per-request cache to save network IO and extremly useful for data service implemented by [GraphQL](http://graphql.org) which intergreted with my project recently. I use MySQL as data storage layer which is a common case in real world i believe. However, I found something inconvenient when playing with MySQL:\n\n### Unnecessary duplicate cache\nIt is common to have one or more unique key(s) in a table. For example,\nan User table with these fields: `id`, `name`, `mobile` can have\n`id` as the [Primary Key](http://wiki.c2.com/?PrimaryKey) and `mobile`\nas a [Unique Key](https://en.wikipedia.org/wiki/Unique_key). So the data service has to response to `fetchByIds` and `fetchByMobiles` calls. Then it\nhave to initiate two instances when using [DataLoader](https://github.com/facebook/dataloader):\n```js\n  const DataLoader = require('dataloader');\n  const idLoader = new DataLoader(fetchByIds);\n  const mobileLoader = new DataLoader(fetchByMobiles);\n\n  idLoader.load(1);\n  mobileLoader.load('+86123456');\n\n  function fetchByIds(ids) {\n    return db.Users.getByIds(ids);\n  }\n\n  function fetchByMobiles(mobiles) {\n    return db.Users.getByMobiles(mobiles);\n  }\n```\n\nThis can work but it's not good enough and the logic is far more complex\nin real world. Two instances meaning two separate [cache](https://github.com/facebook/dataloader/blob/master/src/index.js#L56), you can imagine\nthat there would be many duplecate records cached in both instance\ncache just because they are fetched by a different key(`id` or\n`mobile`) and *Network Still happens for both sides*. Also there would be more instances to initiate as the number\nof unique keys increases.\n\n### Duplicate keys\nThere is an old [issue](https://github.com/facebook/dataloader/issues/49) and [DataLoader](https://github.com/facebook/dataloader) fixes now.\n\n## What does this module address?\nThis module aims to solve the inconvenience metioned above when playing with relational database. *It is recommended that one loader per table.* It'd use a single cache and whenever a record is fetched by PK or UK, it'd `contribute` to the cache. Accordingly, it'd support load by PK or UK to take full advantage of cache.\n\n## Example\n```js\n  const uniqueKeyMap = new Map();\n  uniqueKeyMap.set('name', db.fetchByNames); // UK\n  uniqueKeyMap.set('email', db.fetchByEmails);  // UK\n  const loader = new DataLoader(db.fetchByIds, { uniqueKeyMap });\n  loader.load('luckydrq', 'name') // the second argument `name` is to tell loader to fetchByNames\n    .then(record =\u003e {\n      assert(record.id === 1);\n      assert(loader._promiseCache.size === 1);\n      done();\n    }).catch(done);\n```\n\nMore [examples](https://github.com/luckydrq/rdb-dataloader/blob/master/test/index.test.js).\n\n## API\nSince this module inherits from [DataLoader](https://github.com/facebook/dataloader), it is compatible with the apis of DataLoader. But as you can see from former example, the api is extended. Extended apis are the following:\n\n### contructor(options)\nThe constructor accepts all the options that DataLoader accepts. `options.cache = true` and `options.batch = true` is set by default and there is no way to override it because it'd be useless without these two features disabled. Alse, there are additional options as below:\n\n- options.primaryKey(optional): String\nSpecify PK name, default is \"id\";\n\n- options.uniqueKeyMap(optional): ES6 Map\n  - key: String\n    UK name\n  - value: Function\n    Batch function for UK\nUse it when you want to fetch by UK.\n\n### load(key[, uniqueKey])\nIf you want to load by UK, the second argument should be specified, omitted meaning load by PK.\n\n### loadMany(keys[, uniqueKey])\nIf you want to load by UK, the second argument should be specified, omitted meaning load by PK.\n\n## Lisence\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckydrq%2Frdb-dataloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluckydrq%2Frdb-dataloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckydrq%2Frdb-dataloader/lists"}