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

feat(minato): support subquery, fix koishijs/koishi#595 #41

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

Hieuzest
Copy link
Contributor

@Hieuzest Hieuzest commented Sep 25, 2023

This pr is rebased to first-class json type.

ref: koishijs/koishi#595

Features

  • Selection<S>.evaluate<T>(callback: Callback<S, T>): Expr<T>

convert the selection into subquery using ther aggregation callback in type of Expr<T>, therefore it can be used in any place a Expr<T> can fill.

Eg.

assert((await database.select('bar').execute(row => $.count(row.id))) === 6)
const one = database.select('bar').evaluate(row => $.subtract($.count(row.id), 5))
// We can replace all constant integers inside expressions using one
// ...
  • Selection<S>.evaluate<K extends Keys<S>>(field: K): Expr<S[K][]>

Pick the specific field of the selection and aggregate all rows into array

Eg.

database.select('foo')
  .project({
    x: r => database.select('bar').where(row => $.lt(row.uid, r.id)).evaluate('id')
  })
.execute()
// Get id list and store into single field
  • Selection<S>.evaluate(): Expr<S[]>
    shortcut for Selection.evaluate(row => $.array($.object(row)))

Check tests for more usage

Changes

  • Refactor mongo's eval() to make all pipeline processed at server side
  • Use procedures to bypass the field accessing limitation in inner derived tables
  • Refactor memory driver

Tasks

  • mongo
  • mysql8.0/sqlite
  • mysql5.7/mariadb
  • memory
  • non-aggr subquery return list
  • more test for nested subqueries

@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (b15354a) 93.34% compared to head (1d1e9ca) 93.64%.

Files Patch % Lines
packages/memory/src/index.ts 96.29% 1 Missing ⚠️
packages/mongo/src/utils.ts 99.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
+ Coverage   93.34%   93.64%   +0.30%     
==========================================
  Files          28       28              
  Lines        8079     8405     +326     
  Branches     1960     2058      +98     
==========================================
+ Hits         7541     7871     +330     
+ Misses        538      534       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hieuzest Hieuzest marked this pull request as ready for review November 2, 2023 10:40
@Hieuzest Hieuzest marked this pull request as draft December 30, 2023 09:53
@Hieuzest Hieuzest marked this pull request as ready for review January 4, 2024 04:42
- Introduce new Selection.evaluate() to wrap selection into Expr.
- Refactor mongo eval
@shigma shigma changed the title feat: Subquery feat(minato): support subquery, fix koishijs/koishi#595 Feb 2, 2024
@shigma shigma merged commit dcbdf81 into cordiverse:master Feb 2, 2024
26 checks passed
@Hieuzest Hieuzest deleted the dev-upstream branch February 2, 2024 14:32
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.

2 participants