use roomrs::{DatabaseSpec, Entity, SchemaDef, TableMeta, dao, database, entity};
#[entity(table = "todos")]
struct Todo {
#[pk(autoincrement)]
id: i64,
title: String,
done: bool,
}
#[dao]
trait TodoDao {
#[query("SELECT * FROM todos WHERE id = :id")]
fn find(&self, id: i64) -> roomrs::Result<Option<Todo>>;
}
#[database(entities(Todo), daos(TodoDao), version = 1)]
struct SnapDb;
#[entity(table = "embed_items")]
struct EmbedItemV1 {
#[pk(autoincrement)]
id: i64,
name: String,
}
#[entity(table = "embed_items")]
struct EmbedItemV2 {
#[pk(autoincrement)]
id: i64,
#[column(index)]
name: String,
note: Option<String>,
}
#[entity(table = "gadgets")]
struct GadgetV1 {
#[pk(autoincrement)]
id: i64,
c: String,
}
#[entity(table = "gadgets")]
struct GadgetV2 {
#[pk(autoincrement)]
id: i64,
c: i64,
}
fn snap_of<E: Entity>(version: u32) -> roomrs::SchemaSnapshot {
SchemaDef {
version,
ddl: E::DDL.to_vec(),
tables: vec![TableMeta {
name: E::TABLE,
columns: E::COLUMNS_META,
ddl: E::DDL,
}],
}
.to_snapshot()
}
#[test]
fn ui() {
let dir = tempfile::tempdir().expect("tempdir");
<SnapDb as DatabaseSpec>::schema()
.to_snapshot()
.write_to(&dir.path().join("db.1.json"))
.expect("db 스냅샷 저장");
snap_of::<EmbedItemV1>(1)
.write_to(&dir.path().join("embed_db.1.json"))
.expect("embed v1 저장");
snap_of::<EmbedItemV2>(2)
.write_to(&dir.path().join("embed_db.2.json"))
.expect("embed v2 저장");
snap_of::<GadgetV1>(1)
.write_to(&dir.path().join("gadget_db.1.json"))
.expect("gadget v1 저장");
snap_of::<GadgetV2>(2)
.write_to(&dir.path().join("gadget_db.2.json"))
.expect("gadget v2 저장");
#[allow(unsafe_code)]
unsafe {
std::env::set_var("ROOMRS_SCHEMA_DIR", dir.path());
}
let t = trybuild::TestCases::new();
t.pass("tests/ui/pass/attr_names.rs");
t.pass("tests/ui/pass/schema_ok.rs");
t.pass("tests/ui/pass/schema_stale_runtime.rs");
t.pass("tests/ui/pass/schema_embed.rs");
t.pass("tests/ui/pass/schema_embed_destructive.rs");
t.pass("tests/ui/pass/live_union_cte_deps.rs");
t.pass("tests/ui/pass/insert_default_values.rs");
t.pass("tests/ui/pass/dao_write_returning.rs");
t.compile_fail("tests/ui/fail/param_missing_arg.rs");
t.compile_fail("tests/ui/fail/param_unused_arg.rs");
t.compile_fail("tests/ui/fail/schema_bad_table.rs");
t.compile_fail("tests/ui/fail/schema_bad_column.rs");
t.compile_fail("tests/ui/fail/entity_duplicate_pk.rs");
t.compile_fail("tests/ui/fail/entity_tuple_struct.rs");
t.compile_fail("tests/ui/fail/entity_duplicate_column.rs");
t.compile_fail("tests/ui/fail/entity_default_nan.rs");
t.compile_fail("tests/ui/fail/dao_two_sql_attrs.rs");
t.compile_fail("tests/ui/fail/dao_insert_bad_sig.rs");
t.compile_fail("tests/ui/fail/dao_non_result_return.rs");
t.compile_fail("tests/ui/fail/dao_missing_sql_attr.rs");
t.compile_fail("tests/ui/fail/dao_self_in_macro.rs");
t.compile_fail("tests/ui/fail/dao_query_select_u64.rs");
t.compile_fail("tests/ui/fail/dao_insert_ignore_rowid.rs");
t.compile_fail("tests/ui/fail/dao_update_without_returning.rs");
t.compile_fail("tests/ui/fail/dao_delete_without_returning.rs");
t.compile_fail("tests/ui/fail/dao_missing_receiver.rs");
t.compile_fail("tests/ui/fail/dao_result_live_query.rs");
t.compile_fail("tests/ui/fail/dao_result_unit.rs");
t.compile_fail("tests/ui/fail/relation_bad_key_ident.rs");
t.compile_fail("tests/ui/fail/database_version_zero.rs");
t.compile_fail("tests/ui/fail/database_no_entities.rs");
t.compile_fail("tests/ui/fail/entity_quoted_identifier.rs");
t.compile_fail("tests/ui/fail/relation_conflicting_attrs.rs");
t.compile_fail("tests/ui/fail/relation_quoted_identifier.rs");
t.compile_fail("tests/ui/fail/database_duplicate_entity.rs");
t.compile_fail("tests/ui/fail/dao_unsupported_parameter.rs");
}