Skip to content

Commit 5e6990f

Browse files
committed
feat: migrate update to overwrite and introduce new update as patch
usage
1 parent afc371b commit 5e6990f

File tree

6 files changed

+323
-24
lines changed

6 files changed

+323
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Generated files are automatically formatted with `rustfmt`. The Rust edition is
190190
| `--db-kind` | `-d` | Database kind: `postgres`, `mysql`, `sqlite` | required |
191191
| `--entities-module` | `-e` | Rust module path (e.g. `crate::models::users`). Auto-detected from file path if omitted. | auto |
192192
| `--output-dir` | `-o` | Output directory | `src/crud` |
193-
| `--methods` | `-m` | Methods to generate (comma-separated): `*`, `get_all`, `paginate`, `get`, `insert`, `update`, `delete` | required |
193+
| `--methods` | `-m` | Methods to generate (comma-separated): `*`, `get_all`, `paginate`, `get`, `insert`, `update`, `overwrite`, `delete` | required |
194194
| `--query-macro` | `-q` | Use `sqlx::query_as!()` macros (compile-time checked) | `false` |
195195
| `--pool-visibility` | `-p` | Visibility of the `pool` field: `private`, `pub`, `pub(crate)` | `private` |
196196
| `--dry-run` | `-n` | Print to stdout, don't write files | `false` |

crates/sqlx_gen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-gen"
3-
version = "0.4.9"
3+
version = "0.5.0"
44
edition = "2021"
55
description = "Generate Rust structs from database schema introspection"
66
license = "MIT"

crates/sqlx_gen/src/cli.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,11 @@ pub struct Methods {
263263
pub get: bool,
264264
pub insert: bool,
265265
pub update: bool,
266+
pub overwrite: bool,
266267
pub delete: bool,
267268
}
268269

269-
const ALL_METHODS: &[&str] = &["get_all", "paginate", "get", "insert", "update", "delete"];
270+
const ALL_METHODS: &[&str] = &["get_all", "paginate", "get", "insert", "update", "overwrite", "delete"];
270271

271272
impl Methods {
272273
/// Parse a list of method names. `"*"` enables all methods.
@@ -280,6 +281,7 @@ impl Methods {
280281
"get" => m.get = true,
281282
"insert" => m.insert = true,
282283
"update" => m.update = true,
284+
"overwrite" => m.overwrite = true,
283285
"delete" => m.delete = true,
284286
other => {
285287
return Err(format!(
@@ -300,6 +302,7 @@ impl Methods {
300302
get: true,
301303
insert: true,
302304
update: true,
305+
overwrite: true,
303306
delete: true,
304307
}
305308
}
@@ -490,6 +493,7 @@ mod tests {
490493
assert!(!m.get);
491494
assert!(!m.insert);
492495
assert!(!m.update);
496+
assert!(!m.overwrite);
493497
assert!(!m.delete);
494498
}
495499

@@ -501,6 +505,7 @@ mod tests {
501505
assert!(m.get);
502506
assert!(m.insert);
503507
assert!(m.update);
508+
assert!(m.overwrite);
504509
assert!(m.delete);
505510
}
506511

@@ -536,9 +541,24 @@ mod tests {
536541
assert!(m.get);
537542
assert!(m.insert);
538543
assert!(m.update);
544+
assert!(m.overwrite);
539545
assert!(m.delete);
540546
}
541547

548+
#[test]
549+
fn test_parse_overwrite_method() {
550+
let m = Methods::from_list(&["overwrite".to_string()]).unwrap();
551+
assert!(m.overwrite);
552+
assert!(!m.update);
553+
assert!(!m.get);
554+
}
555+
556+
#[test]
557+
fn test_wildcard_includes_overwrite() {
558+
let m = Methods::from_list(&["*".to_string()]).unwrap();
559+
assert!(m.overwrite);
560+
}
561+
542562
// ========== module_path_from_file ==========
543563

544564
#[test]

0 commit comments

Comments
 (0)