Skip to content

Commit

Permalink
Merge pull request #89 from GuoXiCheng/dev-h
Browse files Browse the repository at this point in the history
Dev h
  • Loading branch information
GuoXiCheng authored Jan 22, 2024
2 parents 4324a5e + 17bdc73 commit d90a0f4
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 2 deletions.
147 changes: 147 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,152 @@
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/GuoXiCheng/TinyCRUD/ci.yml)
![Codecov branch](https://img.shields.io/codecov/c/github/GuoXiCheng/TinyCRUD/main)

## 介绍

TinyCRUD 是一个基于代码托管平台 Issue API 的轻量级数据存储库,它可以将 Issue 作为数据库表,Issue 的评论作为数据表记录,通过 Issue API 将数据序列化/反序列化,实现数据的增删改查。

## 适用场景

TinyCRUD 适合用于满足小型团队或个人项目中需要简单、轻量级数据存储,但又不想或不需要设置复杂数据库系统的情况。

## 支持的代码托管平台

<table>
<tr>
<td>
<p align="center">
<img src="https://guoxicheng.top/assets/image/tiny-crud-docs/github.svg" title="Github"/>
</p>
</td>
<td>
<p align="center">
<img src="https://guoxicheng.top/assets/image/tiny-crud-docs/gitlab.svg" title="Gitlab"/>
</p>
</td>
<td>
<p align="center">
<img src="https://guoxicheng.top/assets/image/tiny-crud-docs/gitee.svg" title="Gitee"/>
</p>
</td>
</tr>
<tr>
<td>
API latest ✔
</td>
<td>
API v4 ✔
</td>
<td>
API v5 ✔
</td>
</tr>
</table>

## 支持的请求库

<table>
<tr>
<td>
<img src="https://axios-http.com/assets/logo.svg" />
</td>
<td>
<p align="center">
<img src="https://guoxicheng.top/assets/image/tiny-crud-docs/wechat.svg" />
</p>
</td>
</tr>
<tr>
<td>
<p align="center">axios ✔</p>
</td>
<td>
wx(微信小程序) ✔
</td>
</tr>
</table>

## 安装

```bash
npm install tiny-crud

```

## 使用

### 创建请求

```ts
import axios from "axios";
import { createRequest } from "tiny-crud";

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

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

### 创建数据模型

```ts
import { BaseModel } from "tiny-crud";

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

### 创建数据存储库

```ts
import { GithubRepository } from "tiny-crud";
import { githubRequest } from "./github-request";

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

### 基本操作

```ts
const userRepository = new UserRepository();

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

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

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

// 删除数据
userRepository.deleteById(1);
```

## 说明

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

## License

[MIT](https://github.com/GuoXiCheng/TinyCRUD/blob/main/LICENSE)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiny-crud",
"version": "1.0.24",
"version": "1.1.0",
"description": "A tiny CRUD library based on Git Issue API",
"main": "dist/bundle.cjs.js",
"module": "dist/bundle.esm.js",
Expand Down
4 changes: 4 additions & 0 deletions src/repository-lib/gitee/gitee-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class GiteeRepository<T extends BaseModel> extends BaseRepository<T> {
/**
* Finds items in the Gitee repository.
* @param params - Optional parameters for the search.
* @param params.since - Only issues updated at or after this time are returned.
* @param params.page - The page number to retrieve.
* @param params.per_page - The number of items to retrieve per page.default: 20, maximum: 100
* @param params.order - The sort order of the results.Either 'asc' or 'desc'.
* @returns A promise that resolves to an array of items.
*/
async find(params?: GiteeParams): Promise<T[]> {
Expand Down
3 changes: 3 additions & 0 deletions src/repository-lib/github/github-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class GithubRepository<T extends BaseModel> extends BaseRepository<T> {
/**
* Finds items in the GitHub repository.
* @param params - Optional parameters for the search.
* @param params.since - Only issues updated at or after this time are returned.
* @param params.page - The page number to retrieve.
* @param params.per_page - The number of items to retrieve per page.default: 30, maximum: 100
* @returns A promise that resolves to an array of items.
*/
async find(params?: GithubParams): Promise<T[]> {
Expand Down
4 changes: 3 additions & 1 deletion src/repository-lib/gitlab/gitlab-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export class GitlabRepository<T extends BaseModel> extends BaseRepository<T> {
/**
* Finds items in the Gitlab storage based on the provided parameters.
* @param params - Optional parameters for the find operation.
* @returns A promise that resolves to an array of items found in the Gitlab storage.
* @param params.sort - Return requests sorted in asc or desc order. Default is desc.
* @param params.order_by - Return requests ordered by created_at or updated_at fields. Default is created_at.
* @returns A promise that resolves to an array of items.
*/
async find(params?: GitlabParams): Promise<T[]> {
const url = this.getRoute(RouteType.find);
Expand Down

0 comments on commit d90a0f4

Please sign in to comment.