{"id":20461024,"url":"https://github.com/ericgj/model-queries","last_synced_at":"2025-08-12T21:04:35.623Z","repository":{"id":8616844,"uuid":"10258647","full_name":"ericgj/model-queries","owner":"ericgj","description":"Custom collection endpoints for component/model","archived":false,"fork":false,"pushed_at":"2013-06-08T02:41:24.000Z","size":184,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T11:34:13.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ericgj.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}},"created_at":"2013-05-24T03:31:26.000Z","updated_at":"2014-05-05T05:24:47.000Z","dependencies_parsed_at":"2022-08-27T18:20:17.632Z","dependency_job_id":null,"html_url":"https://github.com/ericgj/model-queries","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ericgj/model-queries","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericgj%2Fmodel-queries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericgj%2Fmodel-queries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericgj%2Fmodel-queries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericgj%2Fmodel-queries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericgj","download_url":"https://codeload.github.com/ericgj/model-queries/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericgj%2Fmodel-queries/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270134998,"owners_count":24533193,"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-08-12T02:00:09.011Z","response_time":80,"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":[],"created_at":"2024-11-15T12:22:53.114Z","updated_at":"2025-08-12T21:04:35.566Z","avatar_url":"https://github.com/ericgj.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# model-queries\n\n  Custom endpoints for component/model\n\n## Installation\n\n    $ component install ericgj/model-queries\n\n## Usage\n\n\n### Query strings\n\n```javascript\n\nvar queries = require('model-queries');\n\nPost.use(queries);\n\nPost.collection('page', 'all');\n\nPost.page().query({page: 2, limit: 20}).run( callback );\n  //=\u003e  GET /post/all?page=2\u0026limit=20\n\n/* \n * Or specify parameters separately, objects or strings\n * Interface is identical to superagent `request.query`\n *\n */\nPost.page().query({page: 2}).query('limit=20').run( callback );\n\n```\n\n\n### Sub-entities\n\n```javascript\n\nvar queries = require('model-queries');\n\nPost.use(queries);\n\nPost.collection('forUser', '/user/:id/post/all');\n  \nPost.forUser({id: 123}).run( callback );\n  //=\u003e  GET /user/123/post/all\n\n```\n\n\n### Sub-entities with query strings\n\n``` javascript\nPost.forUser({id: 123}).query({p: 2, n: 20}).run( callback );\n  //=\u003e  GET /user/123/post/all?p=2\u0026n=20\n\n```\n\n\n### Custom response parsing\n\n``` javascript\nvar queries = require('model-queries');\n\nPost.use(queries);\n\n/* for example, to parse nested entities */\n\nPost.endpoint('withComments', ':id', function(res,fn){\n  var comments = res.body.comments;\n  delete res.body.comments;\n  var col = new Collection;\n  for (var i = 0, len = comments.length; i \u003c len; ++i) {\n    col.push(new Comment(comments[i]));\n  }\n  var post = new Post(res.body);\n  post.comments = col;\n  fn(null, post);\n}\n\nvar callback = function(err,post){ /* post has comments collection */ };\n\nPost.withComments({id: 123}).query({comments: 1}).run( callback );\n  //=\u003e  GET /post/123?comments=1\n\n```\n\n  \n## API\n\n### Model.collection( method, [path] )\n\nDefine a _collection query endpoint_ for the model called as `Model.method`.\nWhen these queries are run, the response is parsed as a Collection of model\ninstances: identically to how `Model.all` parses responses. \n\n### Model.endpoint( method, [path], [parse] )\n\nDefine a _query endpoint_ for the model with the given parse function for the\nresponses. If no parse function is given, the response will be passed to the\ncallback directly from superagent.\n\nIf path is not given, `Model.url(method)` is the default. Note that any\npath that doesn't start with \"/\" will be treated as relative to the model,\nwhile any path that _does_ start with \"/\" will be treated as absolute.\n\n\n## License\n\n  MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericgj%2Fmodel-queries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericgj%2Fmodel-queries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericgj%2Fmodel-queries/lists"}