{"id":14976273,"url":"https://github.com/couchset/couchset","last_synced_at":"2025-10-27T18:30:57.804Z","repository":{"id":43682917,"uuid":"407736157","full_name":"couchset/couchset","owner":"couchset","description":"Couchbase ORM \u0026 Automatic GraphQL API(Resolver/Queries)","archived":false,"fork":false,"pushed_at":"2024-10-20T02:44:22.000Z","size":956,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T08:49:23.237Z","etag":null,"topics":["couchbase","couchbase-cluster","couchbase-community","couchbase-enterprise","couchbase-server","database-connector","graphql","graphql-client","graphql-server","orm-framework","orm-library"],"latest_commit_sha":null,"homepage":"https://couchset.org?ref=github ","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/couchset.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"ceddybi","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-09-18T02:42:07.000Z","updated_at":"2024-10-20T02:44:25.000Z","dependencies_parsed_at":"2024-10-20T20:07:39.825Z","dependency_job_id":null,"html_url":"https://github.com/couchset/couchset","commit_stats":{"total_commits":61,"total_committers":2,"mean_commits":30.5,"dds":0.2786885245901639,"last_synced_commit":"9fbdc2dcfe930b3ef5be65c94481b477d4920459"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/couchset/couchset","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchset%2Fcouchset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchset%2Fcouchset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchset%2Fcouchset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchset%2Fcouchset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/couchset","download_url":"https://codeload.github.com/couchset/couchset/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchset%2Fcouchset/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281319873,"owners_count":26481079,"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-27T02:00:05.855Z","response_time":61,"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":["couchbase","couchbase-cluster","couchbase-community","couchbase-enterprise","couchbase-server","database-connector","graphql","graphql-client","graphql-server","orm-framework","orm-library"],"created_at":"2024-09-24T13:53:36.558Z","updated_at":"2025-10-27T18:30:57.459Z","avatar_url":"https://github.com/couchset.png","language":"TypeScript","readme":"\n\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003e CouchSet - Couchbase ORM \u0026 Automatic GraphQL API generator (Resolver/Queries)\u003c/h1\u003e\n\u003c/p\u003e\n\n\n\u003cdiv align=\"center\"\u003e\n\n\u003cdiv style=\"display: flex;justify-content:center;\"\u003e\n\n\n\u003cimg alt=\"NPM\" src=\"https://img.shields.io/npm/dt/couchset.svg\"\u003e\u003c/img\u003e\n\n \n\n\u003c/div\u003e\n\n\u003cimg width=\"500px\" src=\"./docs/couchset.png\"\u003e\u003c/img\u003e\n\u003c/div\u003e\n\n\nCouchSet is a Couchbase ORM \u0026 Automatic GraphQL API code generator (Resolver/Queries) tool\n\n- [Install](#install)\n- [License](#license)\n\n## 1. Install\n```bash\nnpm i couchset --save\n```\n\n## 2. Start couchset\n```ts\nimport { couchset } from 'couchset';\n\n const started = await couchset({\n    connectionString: 'couchbase://localhost',\n    username: 'admin',\n    password: '123456',\n    bucketName: 'stq'\n })\n```\n\n## 3. Create a Model and start using it\n\n```ts\nimport { Model } from 'couchset';\n\nconst userModel = new Model('User');\n\n\n// Create document\nconst created = await userModel.create({\n    username: 'ceddy',\n    password: 'love couchbase',\n});\n\n// Find document\nconst foundData = await userModel.findById(created.id);\n\n// update document\nconst updatedData = await userModel.updateById(created.id, { ...created, someValue: 'x' });\n\n// delete\nconst deletedData = await userModel.delete(created.id);\n\n```\n\n## 4. Pagination\n\nAll models come with a method for automatic pagination \n```ts\nconst paginationData = await userModel.pagination({\n    select: [\"id\", \"email\", \"phone\",\"fullname\"],\n    where: { \n        userId: { $eq: \"ceddy\" },\n        $or: [{ userId: { $eq: \"ceddy\" } }, { phone: 10 }],\n        },\n    limit: 100,\n    page: 0,\n});\n```\n\nwhich translates to this query \n\n```sql\nSELECT * FROM `stq` WHERE _type=\"User\" AND userId=\"ceddy\" AND (userId=\"ceddy\" OR phone=10) ORDER BY createdAt DESC LIMIT 100 OFFSET 0\n```\n\n\nPagination results\n\n```js\n[\n  {\n    id: '209d3143-09b7-4b3d-bf7d-f0ccd3f98922',\n    updatedAt: 2021-01-26T01:51:43.218Z,\n    createdAt: 2021-01-26T01:51:43.210Z,\n    _type: 'User',\n    userId: 'ceddy',\n    password: '...',\n    someValue: 'x'\n  },\n  {\n    id: '1392e4f6-ae1e-4e01-b7d5-103bdd0e843f',\n    updatedAt: 2021-01-26T01:51:29.591Z,\n    createdAt: 2021-01-26T01:51:29.583Z,\n    _type: 'User',\n    userId: 'ceddy',\n    password: '...',\n    someValue: 'x'\n  }\n]\n```\n\n\n## 5. Custom queries \u0026 Query builder\nQuery builder is inspired from node-ottoman, for more examples, please see https://ottomanjs.com/guides/query-builder.html#query-builder\n\n```ts\nimport { Query } from 'couchset';\n\nconst params = {\n  select: [\n    {\n      $count: {\n        $field: {\n          name: 'type',\n        },\n        as: 'odm',\n      },\n    },\n  ],\n  let: [\n    { key: 'amount_val', value: 10 },\n    { key: 'size_val', value: 20 },\n  ],\n  where: {\n    $or: [{ price: { $gt: 'amount_val', $isNotNull: true } }, { auto: { $gt: 10 } }, { amount: 10 }],\n    $and: [\n      { price2: { $gt: 1.99, $isNotNull: true } },\n      { $or: [{ price3: { $gt: 1.99, $isNotNull: true } }, { id: '20' }] },\n    ],\n    $any: {\n      $expr: [{ $in: { search_expr: 'search', target_expr: 'address' } }],\n      $satisfied: { address: '10' },\n    },\n    $in: { search_expr: 'search', target_expr: ['address'] },\n  },\n  groupBy: [{ expr: 'type', as: 'sch' }],\n  letting: [\n    { key: 'amount_v2', value: 10 },\n    { key: 'size_v2', value: 20 },\n  ],\n  having: { type: { $like: '%hotel%' } },\n  orderBy: { type: 'DESC' },\n  limit: 10,\n  offset: 1,\n  use: ['airlineR_8093', 'airlineR_8094'],\n};\n\nconst query = new Query(params, 'travel-sample').build();\nconsole.log(query);\n\n```\n\nwhich translates to\n\n```sql\nSELECT COUNT(type) AS odm FROM travel-sample USE KEYS [\"airlineR_8093\",\"airlineR_8094\"] LET amount_val=10,size_val=20 WHERE ((price\u003eamount_val AND price IS NOT NULL) OR auto\u003e10 OR amount=10) AND ((price2\u003e1.99 AND price2 IS NOT NULL) AND ((price3\u003e1.99 AND price3 IS NOT NULL) OR id=\"20\")) AND ANY search IN address SATISFIES address=\"10\" END AND search IN [\"address\"] GROUP BY type AS sch LETTING amount_v2=10,size_v2=20 HAVING type LIKE \"%hotel%\" ORDER BY type DESC LIMIT 10 OFFSET 1\n```\n\n\n\n### Running custom query on cluster\n\n```ts\nimport { QueryCluster } from 'couchset';\n\nconst queryresults = await QueryCluster(queryBuilder);\n// queryresults = { rows: object[], meta: any}\n\n```\n\n## 6. Model Automation\n\nThis is how we automate it to generate code with all methods,schema, queries \n\n```ts\nconst automaticUser = userModel.automate();\n```\n\nAfter automating the model, `automaticUser` will come with Server-side Resolver functions, and client queries, mutations, subscriptions, like below\n\n\n```ts\n// Get all automatic generated resolvers and queries/fragments,mutations,subscriptions\nconst {\n  resolver: UserResolver, // Server resolver for building GraphQL \n  modelKeys: UserSelectors, // for any custom queries or exporting\n  client, // client queries,mutations,subscriptions\n} = automaticUser;\n\n```\n\n## 7. Write to filesystem\nTODO\n\n\n\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n#### Contributors needed \n- Create automatic pagination ✅\n- Create Schema and validation/population ✅\n- Create static methods for models like `save`, `update`, `findMany` e.t.c ✅\n- Automated indexes (only couchbase enterprise) ✅\n- Geospatial queries ✅\n- FTS queries ✅\n\n\n\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg height=\"300px\" src=\"./docs/couch.png\"\u003e\u003c/img\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003e Algo Inc \u003c/h1\u003e\n\u003c/p\u003e\n\n## License\t\nCouchset is [MIT licensed](./LICENSE).\n","funding_links":["https://github.com/sponsors/ceddybi"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchset%2Fcouchset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcouchset%2Fcouchset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchset%2Fcouchset/lists"}