Skip to content

Commit

Permalink
fix: compiler example
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-prisma committed Jan 15, 2025
1 parent 1d35fa4 commit 3413289
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions query-engine/query-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ serial_test = "*"
quaint.workspace = true
indoc.workspace = true
indexmap.workspace = true
sql-query-builder = { path = "../query-builders/sql-query-builder" }

[build-dependencies]
build-utils.path = "../../libs/build-utils"
16 changes: 15 additions & 1 deletion query-engine/query-engine/examples/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use std::sync::Arc;

use quaint::{
prelude::{ConnectionInfo, ExternalConnectionInfo, SqlFamily},
visitor::Postgres,
};
use query_core::{query_graph_builder::QueryGraphBuilder, QueryDocument};
use request_handlers::{JsonBody, JsonSingleQuery, RequestBody};
use serde_json::json;
use sql_query_builder::{Context, SqlQueryBuilder};

pub fn main() -> anyhow::Result<()> {
let schema_string = include_str!("./schema.prisma");
Expand Down Expand Up @@ -66,7 +71,16 @@ pub fn main() -> anyhow::Result<()> {

println!("{graph}");

let expr = query_core::compiler::translate(graph)?;
let connection_info = ConnectionInfo::External(ExternalConnectionInfo::new(
SqlFamily::Postgres,
"public".to_owned(),
None,
));

let ctx = Context::new(&connection_info, None);
let builder = SqlQueryBuilder::<Postgres<'_>>::new(ctx);

let expr = query_core::compiler::translate(graph, &builder)?;

println!("{}", expr.pretty_print(true, 80)?);

Expand Down

0 comments on commit 3413289

Please sign in to comment.