Skip to content

Commit 549f15b

Browse files
committed
refine #36
1 parent 47abc5a commit 549f15b

File tree

3 files changed

+8
-50
lines changed

3 files changed

+8
-50
lines changed

migrations.toml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1 @@
1-
# This file is auto-generated by Turbosql.
2-
# It is used to create and apply automatic schema migrations.
3-
# It should be checked into source control.
4-
# Modifying it by hand may be dangerous; see the docs.
51

6-
migrations_append_only = [
7-
"CREATE TABLE person (rowid INTEGER PRIMARY KEY) STRICT",
8-
"ALTER TABLE person ADD COLUMN name TEXT",
9-
"ALTER TABLE person ADD COLUMN age INTEGER",
10-
"ALTER TABLE person ADD COLUMN image_jpg BLOB",
11-
]
12-
output_generated_schema_for_your_information_do_not_edit = """
13-
CREATE TABLE _turbosql_migrations (
14-
rowid INTEGER PRIMARY KEY,
15-
migration TEXT NOT NULL
16-
) STRICT
17-
CREATE TABLE person (
18-
rowid INTEGER PRIMARY KEY,
19-
name TEXT,
20-
age INTEGER,
21-
image_jpg BLOB
22-
) STRICT
23-
"""
24-
25-
[output_generated_tables_do_not_edit.person]
26-
name = "person"
27-
28-
[[output_generated_tables_do_not_edit.person.columns]]
29-
name = "rowid"
30-
rust_type = "Option < i64 >"
31-
sql_type = "INTEGER PRIMARY KEY"
32-
33-
[[output_generated_tables_do_not_edit.person.columns]]
34-
name = "name"
35-
rust_type = "Option < String >"
36-
sql_type = "TEXT"

turbosql-impl/src/delete.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,14 @@ use crate::Table;
55
pub(super) fn delete(table: &Table) -> proc_macro2::TokenStream {
66
let sql = makesql_delete(table);
77
super::validate_sql_or_abort(&sql);
8-
let columns = table.columns.iter().filter(|c| c.name == "rowid").map(|c| {
9-
let ident = &c.ident;
10-
if c.sql_type == "TEXT" && c.rust_type != "Option < String >" {
11-
quote_spanned!(c.span => &::turbosql::serde_json::to_string(&self.#ident)? as &dyn ::turbosql::ToSql)
12-
} else {
13-
quote_spanned!(c.span => &self.#ident as &dyn ::turbosql::ToSql)
14-
}
15-
})
16-
.collect::<Vec<_>>();
17-
188

199
quote_spanned! { table.span =>
2010
fn delete(&self) -> Result<usize, ::turbosql::Error> {
2111
assert!(self.rowid.is_some());
2212
::turbosql::__TURBOSQL_DB.with(|db| {
2313
let db = db.borrow_mut();
2414
let mut stmt = db.prepare_cached(#sql)?;
25-
Ok(stmt.execute(&[#( #columns ),*] as &[&dyn ::turbosql::ToSql])?)
15+
Ok(stmt.execute([self.rowid])?)
2616
})
2717
}
2818
}

turbosql/tests/integration_test.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// cargo test --features test --manifest-path turbosql/Cargo.toml -- --nocapture
1+
// cargo test --features test --manifest-path turbosql/Cargo.toml -- --nocapture --test-threads=1
22

33
#![allow(clippy::bool_assert_comparison, clippy::redundant_clone)]
44

@@ -58,13 +58,16 @@ fn integration_test() {
5858
select!(Vec<String> "field_string FROM personintegrationtest").unwrap(),
5959
vec!["Bob", "Bob"]
6060
);
61-
let mut r = PersonIntegrationTest {
62-
..Default::default()
63-
};
61+
let mut r = PersonIntegrationTest::default();
6462
let id = r.insert().unwrap();
63+
let id2 = r.insert().unwrap();
6564
r.rowid = Some(id);
6665
r.delete().unwrap();
6766
assert!(select!(PersonIntegrationTest "WHERE rowid = ?", id).is_err());
67+
assert!(select!(PersonIntegrationTest "WHERE rowid = ?", id2).is_ok());
68+
r.rowid = Some(id2);
69+
r.delete().unwrap();
70+
assert!(select!(PersonIntegrationTest "WHERE rowid = ?", id2).is_err());
6871
execute!("DELETE FROM personintegrationtest WHERE rowid = 2").unwrap();
6972
assert_eq!(select!(i64 "SELECT 1").unwrap(), 1);
7073
assert_eq!(select!(bool "SELECT 1 > ? AS val", 0).unwrap(), true);

0 commit comments

Comments
 (0)