build.rs
 1  use cornucopia::{CodegenSettings, Error};
 2  use postgres::{Client, NoTls};
 3  
 4  fn main() -> Result<(), Error> {
 5      let queries_path = "queries";
 6      let destination = format!("{}/controller-sql.rs", std::env::var("OUT_DIR").unwrap());
 7      let settings = CodegenSettings {
 8          gen_async: true,
 9          derive_ser: false,
10          gen_sync: false,
11          gen_sqlite: true,
12      };
13  
14      println!("cargo:rerun-if-changed={queries_path}");
15      println!("cargo:rerun-if-changed=../arroyo-api/migrations");
16      println!("cargo:rerun-if-changed=../arroyo-api/sqlite_migrations");
17  
18      let mut client = Client::configure()
19          .dbname("arroyo")
20          .host("localhost")
21          .port(5432)
22          .user("arroyo")
23          .password("arroyo")
24          .connect(NoTls)
25          .unwrap_or_else(|_| {
26              panic!("Could not connect to postgres: arroyo:arroyo@localhost:5432/arroyo")
27          });
28  
29      let mut sqlite =
30          rusqlite::Connection::open_in_memory().expect("Couldn't open sqlite memory connection");
31      let migrations = refinery::load_sql_migrations("../arroyo-api/sqlite_migrations").unwrap();
32      refinery::Runner::new(&migrations)
33          .run(&mut sqlite)
34          .expect("Failed to run migrations");
35  
36      cornucopia::generate_live_with_sqlite(
37          &mut client,
38          queries_path,
39          Some(&destination),
40          &sqlite,
41          settings,
42      )?;
43  
44      Ok(())
45  }