sunnie to Programmer Humor@programming.dev · 11 months agono.. just noimagemessage-square93fedilinkarrow-up1568arrow-down119
arrow-up1549arrow-down1imageno.. just nosunnie to Programmer Humor@programming.dev · 11 months agomessage-square93fedilink
minus-squareakash_rawal@lemmy.worldlinkfedilinkarrow-up2·edit-211 months agoI was thinking along the lines of Plenty of libraries can build the XML using structs/classes. e.g. with serde: //Data type for row #[derive(serde::Serialize)] pub struct Foo { pub status: String, pub name: String, } //Example row let ent = Foo { status: "paid".into(), name: "bob".into(), } //Example execution sqlx::query(&serde_xml_rs::to_string(&InsertStmt{ table: "foo".into(), value: &ent, })?).execute(&conn)?; Or with jackson-dataformat-xml: //Data type for row public class Foo { public string status; public string name; } //Example row Foo ent = new Foo(); foo.status = "paid"; foo.value = "bob"; //Example execution XmlMapper xmlMapper = new XmlMapper(); String xml = xmlMapper.writeValueAsString(new InsertStmt("foo", ent)); try (Statement stmt = conn.createStatement()) { stmt.executeUpdate(xml) } I don’t do JS (yet) but maybe JSX could also do similar things with XML queries. No more matching $1, $2, … (or ? for mysql) with individual columns, I could dump entire structs/objects into a query and it would work.
I was thinking along the lines of
Plenty of libraries can build the XML using structs/classes. e.g. with serde:
//Data type for row #[derive(serde::Serialize)] pub struct Foo { pub status: String, pub name: String, } //Example row let ent = Foo { status: "paid".into(), name: "bob".into(), } //Example execution sqlx::query(&serde_xml_rs::to_string(&InsertStmt{ table: "foo".into(), value: &ent, })?).execute(&conn)?;
Or with jackson-dataformat-xml:
//Data type for row public class Foo { public string status; public string name; } //Example row Foo ent = new Foo(); foo.status = "paid"; foo.value = "bob"; //Example execution XmlMapper xmlMapper = new XmlMapper(); String xml = xmlMapper.writeValueAsString(new InsertStmt("foo", ent)); try (Statement stmt = conn.createStatement()) { stmt.executeUpdate(xml) }
I don’t do JS (yet) but maybe JSX could also do similar things with XML queries.
No more matching $1, $2, … (or
?
for mysql) with individual columns, I could dump entire structs/objects into a query and it would work.