{"id":20350002,"url":"https://github.com/webbestmaster/petsdb","last_synced_at":"2025-04-12T01:32:07.831Z","repository":{"id":65026756,"uuid":"580940119","full_name":"webbestmaster/petsdb","owner":"webbestmaster","description":"File-based embedded data store for node.js","archived":false,"fork":false,"pushed_at":"2024-09-24T21:58:46.000Z","size":304,"stargazers_count":22,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T21:11:59.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/webbestmaster.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2022-12-21T21:02:55.000Z","updated_at":"2024-09-24T21:58:50.000Z","dependencies_parsed_at":"2023-12-23T22:48:57.802Z","dependency_job_id":"5752b7fd-3fbd-46c8-bfa8-efeabc9d2012","html_url":"https://github.com/webbestmaster/petsdb","commit_stats":{"total_commits":59,"total_committers":2,"mean_commits":29.5,"dds":0.3389830508474576,"last_synced_commit":"c3a9adf0a05a0ecd032c19d6da28a0578ec880ec"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbestmaster%2Fpetsdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbestmaster%2Fpetsdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbestmaster%2Fpetsdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbestmaster%2Fpetsdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webbestmaster","download_url":"https://codeload.github.com/webbestmaster/petsdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248504198,"owners_count":21115133,"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":[],"created_at":"2024-11-14T22:28:30.237Z","updated_at":"2025-04-12T01:32:07.806Z","avatar_url":"https://github.com/webbestmaster.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PeTSDB - Pet's TypeScript DataBase\n\n[![GitHub license](https://img.shields.io/npm/l/petsdb)](https://github.com/webbestmaster/petsdb/blob/master/license)\n[![codecov](https://codecov.io/gh/webbestmaster/petsdb/branch/master/graph/badge.svg)](https://codecov.io/gh/webbestmaster/petsdb)\n[![npm version](https://img.shields.io/npm/v/petsdb.svg)](https://www.npmjs.com/package/petsdb)\n[![Known Vulnerabilities](https://snyk.io/test/github/webbestmaster/petsdb/badge.svg)](https://snyk.io/test/github/webbestmaster/petsdb)\n[![Dependency count](https://badgen.net/bundlephobia/dependency-count/petsdb)](https://libraries.io/npm/petsdb)\n[![npm bundle size](https://img.shields.io/bundlephobia/minzip/petsdb)](https://bundlephobia.com/package/petsdb)\n[![nodejs version](https://img.shields.io/node/v/petsdb)](https://nodejs.org/en/docs)\n[![Github CI](https://github.com/webbestmaster/petsdb/actions/workflows/github-ci.yml/badge.svg)](https://github.com/webbestmaster/petsdb/actions/workflows/github-ci.yml)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/webbestmaster/petsdb/github-ci.yml)](https://github.com/webbestmaster/petsdb/actions/workflows/github-ci.yml)\n[![Type definitions](https://img.shields.io/npm/types/petsdb)](https://www.typescriptlang.org)\n[![Website](https://img.shields.io/website?url=https://github.com/webbestmaster/petsdb)](https://github.com/webbestmaster/petsdb)\n[![CodeFactor](https://www.codefactor.io/repository/github/webbestmaster/petsdb/badge)](https://www.codefactor.io/repository/github/webbestmaster/petsdb)\n[![Package Quality](https://packagequality.com/shield/petsdb.svg)](https://packagequality.com/#?package=petsdb)\n[![GitHub stars](https://img.shields.io/github/stars/webbestmaster/petsdb?style=social)](https://github.com/webbestmaster/petsdb)\n\n\u003c!--\n[![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/webbestmaster/petsdb)](https://libraries.io/npm/petsdb)\n--\u003e\n\nSmall database for _prototyping_ and _pet_ projects. Not for production.\n\n**Embedded persistent database for Node.js, 100% TypeScript/JavaScript, no binary dependency.**\n\n## Installation\nModule name on npm is `petsdb`.\n\n```shell\n$ npm install petsdb --save     # Put latest version in your package.json\n$ npm run test:unit             # You'll need the dev dependencies to run tests\n```\n\n### Creating/loading a database\nYou can use `Petsdb` as a persistent datastore. One datastore is the equivalent of a collection\\array. The constructor is used as follows `new Petsdb(config)` where `config` is an object with the following fields (actually one field only):\n\n* `dbPath` (required): path to the file where the data is persisted.\n\n```typescript\nimport {Petsdb} from 'petsdb';\n\ntype ExampleDataType = {\n    listOfNumber: Array\u003cnumber\u003e;\n    listOfString: Array\u003cstring\u003e;\n    someData: {\n        data: {\n            isExists: boolean;\n            text: string;\n        };\n    };\n    someNumber: number;\n    someString: string;\n};\n\n// create dataBase\nconst petsdb: Petsdb\u003cExampleDataType\u003e = new Petsdb\u003cExampleDataType\u003e({dbPath: 'path/to/your/file'});\n\n// run dataBase, use async/await OR Promises\nawait petsdb.run();\n```\n\n### Creating documents\nPetsdb uses `JSON.stringify` to place document. Also, Petsdb will automatically generate `_id` (a 16-characters alphanumerical string). The `_id` of a document, once set, cannot be modified.\n\n```typescript\nconst someDocument: ExampleDataType = {\n    listOfNumber: [1, 2, 3],\n    listOfString: ['one', 'two', 'three'],\n    someData: {\n        data: {\n            isExists: false,\n            text: 'lorem ipsum',\n        },\n    },\n    someNumber: 1,\n    someString: 'the string',\n};\n\n// create document into dataBase, use async/await OR Promises\nawait petsdb.create(someDocument);\n```\n\n### Reading documents\nUse `read` to look for multiple documents matching you query.\nOr use `readOne` to look for one specific document.\nOr use `readPage` to look for multiple documents matching you query by pagination.\n\nYou can use regular expressions in basic querying in place of a string and an array of string.\n\nYou can sort paginated result (`readPage` only) using `sort`. You can use nested properties to navigate inside nested documents (see below).\n\n#### Reading documents: read\\readOne\nMethod `.read()` read database by query. It returns promise with array of items. Method `.readOne()` works the same as `.read()`, but returns promise with _one_ item or `null`.\n\n```typescript\n// search by key\\value\nawait petsdb.read({someString: 'the string'});\n\n// search by nested object\nawait petsdb.read({someData: {data: {isExists: false}}});\n\n// search by value(s) of array\nawait petsdb.read({listOfString: ['one']});\n\n// search by RegExp instead of string\nawait petsdb.read({someString: /the/});\n\n// search by RegExp instead of array of string\nawait petsdb.read({listOfString: /thr/});\n```\n\n#### Reading documents: readPage\nMethod `.readPage()` read database by query and sort. It returns promise with page of items.\n```typescript\n// get page by index 0, set page's size as 10 and sort by `someNumber`\nawait petsdb.readPage({someString: /the/}, {pageIndex: 0, pageSize: 10, sort: {someNumber: 1}});\n\n// the same, but use for sort nested object\nawait petsdb.readPage({someString: /the/}, {pageIndex: 0, pageSize: 10, sort: {someData: {data: {text: -1}}}});\n```\n\n#### Updating documents\nMethod `.update()` updates documents by query. All data of document needed. No partial update.\n\n```typescript\nconst newDocument: ExampleDataType = {\n    listOfNumber: [100, 200, 300],\n    listOfString: ['not one', 'not two', 'not three'],\n    someData: {\n        data: {\n            isExists: true,\n            text: 'dolor',\n        },\n    },\n    someNumber: 1,\n    someString: 'new string',\n};\n\n// fully update document, all data needed\nawait petsdb.update({someNumber: 1}, newDocument);\n```\n\n#### Deleting documents\nMethod `.delete()` delete documents by query.\n```typescript\nawait petsdb.delete({someNumber: 1});\n```\n\n#### Basic querying\nBasic querying means are looking for documents whose fields match the ones you specify. You can use regular expression to match strings. To check your query use `PetsdbQueryType`.\n\n```typescript\nimport type {PetsdbQueryType} from 'petsdb';\n\nconst myQuery: PetsdbQueryType\u003cExampleDataType\u003e = {\n    someData: {data: {isExists: true}},\n    someString: /one/,\n};\n```\n\n#### Basic sorting\nBasic sorting means are sorting for documents whose fields match the ones you specify. You can use `1` or `-1` to sort. You can use only one field to sort. To check your sort use `PetsdbSortType`.\n\n```typescript\nimport type {PetsdbSortType} from 'petsdb';\n\nconst mySortByNumber: PetsdbSortType\u003cExampleDataType\u003e = {\n    someString: 1,\n};\n\nconst mySortByNestedObject: PetsdbSortType\u003cExampleDataType\u003e = {\n    someData: {data: {text: -1}},\n};\n```\n\n##### Full export: class and types\n```typescript\nimport {Petsdb} from 'petsdb';\nimport type {\n    PetsdbInitialConfigType,\n    PetsdbItemType,\n    PetsdbQueryType,\n    PetsdbReadPageConfigType,\n    PetsdbReadPageResultType,\n    PetsdbSortDirectionType,\n    PetsdbSortType,\n    PetsdbSortValueType,\n} from 'petsdb';\n```\n\n## License\n\nSee [license](license).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebbestmaster%2Fpetsdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebbestmaster%2Fpetsdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebbestmaster%2Fpetsdb/lists"}