Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic ORM API #179

Merged
merged 20 commits into from
Mar 23, 2021
Merged

Basic ORM API #179

merged 20 commits into from
Mar 23, 2021

Conversation

shigma
Copy link
Member

@shigma shigma commented Mar 22, 2021

type IndexKeys<O, T = any> = string & { [K in keyof O]: O[K] extends T ? K : never }[keyof O]
type TableIndex<T extends TableType> = IndexKeys<Tables[T], string | number>

interface Database {
  get<T extends TableType, K extends TableIndex<T>, F extends string & keyof Tables[T]>(table: T, key: K, value: Tables[T][K][], fields?: readonly F[]): Promise<Pick<Tables[T], F>[]>
  create<T extends TableType>(table: T, data: Partial<Tables[T]>): Promise<Tables[T]>
  update<T extends TableType>(table: T, data: Partial<Tables[T]>[]): Promise<void>
  remove<T extends TableType, K extends TableIndex<T>>(table: T, key: K, value: Tables[T][K][]): Promise<void>
}

@shigma shigma linked an issue Mar 22, 2021 that may be closed by this pull request
@shigma shigma marked this pull request as ready for review March 22, 2021 19:43
@shigma shigma requested review from undefined-moe and dragon-fish and removed request for undefined-moe March 22, 2021 19:43
@codecov
Copy link

codecov bot commented Mar 22, 2021

Codecov Report

Merging #179 (1d84d6f) into develop (8172dc7) will increase coverage by 0.09%.
The diff coverage is 88.59%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #179      +/-   ##
===========================================
+ Coverage    90.91%   91.01%   +0.09%     
===========================================
  Files           54       56       +2     
  Lines        10200    10445     +245     
  Branches      2011     2073      +62     
===========================================
+ Hits          9273     9506     +233     
- Misses         927      939      +12     
Impacted Files Coverage Δ
packages/plugin-teach/src/update.ts 73.36% <42.85%> (+0.81%) ⬆️
packages/plugin-teach/src/utils.ts 90.04% <45.00%> (-5.14%) ⬇️
packages/plugin-schedule/src/index.ts 95.83% <91.30%> (ø)
packages/koishi-core/src/database.ts 98.62% <100.00%> (+0.09%) ⬆️
packages/koishi-core/src/session.ts 96.11% <100.00%> (+0.86%) ⬆️
packages/koishi-test-utils/src/app.ts 99.03% <100.00%> (-0.97%) ⬇️
packages/koishi-test-utils/src/memory.ts 100.00% <100.00%> (ø)
packages/koishi-utils/src/misc.ts 97.91% <100.00%> (+0.44%) ⬆️
packages/koishi-utils/src/time.ts 100.00% <100.00%> (+6.66%) ⬆️
packages/plugin-schedule/src/database.ts 100.00% <100.00%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8172dc7...1d84d6f. Read the comment docs.

packages/plugin-mongo/src/database.ts Show resolved Hide resolved
packages/plugin-mongo/src/database.ts Show resolved Hide resolved
packages/plugin-mongo/src/index.ts Outdated Show resolved Hide resolved
@lgtm-com

This comment has been minimized.

@lgtm-com

This comment has been minimized.

packages/koishi-core/src/database.ts Outdated Show resolved Hide resolved
packages/plugin-mongo/src/index.ts Show resolved Hide resolved
packages/plugin-mongo/src/database.ts Show resolved Hide resolved
Copy link
Member

@dragon-fish dragon-fish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

作为上游开发,支持这个想法。但是我对于底层并不十分了解,因此暂时不作进一步的评论。

@shigma shigma changed the title [WIP] Basic ORM API Basic ORM API Mar 23, 2021
@shigma shigma merged commit f2e5535 into develop Mar 23, 2021
@shigma shigma deleted the basic-orm branch March 23, 2021 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Basic ORM Support
3 participants