{"id":25748746,"url":"https://github.com/emresandikci/pocketbase-query","last_synced_at":"2025-02-26T13:03:09.794Z","repository":{"id":275135413,"uuid":"925177376","full_name":"emresandikci/pocketbase-query","owner":"emresandikci","description":"A pocketbase query builder","archived":false,"fork":false,"pushed_at":"2025-02-25T21:12:10.000Z","size":227,"stargazers_count":31,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T22:20:16.787Z","etag":null,"topics":["pcoketbase","query","query-builder"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@emresandikci/pocketbase-query","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/emresandikci.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-31T11:33:24.000Z","updated_at":"2025-02-25T21:12:13.000Z","dependencies_parsed_at":"2025-01-31T12:43:00.985Z","dependency_job_id":"c7283335-442a-4a2e-8841-ff272d46a8cf","html_url":"https://github.com/emresandikci/pocketbase-query","commit_stats":null,"previous_names":["emresandikci/pocketbase-query"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emresandikci%2Fpocketbase-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emresandikci%2Fpocketbase-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emresandikci%2Fpocketbase-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emresandikci%2Fpocketbase-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emresandikci","download_url":"https://codeload.github.com/emresandikci/pocketbase-query/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240755001,"owners_count":19852305,"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","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":["pcoketbase","query","query-builder"],"created_at":"2025-02-26T13:01:30.103Z","updated_at":"2025-02-26T13:03:09.744Z","avatar_url":"https://github.com/emresandikci.png","language":"TypeScript","funding_links":[],"categories":["TypeScript tools"],"sub_categories":[],"readme":"# Pocketbase Query\n\n\u003ca href=\"https://www.npmjs.com/package/@emresandikci/pocketbase-query\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@emresandikci/pocketbase-query?color=birgtgreen\"\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/npm/l/@emresandikci/pocketbase-query\"\u003e\n\u003cimg alt=\"semantic-release\" src=\"https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\"\u003e\n\u003ca href=\"https://twitter.com/emresand1kc1\" target=\"\\_parent\"\u003e\n  \u003cimg alt=\"\" src=\"https://img.shields.io/twitter/follow/emresandikci.svg?style=social\u0026label=Follow\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.producthunt.com/posts/pocketbase-query\" target=\"\\_parent\"\u003e\n  \u003cimg alt=\"\" src=\"https://img.shields.io/badge/Product%20Hunt-DA552F?logo=producthunt\u0026logoColor=fff\" /\u003e\n\u003c/a\u003e\n\n## Overview\n\n`@emresandikci/pocketbase-query` is a TypeScript-based query builder designed to generate complex filter queries for PocketBase. It allows for easy construction of queries using various operators while maintaining a fluent and chainable API.\n\n---\n\n## Installation\n\nThis library can be used in any TypeScript/JavaScript project. Simply import it as needed:\n\n```bash\nnpm i @emresandikci/pocketbase-query\n```\n\n```typescript\nimport PocketbaseQuery from '@emresandikci/pocketbase-query';\n```\n\n---\n\n## Usage\n\n### Creating an Instance\n\nThe `PocketbaseQuery` class follows the singleton pattern. You should use `getInstance()` to get a query builder instance:\n\n\n```typescript\nconst query = PocketbaseQuery.getInstance\u003cMyType\u003e();\n```\n\n## Example\n\n```typescript\nimport PocketbaseQuery from '@emresandikci/pocketbase-query';\n\nconst query = PocketbaseQuery.getInstance\u003c{ status: string; comments: number }\u003e();\n\nconst customFilters = query\n  .equal('status', 'active')\n  .and()\n  .greaterThan('comments', 50)\n  .build();\n\nconsole.log(customFilters); // Outputs: status='active' \u0026\u0026 comments\u003e50\n\nawait pb.collection('posts').getFullList({\n\tfilter: customFilters,\n\texpand: [{ key: 'comments_via_post' }],\n})\n```\n\n---\n\n## API Methods\n\n### Operators Enum\n\n`OperatorEnum` defines a set of operators for use in queries:\n\n```typescript\nenum OperatorEnum {\n  Equal = \"=\",\n  NotEqual = \"!=\",\n  GreaterThan = \"\u003e\",\n  GreaterThanOrEqual = \"\u003e=\",\n  LessThan = \"\u003c\",\n  LessThanOrEqual = \"\u003c=\",\n  Like = \"~\",\n  NotLike = \"!~\",\n  AnyEqual = \"?=\",\n  AnyNotEqual = \"?!=\",\n  AnyGreaterThan = \"?\u003e\",\n  AnyGreaterThanOrEqual = \"?\u003e=\",\n  AnyLessThan = \"?\u003c\",\n  AnyLessThanOrEqual = \"?\u003c=\",\n  AnyLike = \"?~\",\n  AnyNotLike = \"?!~\",\n}\n```\n\n### Query Builder Methods\n\n#### `equal(field: keyof T, value: string | boolean)`\n\nAdds an equality condition to the query.\n\n```typescript\nquery.equal(\"status\", \"active\");\n```\n\n#### `notEqual(field: keyof T, value: string)`\n\nAdds a not-equal condition to the query.\n\n```typescript\nquery.notEqual(\"category\", \"archived\");\n```\n\n#### `greaterThan(field: keyof T, value: string)`\n\nAdds a greater-than condition.\n\n```typescript\nquery.greaterThan(\"age\", \"18\");\n```\n\n#### `lessThan(field: keyof T, value: string)`\n\nAdds a less-than condition.\n\n```typescript\nquery.lessThan(\"price\", \"100\");\n```\n\n#### `like(field: keyof T, value: string)`\n\nAdds a LIKE condition (partial match).\n\n```typescript\nquery.like(\"name\", \"John\");\n```\n\n#### `notLike(field: keyof T, value: string)`\n\nAdds a NOT LIKE condition.\n\n```typescript\nquery.notLike(\"description\", \"discount\");\n```\n\n#### `anyEqual(field: keyof T, value: string)`\n\nAdds an equality condition for array fields.\n\n```typescript\nquery.anyEqual(\"tags\", \"sale\");\n```\n\n#### `in(field: keyof T, values: any[])`\n\nAdds an OR condition for multiple values.\n\n```typescript\nquery.in(\"category\", [\"electronics\", \"furniture\"]);\n```\n\n#### `customFilter(filter: string)`\n\nAdds a custom filter string to the query.\n\n```typescript\nquery.customFilter(\"status='active' \u0026\u0026 price\u003e100\");\n```\n\n---\n\n### Logical Operators\n\n#### `and()`\n\nJoins multiple conditions with `\u0026\u0026`.\n\n```typescript\nquery.equal(\"status\", \"active\").and().greaterThan(\"price\", \"50\");\n```\n\n#### `or()`\n\nJoins multiple conditions with `||`.\n\n```typescript\nquery.equal(\"status\", \"active\").or().equal(\"status\", \"pending\");\n```\n\n#### `openBracket()` and `closeBracket()`\n\nGroups conditions using parentheses.\n\n```typescript\nquery.openBracket().equal(\"status\", \"active\").or().equal(\"status\", \"pending\").closeBracket().and().greaterThan(\"price\", \"50\");\n```\n\n---\n\n### Query Execution\n\n#### `getQuery()`\n\nReturns the current query string.\n\n```typescript\nconst queryString = query.getQuery();\n```\n\n#### `build()`\n\nFinalizes and returns the query string while clearing the internal state.\n\n```typescript\nconst finalQuery = query.build();\n```\n\n\n## Notes\n\n- The `PocketbaseQuery` class uses a singleton pattern, meaning a single instance is reused across calls.\n- The `.build()` method resets the query, so ensure you store the generated string if you need it.\n- The `in()` method applies `OR` between multiple values.\n\n---\n\n## License\n\nMIT License\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femresandikci%2Fpocketbase-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femresandikci%2Fpocketbase-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femresandikci%2Fpocketbase-query/lists"}