@loopback/repository
Advanced tools
Comparing version 4.0.0-alpha.4 to 4.0.0-alpha.5
{ | ||
"name": "@loopback/repository", | ||
"version": "4.0.0-alpha.4", | ||
"version": "4.0.0-alpha.5", | ||
"description": "Repository for LoopBack.next", | ||
@@ -23,6 +23,6 @@ "main": "index", | ||
"devDependencies": { | ||
"@loopback/testlab": "^4.0.0-alpha.5" | ||
"@loopback/testlab": "^4.0.0-alpha.6" | ||
}, | ||
"dependencies": { | ||
"@loopback/context": "^4.0.0-alpha.9", | ||
"@loopback/context": "^4.0.0-alpha.11", | ||
"loopback-datasource-juggler": "^3.9.2" | ||
@@ -29,0 +29,0 @@ }, |
100
README.md
# @loopback/repository | ||
This module provides data access facilities to various databases and services. | ||
It contains the constructs for modeling and accessing data. | ||
It provides a common set of interfaces for interacting with databases. | ||
## Overview | ||
**NOTE**: This module is experimental and evolving. It is likely going to be | ||
@@ -11,6 +12,49 @@ refactored and decomposed into multiple modules as we refine the story based on | ||
# Concepts | ||
This module provides data access facilities to various databases and services. | ||
It contains the constructs for modeling and accessing data. Repositories can be | ||
used alone or as part of `Controller` implementation. | ||
## Repository | ||
## Installation | ||
``` | ||
$ npm install --save @loopback/repository | ||
``` | ||
## Basic use | ||
The repository module provides APIs to define LoopBack 3.x data sources and | ||
models. For example, | ||
```ts | ||
import { | ||
DataSourceConstructor, | ||
juggler, | ||
} from '@loopback/repository'; | ||
const ds: juggler.DataSource = new DataSourceConstructor({ | ||
name: 'db', | ||
connector: 'memory', | ||
}); | ||
/* tslint:disable-next-line:variable-name */ | ||
const Note = ds.createModel<typeof juggler.PersistedModel>( | ||
'note', | ||
{title: 'string', content: 'string'}, | ||
{}, | ||
); | ||
``` | ||
A repository can be created directly using `DefaultCrudRepository`. | ||
```ts | ||
const repo = new DefaultCrudRepository(Note, ds); | ||
// Bind the repository instance | ||
ctx.bind('repositories.noteRepo').to(repo); | ||
``` | ||
Fore more detailed info about the repository usage and implementation with a controller, please refer to [Use Repository](#use-repository) | ||
## Concepts | ||
### Repository | ||
`Repository` represents a specialized `Service` interface that provides | ||
@@ -39,3 +83,3 @@ strong-typed data access (for example, CRUD) operations of a domain model | ||
## Model | ||
### Model | ||
@@ -89,3 +133,3 @@ A model describes business domain objects, for example, `Customer`, `Address`, | ||
## DataSource | ||
### DataSource | ||
@@ -109,3 +153,3 @@ `DataSource` is a named configuration of a connector. The configuration | ||
## Connector | ||
### Connector | ||
@@ -123,3 +167,3 @@ `Connector` is a provider that implements data access or api calls with a | ||
## Mixin | ||
### Mixin | ||
@@ -161,3 +205,3 @@ `Mixin` is a way of building up classes from reusable components by combining | ||
## Type | ||
### Type | ||
@@ -177,4 +221,3 @@ To support property and parameter typing, LoopBack Next introduces an extensible | ||
# Use Repository | ||
## Use Repository | ||
The `Repository` and other interfaces extended from `Repository` provide access | ||
@@ -188,3 +231,3 @@ to backend databases and services. Repositories can be used alone or as part | ||
## Define legacy data sources and models | ||
### Define legacy data sources and models | ||
@@ -217,3 +260,3 @@ The repository module provides APIs to define LoopBack 3.x data sources and | ||
## Define a repository | ||
### Define a repository | ||
@@ -246,3 +289,3 @@ A repository can be created directly using `DefaultCrudRepository`. | ||
## Define a controller | ||
### Define a controller | ||
@@ -294,5 +337,5 @@ Controllers serve as handlers for API requests. We declare controllers as | ||
## Run the controller and repository together | ||
### Run the controller and repository together | ||
### Bind the repository to context | ||
#### Bind the repository to context | ||
@@ -324,3 +367,3 @@ ```ts | ||
## Compose repositories and controllers in a context | ||
### Compose repositories and controllers in a context | ||
@@ -360,3 +403,3 @@ ```ts | ||
## Mix in a repository into the controller (To be implemented) | ||
### Mix in a repository into the controller (To be implemented) | ||
@@ -388,3 +431,3 @@ This style allows repository methods to be mixed into the controller class | ||
# Declare pre-defined repositories in JSON/YAML (To be implemented) | ||
## Declare pre-defined repositories in JSON/YAML (To be implemented) | ||
@@ -403,4 +446,3 @@ Repositories can be declared in JSON/YAML files as follows: | ||
``` | ||
# References | ||
## Related resources | ||
- https://martinfowler.com/eaaCatalog/repository.html | ||
@@ -410,1 +452,17 @@ - https://msdn.microsoft.com/en-us/library/ff649690.aspx | ||
## Contributions | ||
- [Guidelines](https://github.com/strongloop/loopback-next/wiki/Contributing##guidelines) | ||
- [Join the team](https://github.com/strongloop/loopback-next/issues/110) | ||
## Tests | ||
run 'npm test' from the root folder. | ||
## Contributors | ||
See [all contributors](https://github.com/strongloop/loopback-next/graphs/contributors). | ||
## License | ||
MIT |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1141888
453