Skip to content

Commit

Permalink
Merge pull request #104 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
update docs
  • Loading branch information
GuoXiCheng authored Jun 6, 2024
2 parents bccc1ac + 05f824d commit 86660a8
Show file tree
Hide file tree
Showing 11 changed files with 661 additions and 42 deletions.
42 changes: 21 additions & 21 deletions README.en.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[简体中文](README.md) | ENGLISH
[简体中文](README.md) | ENGLISH

# TinyCRUD

Expand Down Expand Up @@ -84,13 +84,13 @@ import axios from "axios";
import { createRequest } from "tiny-crud";

const GithubRequest = createRequest({
httpLib: "axios",
httpClient: axios,
accessToken: "Your Personal Access Token",
httpLib: "axios",
httpClient: axios,
accessToken: "Your Personal Access Token",

platform: "github",
owner: "Your Owner",
repo: "Your Repo",
platform: "github",
owner: "Your Owner",
repo: "Your Repo",
});
```

Expand All @@ -100,9 +100,9 @@ const GithubRequest = createRequest({
import { BaseModel } from "tiny-crud";

export interface UserModel extends BaseModel {
name: string;
age: number;
gender: string;
name: string;
age: number;
gender: string;
}
```

Expand All @@ -113,9 +113,9 @@ import { GithubRepository } from "tiny-crud";
import { githubRequest } from "./github-request";

export class UserRepository extends GithubRepository<UserModel> {
constructor() {
super(githubRequest, "Your Issue Number");
}
constructor() {
super(githubRequest, "Your Issue Number");
}
}
```

Expand All @@ -126,19 +126,19 @@ const userRepository = new UserRepository();

// create data
userRepository.create({
name: "John",
age: 30,
gender: "male",
name: "John",
age: 30,
gender: "male",
});

// find data
userRepository.find();

// update data
userRepository.updateById(1, {
name: "Mary",
age: 25,
gender: "female",
name: "Mary",
age: 25,
gender: "female",
});

// delete data
Expand All @@ -147,9 +147,9 @@ userRepository.deleteById(1);

## Documentation

- more detailed documentation 👉[TinyCRUD Docs](https://guoxicheng.top/en/projects/TinyCRUD-Docs)
- more detailed documentation 👉[TinyCRUD Docs](https://tinycrud.guoxicheng.top)
- If you find it helpful, please consider giving it a little star, and thank you for your support! 🌟

## License

[MIT](https://github.com/GuoXiCheng/TinyCRUD/blob/main/LICENSE)
[MIT](https://github.com/GuoXiCheng/TinyCRUD/blob/main/LICENSE)
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TinyCRUD 适合用于满足小型团队或个人项目中需要简单、轻量

## 安装

```bash
```bash
npm install tiny-crud

```
Expand All @@ -85,13 +85,13 @@ import axios from "axios";
import { createRequest } from "tiny-crud";

const GithubRequest = createRequest({
httpLib: "axios",
httpClient: axios,
accessToken: "Your Personal Access Token",
httpLib: "axios",
httpClient: axios,
accessToken: "Your Personal Access Token",

platform: "github",
owner: "Your Owner",
repo: "Your Repo",
platform: "github",
owner: "Your Owner",
repo: "Your Repo",
});
```

Expand All @@ -101,9 +101,9 @@ const GithubRequest = createRequest({
import { BaseModel } from "tiny-crud";

export interface UserModel extends BaseModel {
name: string;
age: number;
gender: string;
name: string;
age: number;
gender: string;
}
```

Expand All @@ -114,9 +114,9 @@ import { GithubRepository } from "tiny-crud";
import { githubRequest } from "./github-request";

export class UserRepository extends GithubRepository<UserModel> {
constructor() {
super(githubRequest, "Your Issue Number");
}
constructor() {
super(githubRequest, "Your Issue Number");
}
}
```

Expand All @@ -127,19 +127,19 @@ const userRepository = new UserRepository();

// 创建数据
userRepository.create({
name: "John",
age: 30,
gender: "male",
name: "John",
age: 30,
gender: "male",
});

// 查询数据
userRepository.find();

// 更新数据
userRepository.updateById(1, {
name: "Mary",
age: 25,
gender: "female",
name: "Mary",
age: 25,
gender: "female",
});

// 删除数据
Expand All @@ -148,8 +148,8 @@ userRepository.deleteById(1);

## 详细文档

* 更好的阅读体验以及详细的使用文档请戳 👉[TinyCRUD Docs](https://guoxicheng.top/projects/TinyCRUD-Docs/)
* 如果对你有帮助的话可以给颗小星星,感谢支持!🌟
- 更好的阅读体验以及详细的使用文档请戳 👉[TinyCRUD Docs](https://tinycrud.guoxicheng.top)
- 如果对你有帮助的话可以给颗小星星,感谢支持!🌟

## License

Expand Down
36 changes: 36 additions & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ export default {
text: "应用加密",
link: "/guide/install/encryption"
}]
}, {
text: "开始使用",
items: [{
text: "创建数据模型",
link: "/guide/usage/create-model"
}, {
text: "创建数据存储库",
link: "/guide/usage/create-repository"
}, {
text: "增删改查方法",
link: "/guide/usage/crud"
}]
}, {
text: "贡献指南",
items: [{
text: "构建运行",
link: "/guide/contribute/build"
}]
}
]
}
Expand Down Expand Up @@ -66,6 +84,24 @@ export default {
text: "Encryption",
link: "/en/guide/install/encryption"
}]
}, {
text: "Usage",
items: [{
text: "Create Model",
link: "/en/guide/usage/create-model"
}, {
text: "Create Repository",
link: "/en/guide/usage/create-repository"
}, {
text: "CRUD",
link: "/en/guide/usage/crud"
}]
}, {
text: "Contribute",
items: [{
text: "Build",
link: "/en/guide/contribute/build"
}]
}
]
}
Expand Down
55 changes: 55 additions & 0 deletions docs/en/guide/contribute/build.md
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
```
21 changes: 21 additions & 0 deletions docs/en/guide/usage/create-model.md
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;
}
```
88 changes: 88 additions & 0 deletions docs/en/guide/usage/create-repository.md
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);
}
}
```
Loading

0 comments on commit 86660a8

Please sign in to comment.