Advice: typescript query builder

Đang mở
#5,699 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 5 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
20/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
api

Hướng nghiên cứu

The issue describes a possible TypeScript query-builder client but names no repository files, tests, or entry points. First review PRQL’s type-system specification linked in the issue and the existing client-library structure; the issue asks for advice and adoption criteria rather than defining an implementation or a completion test.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

What's up?

I want to build a query builder in typescript with exceptional, schema-aware type safety. TLDR something like this:

const penguins = prql.table('penguins', {
    "species": "string",
    "year": "int32",
    "bill_length_mm": "float64",
})

const by_year_species = penguins
    .group(
        r => [r.col("species"), r.col("year")],
        g => g
            .filter(r => r.col("bill_length_mm").is_not_null())
            .agg(
                g => ({
                    count: prql.count(),
                    mean_length: g.col("bill_length_mm").mean(),
                })
            )
    )
    .sort(r => r.col("mean_length"))
    .take(10)


const recent_longest_per_year = penguins
    .group(
        r => r.col("year"),
        g => g.sort(r => r.col("bill_length_mm").desc()).take(1)
    )
    .filter(r => r.col("bill_length_mm").gt(50))
    .derive(r => {
       bill_length_cm = r.col("bill_length_mm").div(10), // yuck that we need .div() since typescript doesn't have operator overloading
       version = prql.sql<"string">("version()"),
     })

I am coming from experience maintaining https://github.com/ibis-project/ibis, which is similar to prql in the sense that it is mostly pipelined, but it really suffers from the root limitation that python doesn't have the complex typing system required to track a relations schema through transformations. It also is in python, and I want something that I can use on the web.

I also have used drizzle ORM and zod in some web projects, and I love the type safety they provide, and they demonstrate how much you can leverage advanced typescript features to get exceptional DX.

I started hacking a prototype implementation of the above together, but I was using duckb's json_deserialize_sql() function to compile my IR into SQL. But that was limiting me to duckdb only, and it was requiring a very SQL-like format, where my lib was working with a very pipeline-like format, so it was requiring a lot of complex transformation. Then I thought of PRQL, which is basically exactly the semantics I was looking for in the user-facing API, and it also has the compilation solved! So I want to pivot to using PRQL as the compiler, and while I'm at it align the semantics to be a 1:1 correspondence with PRQL (which I think are awesome semantics!).

A few things I'm looking for:

  • Is there other prior art here that I should be looking at?
  • If I try to actually implement a query builder with the above semantics, what do you think my biggest challenge would be?
  • The above example relies on an explicit type system for all the scalars/columns in the relations. I read https://prql-lang.org/book/reference/spec/type-system.html, which is a great start, but it doesn't look like there was actually any decision made here. Is there something I can use as a spec to map these types 1:1 into typescript? PS, if any of your contributors want to see prior art on this topic, ibis had to solve a very similar problem of presenting a ibis datatype system that can be converted to/from the underlying backend's type sytem.
  • If I do end up going for this, what would you need to see to be interested in adopting this under this repo as an official client library?
Ngôn ngữ chính
Rust
Star
10.9k
Fork
261
Merge trung bình
4 ngày 7 giờ
Pull request đã merge (30 ngày)
77

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PRQL/prql

Tất cả issue của PRQL/prql

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.