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

Deduplicate structure from queries #258

Open
tailhook opened this issue Jun 19, 2023 · 0 comments
Open

Deduplicate structure from queries #258

tailhook opened this issue Jun 19, 2023 · 0 comments

Comments

@tailhook
Copy link
Contributor

The idea is that when one does a query via Rust (or perhaps any other type-safe language), they describe shape twice:

struct User {
  first_name: String,
  last_name: String,
  articles: Vec<Article>,
}
struct Article {
  title: String,
  date: SystemTime,
}

let user: User = cli.query("
  SELECT User {
    first_name,
    last_name,
    articles: {
      title,
      date,
    },
  }
  FILTER .id = <uuid>$0
", (user_id,) 

Since we know the shape of the query from defined structure we can simplify query to:

let user: User = cli.auto_query("SELECT User FILTER .id = <uuid>$0", (user_id,));

Where internally it's transformed into the following query:

WITH inner := (SELECT User FILTER .id = <uuid>$0)
SELECT inner { first_name, last_name, articles: {title, date}}

Since EdgeQL is easily composable, it will work fine if you need a filter on an articles, or a computable:

cli.auto_query("
  SELECT User {
    first_name := get_first_name(.full_name),
    articles := (SELECT .articles FILTER .visible LIMIT 10),
  }
  FILTER .id = <uuid>$0
", (user_id,));

Note:

  1. first_name would better be in-schema computable
  2. Shape on articles still auto-generated (by having it in outer query, we don't need to parse EdgeQL text and inject anything inside).

This might also be integrated to compile-time checks, described in edgedb/edgedb#4276 so that shape and types of values are checked at compile time rather than at run time.

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

No branches or pull requests

1 participant