Raw Transact
Raw Transact
Molecule transactions are translated to prepared statements for SQL databases (with input placeholders).
inspect
Inspect a query molecule without returning data by adding inspect after <action>:
Person.name("Bob").age(42)
.Home.street("DoobieSetup2 st. 1")
.save.inspect // (returns Unit)This will print the MetaModel of the molecule and for SQL, the produced prepared statements for each table:
========================================
SAVE:
AttrOneManString("Person", "name", Eq, Seq("Bob"), None, None, Nil, Nil, None, None, Seq(0, 1))
AttrOneManInt("Person", "age", Eq, Seq(42), None, None, Nil, Nil, None, None, Seq(0, 4))
Ref("Person", "home", "Address", CardOne, false, Seq(0, 6, 1))
AttrOneManString("Address", "street", Eq, Seq("DoobieSetup2 st. 1"), None, None, Nil, Nil, None, None, Seq(1, 12))
Save(
Ns(
RefOne(
INSERT INTO Address (
street
) VALUES (?)
)
---------------------------
INSERT INTO Person (
name,
age,
home
) VALUES (?, ?, ?)
)
)
----------------------------------------i
When working on molecules we might want to do a quick check of the prepared statements produced without having to change our code. Then we can simply add i (for "inspect") to transact and apart from transacting the data also print the same info as shown above.
Person.name("Bob").age(42)
.Home.street("DoobieSetup2 st. 1")
.save.i.transact // adding `i` to also inspectrawTransact
For SQL databases we could insert raw data with an insert:
rawTransact(
"""INSERT INTO Person (
| name,
| age
|) VALUES ('Bob', 42)""".stripMargin
)We can confirm if the data has been inserted:
Person.name.age.query.get ==> List(
("Bob", 42),
)Likewise, we could update or delete raw data using raw transaction strings for the selected database.
See also raw query.
