-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from GuoXiCheng/dev-c
update docs
- Loading branch information
Showing
11 changed files
with
661 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# How to Build and Run | ||
|
||
## Clone the Repository | ||
|
||
```bash | ||
git clone [email protected]:GuoXiCheng/TinyCRUD.git | ||
``` | ||
|
||
## Install Dependencies | ||
|
||
```bash | ||
cd TinyCRUD | ||
|
||
npm install | ||
``` | ||
|
||
## Run Tests | ||
|
||
```bash | ||
npm run test | ||
``` | ||
|
||
By default, to ensure that the tests are not affected by the test environment, they are executed in a simulated environment. If you need to perform the tests using real network request APIs, create a new .env file in the project root directory with the following content: | ||
|
||
::: warning | ||
If `USE_API = true` is set, real network requests will be made during the test process, so whether the tests pass depends not only on whether the code is correct, but also on whether your network environment is normal and the settings are correct. | ||
::: | ||
|
||
```makefile | ||
USE_API=true # Whether to use a real network environment | ||
TEST_ENCRYPT_KEY=YourEncryptKey | ||
|
||
# Gitee | ||
TEST_GITEE_TOKEN=Your Gitee Token | ||
TEST_GITEE_OWNER=Your Gitee Owner | ||
TEST_GITEE_REPO=Your Gitee Repo | ||
TEST_GITEE_NUMBER=Your Gitee Issue Number | ||
|
||
# Github | ||
TEST_GITHUB_TOKEN=Your Github Token | ||
TEST_GITHUB_OWNER=Your Github Owner | ||
TEST_GITHUB_REPO=Your Github Repo | ||
TEST_GITHUB_NUMBER=Your Github Issue Number | ||
|
||
# Gitlab | ||
TEST_GITLAB_TOKEN=Your Gitlab Token | ||
TEST_GITLAB_PROJECT_ID=Your Gitlab Project ID | ||
TEST_GITLAB_NUMBER=Your Gitlab Issue Number | ||
``` | ||
|
||
## Build | ||
|
||
```bash | ||
npm run build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Creating a Data Model | ||
|
||
## What is a Data Model | ||
|
||
A data model is used to define the data structure of an object. | ||
|
||
Data models can inherit from `BaseModel`, thereby having basic fields: `id`, `created_at`, `updated_at`, and `created_by`, which are automatically populated from the corresponding data. | ||
|
||
## Custom Data Model | ||
|
||
Here, as an example of a user data model, we create a `User` model that includes fields such as name, age, and gender. | ||
|
||
```ts | ||
import { BaseModel } from "tiny-crud"; | ||
|
||
export interface UserModel extends BaseModel { | ||
name: string; | ||
age: number; | ||
gender: string; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Creating a Data Repository | ||
|
||
## What is a Data Repository | ||
|
||
A data repository is used to define methods for manipulating data. | ||
|
||
A data repository can inherit from a corresponding platform's repository class, thus having some basic CRUD methods. | ||
|
||
## Customizing a Data Repository | ||
|
||
### Defining the Repository Class | ||
|
||
Inherit from the corresponding platform's repository class to be able to call the respective platform's Issue API. | ||
|
||
The second parameter of the constructor: `Your Issue Number` represents the Issue number corresponding to the current repository. If not provided, it defaults to using the `issueNumber` property of the first parameter object. | ||
|
||
::: code-group | ||
|
||
```ts [github] | ||
import { GithubRepository } from "tiny-crud"; | ||
import { githubRequest } from "./github-request"; | ||
|
||
export class UserRepository extends GithubRepository<UserModel> { | ||
constructor() { | ||
super(githubRequest, "Your Issue Number"); | ||
} | ||
} | ||
``` | ||
|
||
```ts [gitee] | ||
import { GiteeRepository } from "tiny-crud"; | ||
import { giteeRequest } from "./gitee-request"; | ||
|
||
export class UserRepository extends GiteeRepository<UserModel> { | ||
constructor() { | ||
super(giteeRequest, "Your Issue Number"); | ||
} | ||
} | ||
``` | ||
|
||
```ts [gitlab] | ||
import { GitlabRepository } from "tiny-crud"; | ||
import { gitlabRequest } from "./gitlab-request"; | ||
|
||
export class UserRepository extends GitlabRepository<UserModel> { | ||
constructor() { | ||
super(gitlabRequest, "Your Issue Number"); | ||
} | ||
} | ||
``` | ||
|
||
::: | ||
|
||
### Creating Repository Objects | ||
|
||
You can use the conventional object creation method to create a repository object: | ||
|
||
```ts | ||
const userRepository = new UserRepository(); | ||
``` | ||
|
||
Alternatively, you can use `SingletonFactory` to create a singleton object: | ||
|
||
```ts | ||
import { SingletonFactory } from "tiny-crud"; | ||
|
||
const userRepository = SingletonFactory.createInstance(UserRepository); | ||
``` | ||
|
||
### Extending the Repository Class | ||
|
||
The data repository provides some basic CRUD methods, but you can extend them further: | ||
|
||
```ts | ||
import { GithubRepository } from "tiny-crud"; | ||
import { githubRequest } from "./github-request"; | ||
|
||
export class UserRepository extends GithubRepository<UserModel> { | ||
constructor() { | ||
super(githubRequest); | ||
} | ||
|
||
async findByName(name: string): Promise<UserModel[]> { | ||
const users = await this.find(); | ||
return users.filter((user) => user.name === name); | ||
} | ||
} | ||
``` |
Oops, something went wrong.