{"id":22559597,"url":"https://github.com/random-guys/bucket","last_synced_at":"2025-07-04T10:37:00.110Z","repository":{"id":35138530,"uuid":"192759385","full_name":"random-guys/bucket","owner":"random-guys","description":"Handy CRUD methods for working with Mongoose","archived":false,"fork":false,"pushed_at":"2023-01-06T02:10:36.000Z","size":501,"stargazers_count":8,"open_issues_count":10,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T05:45:49.281Z","etag":null,"topics":["library","mongodb","mongoose","repository-pattern"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/random-guys.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-06-19T15:30:21.000Z","updated_at":"2021-10-14T02:13:58.000Z","dependencies_parsed_at":"2023-01-15T14:36:38.950Z","dependency_job_id":null,"html_url":"https://github.com/random-guys/bucket","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/random-guys%2Fbucket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/random-guys%2Fbucket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/random-guys%2Fbucket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/random-guys%2Fbucket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/random-guys","download_url":"https://codeload.github.com/random-guys/bucket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248190921,"owners_count":21062375,"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":["library","mongodb","mongoose","repository-pattern"],"created_at":"2024-12-07T21:07:37.642Z","updated_at":"2025-04-10T09:27:12.541Z","avatar_url":"https://github.com/random-guys.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bucket\n\nBucket is an implementation of the [Repository](https://martinfowler.com/eaaCatalog/repository.html) pattern over mongoose\n\n## How to install\n\n```shell\nyarn add @random-guys/bucket\n```\n\nor\n\n```shell\nnpm install @random-guys/bucket\n```\n\n## How does it work\n\nBucket is made up of 3 parts. An interface that defines the properties of the your model, a repository that defines basic operations and queries as well as custom ones, and a schema to help with conversion of types as well as validate input.\n\n## Quick Start\n\nDefine the properties of your model\n\n```ts\nimport { Model } from \"@random-guys/bucket\";\n\nexport interface Book extends Model {\n  isbn: string;\n  title: string;\n  version: Version;\n}\n\nexport interface Version {\n  major: number;\n  minor: number;\n  patch: number;\n}\n```\n\n`Model` is just an extension of mongoose's `Document` with support for timestamps as well as string(UUID) based id, \\_id.\n\nThen define a schema for your data using [SchemaTypes](https://mongoosejs.com/docs/schematypes.html) and custom schemas\n\n```ts\nimport { SchemaTypes, SchemaDefinition } from \"mongoose\";\nimport { SchemaFactory } from \"@random-guys/bucket\";\n\nconst VersionSchema: SchemaDefinition = {\n  major: { type: SchemaTypes.Number, default: 0 },\n  minor: { type: SchemaTypes.Number, default: 1 },\n  patch: { type: SchemaTypes.Number, default: 0 }\n};\n\nexport const BookSchema = SchemaFactory({\n  isbn: { type: SchemaTypes.String, trim: true },\n  title: { type: SchemaTypes.String, trim: true },\n  version: VersionSchema\n});\n```\n\n`SchemaFactory` gives you automatic UUID for `_id`, the actual definitions for timestamps and a `toJSON` mapper.\n\nNext, extend the `BaseRepository` which gives you access to generic operations and queries.\n\n```ts\nimport { Book } from \"./path/to/model\";\nimport { BookSchema } from \"./path/to/schema\";\nimport { BaseRepository } from \"@random-guys/bucket\";\nimport mongoose from \"mongoose\";\n\nclass PersonRepository extends BaseRepository\u003cPerson\u003e {\n  constructor() {\n    super(mongoose, \"Person\", PersonSchema);\n  }\n}\n\nexport const PersonRepo = new PersonRepository();\n```\n\nNow we are ready to use the DB.\n\n```ts\nimport { PersonRepo } from './path/to/repo';\nimport { defaultMongoOpts } from '@random-guys/bucket';\nimport mongoose from 'mongoose';\n\nawait mongoose.connect(url, defaultMongoOpts)\n\nconst person = await PersonRepo.byID(id));\nconst people = await PersonRepo.all({});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frandom-guys%2Fbucket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frandom-guys%2Fbucket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frandom-guys%2Fbucket/lists"}