{"_id":"@aaqilniz/repository","name":"@aaqilniz/repository","dist-tags":{"latest":"5.0.4"},"versions":{"5.0.4":{"name":"@aaqilniz/repository","description":"Define and implement a common set of interfaces for interacting with databases","version":"5.0.4","license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","author":{"name":"IBM Corp. and LoopBack contributors"},"copyright.owner":"IBM Corp. and LoopBack contributors","repository":{"type":"git","url":"git+https://github.com/loopbackio/loopback-next.git","directory":"packages/repository"},"engines":{"node":"14 || 16 || 17 || 18"},"scripts":{"acceptance":"lb-mocha \"dist/__tests__/acceptance/**/*.js\"","build":"lb-tsc","clean":"lb-clean loopback-repository*.tgz dist *.tsbuildinfo package","pretest":"npm run build","test":"lb-mocha \"dist/__tests__/**/*.js\"","verify":"npm pack && tar xf loopback-repository*.tgz && tree package && npm run clean"},"publishConfig":{"access":"public"},"peerDependencies":{"@loopback/core":"^4.0.4"},"dependencies":{"@loopback/filter":"^3.0.4","@types/debug":"^4.1.7","debug":"^4.3.4","lodash":"^4.17.21","@aaqilniz/loopback-datasource-juggler":"^4.27.8","tslib":"^2.4.0"},"devDependencies":{"@loopback/build":"^9.0.4","@loopback/core":"^4.0.4","@loopback/eslint-config":"^13.0.4","@loopback/testlab":"^5.0.4","@types/bson":"^4.0.5","@types/json-schema":"^7.0.11","@types/lodash":"^4.14.187","@types/node":"^14.18.33","bson":"4.7.0"},"gitHead":"71f4fff606e2849856785d4ad865c164a7fdb8ce","bugs":{"url":"https://github.com/loopbackio/loopback-next/issues"},"homepage":"https://github.com/loopbackio/loopback-next#readme","_id":"@aaqilniz/repository@5.0.4","_nodeVersion":"16.13.0","_npmVersion":"8.5.3","dist":{"integrity":"sha512-NHTUPLuog3BPPE1dxGb+XLIGGg+RvLmtREFpQ7uAucpTIoYwYyIWdiP0CVfx1CUjbCaWNa+fNt8Wnn2XxM3Dsg==","shasum":"fb20210e2fd4aabbd1c0b379f3379a308ad7af38","tarball":"https://registry.npmjs.org/@aaqilniz/repository/-/repository-5.0.4.tgz","fileCount":303,"unpackedSize":809935,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGQp0xOqm8QRCNxSO6cMQiS35x2+OjneP5NDCybFZ/0NAiBSIBCLaBzHoaZ2EhOqzzOQH7Ijztc4EmpPPjluYlWgcg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjZhR4ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpjCA//d8zIfqR1cApIX9j4JkJD6vzsHo+kGZxp5A1Gc4VRzyVt3Q7q\r\nASJpfr5b9ECNGTqYyjGXcr8DAnAy+LQOMq8/ESpipLTjjVW20PUIXtdvgJFq\r\nzTBGr7oLSLUbxQXeRAE3E3n2ThPFg+5vAZd9Zdw4IlPfcAtu4pm7j1vybwdh\r\nQA+KiQ2ZawD7yeOphlXyQ5pJHJs+unBtgpaGERcvBmtwI1lzlcEWp3Z5e1Ew\r\ndMjvY8LeHAdjOu6KNanMheqJc/sYMNLeVmlFvApelNTZbjglwaLR/z+oN8WD\r\nl2XvEcYDNH0DG9772nMWYjtVDx2Wb2BJytQq3A4hnLC3WqdE42zTj5lGCkMD\r\nerNw27SAeUBPrv+9EhHQgt6FZZfuBKUBIQjsvX7GiOfg54u/MI41HoIiSxWD\r\nEXGfZxgSOscA3ZQNuZf5pqT6+e5kz7Pzuz/cR+08fUmXkTZYukUQ/rQlBk3F\r\nGLx/vZXGX7dHhKNfN8lG2qVjEsY21H6F+jS9ydIW8w1+E77kSe1n/sNgEcJ9\r\nzVg8/qJZSVVXgQuMpBHHOcCPfshXHygyZFruGyci+X5OgqMXlqatWs5YNZcy\r\nv5umrdNBfoz0Z431TgNzVqNMn79/7CWKRUbylggHO0rBn0Kbd8fEeF4UqVBn\r\n1cYxPkjY0q5zmaYBWgczahKVKTa+rE+tNWQ=\r\n=n0wf\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"aaqilniz","email":"aaqilniz@yahoo.com"},"directories":{},"maintainers":[{"name":"aaqilniz","email":"aaqilniz@yahoo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/repository_5.0.4_1667634296077_0.7178955295941216"},"_hasShrinkwrap":false}},"time":{"created":"2022-11-05T07:44:56.016Z","5.0.4":"2022-11-05T07:44:56.301Z","modified":"2022-11-05T07:44:56.429Z"},"maintainers":[{"name":"aaqilniz","email":"aaqilniz@yahoo.com"}],"description":"Define and implement a common set of interfaces for interacting with databases","homepage":"https://github.com/loopbackio/loopback-next#readme","repository":{"type":"git","url":"git+https://github.com/loopbackio/loopback-next.git","directory":"packages/repository"},"author":{"name":"IBM Corp. and LoopBack contributors"},"bugs":{"url":"https://github.com/loopbackio/loopback-next/issues"},"license":"MIT","readme":"# @loopback/repository\n\nThis module provides a common set of interfaces for interacting with databases.\n\n## Overview\n\nThis module provides data access facilities to various databases and services as\nwell as the constructs for modeling and accessing those data.\n\n## Installation\n\n```sh\nnpm install --save @loopback/repository\n```\n\n## Basic use\n\nAt the moment, we only have implementations of `Repository` based on LoopBack\n3.x `loopback-datasource-juggler` and connectors. The following steps illustrate\nhow to define repositories and use them with controllers.\n\n### Defining a legacy datasource and a model\n\nThe repository module provides APIs to define LoopBack 3.x data sources and\nmodels. For example,\n\n```ts\n// src/datasources/db.datasource.ts\nimport {juggler} from '@loopback/repository';\n\nexport const db: juggler.DataSource = new juggler.DataSource({\n  name: 'db',\n  connector: 'memory',\n});\n```\n\n```ts\n// src/models/note.model.ts\nimport {model, Entity, property} from '@loopback/repository';\n\n@model()\nexport class Note extends Entity {\n  @property({id: true})\n  id: string;\n  @property()\n  title: string;\n  @property()\n  content: string;\n}\n\nexport interface NoteRelations {\n  // describe navigational properties here\n}\n\nexport type NoteWithRelations = Note & NoteRelations;\n```\n\n**NOTE**: There is no declarative support for data source and model yet in\nLoopBack 4. These constructs need to be created programmatically as illustrated\nabove.\n\n### Defining a repository\n\nA repository can be created by extending `DefaultCrudRepository` and using\ndependency injection to resolve the datasource.\n\n```ts\n// src/repositories/note.repository.ts\nimport {DefaultCrudRepository, DataSourceType} from '@loopback/repository';\nimport {Note, NoteRelations} from '../models';\nimport {inject} from '@loopback/core';\n\nexport class NoteRepository extends DefaultCrudRepository<\n  Note,\n  typeof Note.prototype.id,\n  NoteRelations\n> {\n  constructor(@inject('datasources.db') protected dataSource: DataSourceType) {\n    super(Note, dataSource);\n  }\n}\n```\n\n### Defining a controller\n\nControllers serve as handlers for API requests. We declare controllers as\nclasses with optional dependency injection by decorating constructor parameters\nor properties.\n\n```ts\n// src/controllers/note.controller.ts\nimport {repository} from '@loopback/repository';\nimport {NoteRepository} from '../repositories';\nimport {Note} from '../models';\nimport {post, requestBody, get, param} from '@loopback/rest';\n\nexport class NoteController {\n  constructor(\n    // Use constructor dependency injection to set up the repository\n    @repository(NoteRepository) public noteRepo: NoteRepository,\n  ) {}\n\n  // Create a new note\n  @post('/note')\n  create(@requestBody() data: Note) {\n    return this.noteRepo.create(data);\n  }\n\n  // Find notes by title\n  @get('/note/{title}')\n  findByTitle(@param.path.string('title') title: string) {\n    return this.noteRepo.find({where: {title}});\n  }\n}\n```\n\n### Run the controller and repository together\n\n#### Using the Repository Mixin for Application\n\nA Repository Mixin is available for Application that provides convenience\nmethods for binding and instantiating a repository class. Bound instances can be\nused anywhere in your application using Dependency Injection. The\n`.repository(RepositoryClass)` function can be used to bind a repository class\nto an Application. The mixin will also instantiate any repositories declared by\na component in its constructor using the `repositories` key.\n\nRepositories will be bound to the key `repositories.RepositoryClass` where\n`RepositoryClass` is the name of the Repository class being bound.\n\nWe'll use `BootMixin` on top of `RepositoryMixin` so that Repository bindings\ncan be taken care of automatically at boot time before the application starts.\n\n```ts\nimport {BootMixin} from '@loopback/boot';\nimport {ApplicationConfig} from '@loopback/core';\nimport {RepositoryMixin} from '@loopback/repository';\nimport {RestApplication} from '@loopback/rest';\nimport {db} from './datasources/db.datasource';\n\nexport class RepoApplication extends BootMixin(\n  RepositoryMixin(RestApplication),\n) {\n  constructor(options?: ApplicationConfig) {\n    super(options);\n    this.projectRoot = __dirname;\n    this.dataSource(db);\n  }\n}\n```\n\n## Related resources\n\n- <https://martinfowler.com/eaaCatalog/repository.html>\n- <https://msdn.microsoft.com/en-us/library/ff649690.aspx>\n- <http://docs.spring.io/spring-data/data-commons/docs/2.0.0.M3/reference/html/#repositories>\n\n## Contributions\n\n- [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)\n- [Join the team](https://github.com/loopbackio/loopback-next/issues/110)\n\n## Tests\n\nRun `npm test` from the root folder.\n\n## Contributors\n\nSee\n[all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).\n\n## License\n\nMIT\n","readmeFilename":"README.md"}