no.. just no

mlg, ![]()
“HTTP and the Web is a totally reliable and easy to use internet protocol”
mvirts, Remember kids, JSX is just function calls. It can’t hurt you.
Thcdenton, Oh it can and it did.
normalexit, This idea is bad and whoever came up with it should feel bad.
III, It never ceases to amaze me how far idiots will go to avoid learning the most simple things. SQL isn’t hard, people’s difficulty with it says a lot more about them than it does SQL.
emptyother, People think in different ways. What might seem logical to you might look alien to another. I know SQL well enough to optimize queries, but I find it a lot easier to think about and write queries as LINQ methods. A lot more cleaner and logical to my brain.
MonkderZweite, Neither is sending form data to the server without any JS. It’s more robust too. Yet almost no form on the web works without JS.
akash_rawal, I actually like this. This would allow reuse of all the infrastructure we have around XML. No more SQL injection and dealing with query parameters? Sign me up!
CanadaPlus, Assuming it’s built well. As someone else pointed out, it doesn’t look quite right here.
utopianfiat, So you mean like parameterized queries, which exist?
akash_rawal, Better than parameterized queries. Yes, we have stuff like
query(“INSERT INTO table(status, name) VALUES ($1, $2);”).bind(ent.status).bind(ent.name).execute…
, but that’s kind of awful isn’t it? With XML queries, we could use any of the XML libraries we have to create and manipulate XML queries without risking ‘XML injection’. e.g we could convert ordinary structs/classes into column values automatically without having to use any ORM.
docAvid, (edited ) I mean, that’s just a bad library interface. With a halfway decent interface, you can do something like
<span style="color:#323232;">query('insert into foo (status, name) values (:status, :name)', ent) </span>
No orm required. With tagged templates in JS, you can do
<span style="color:#323232;">q`insert into foo (status, name) values (${ent.status}, ${ent.name})` </span>
Even wrap it in a function with destructuring to get rid of
ent
:<span style="color:#323232;">const addFoo = (q, {status, name}) => </span><span style="color:#323232;"> q`insert into foo (status, name) values (${status}, ${name})` </span>
Typescript can add type safety on top of that, of course. And there’s the option to prepare a query once and execute it multiple times.
Honestly, the idea of manipulating XML queries, if you mean anything more fancy than the equivalent of parameter injection, sounds over-complicated, but I’d love to see a more concrete example of what you mean by that.
akash_rawal, (edited ) I was thinking along the lines of
https://lemmy.world/pictrs/image/4ef7f59c-88c7-4cfa-8dd5-91c71d8ad801.jpeg
Plenty of libraries can build the XML using structs/classes. e.g. with serde:
<span style="font-style:italic;color:#969896;">//Data type for row </span><span style="color:#323232;">#[derive(serde::Serialize)] </span><span style="font-weight:bold;color:#a71d5d;">pub struct </span><span style="color:#323232;">Foo { </span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">pub </span><span style="color:#323232;">status: String, </span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">pub </span><span style="color:#323232;">name: String, </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;">//Example row </span><span style="font-weight:bold;color:#a71d5d;">let</span><span style="color:#323232;"> ent </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> Foo { </span><span style="color:#323232;"> status: </span><span style="color:#183691;">"paid"</span><span style="color:#323232;">.</span><span style="color:#62a35c;">into</span><span style="color:#323232;">(), </span><span style="color:#323232;"> name: </span><span style="color:#183691;">"bob"</span><span style="color:#323232;">.</span><span style="color:#62a35c;">into</span><span style="color:#323232;">(), </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;">//Example execution </span><span style="color:#323232;">sqlx::query(</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;serde_xml_rs::to_string(</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;InsertStmt{ </span><span style="color:#323232;"> table: </span><span style="color:#183691;">"foo"</span><span style="color:#323232;">.</span><span style="color:#62a35c;">into</span><span style="color:#323232;">(), </span><span style="color:#323232;"> value: </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;ent, </span><span style="color:#323232;">})</span><span style="font-weight:bold;color:#a71d5d;">?</span><span style="color:#323232;">).</span><span style="color:#62a35c;">execute</span><span style="color:#323232;">(</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp;conn)</span><span style="font-weight:bold;color:#a71d5d;">?</span><span style="color:#323232;">; </span>
Or with jackson-dataformat-xml:
<span style="font-style:italic;color:#969896;">//Data type for row </span><span style="font-weight:bold;color:#a71d5d;">public class </span><span style="color:#0086b3;">Foo </span><span style="color:#323232;">{ </span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">public</span><span style="color:#323232;"> string status; </span><span style="color:#323232;"> </span><span style="font-weight:bold;color:#a71d5d;">public</span><span style="color:#323232;"> string name; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;">//Example row </span><span style="color:#0086b3;">Foo</span><span style="color:#323232;"> ent </span><span style="font-weight:bold;color:#a71d5d;">= new </span><span style="color:#0086b3;">Foo</span><span style="color:#323232;">(); </span><span style="color:#323232;">foo.status </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#183691;">"paid"</span><span style="color:#323232;">; </span><span style="color:#323232;">foo.value </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#183691;">"bob"</span><span style="color:#323232;">; </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;">//Example execution </span><span style="color:#0086b3;">XmlMapper</span><span style="color:#323232;"> xmlMapper </span><span style="font-weight:bold;color:#a71d5d;">= new </span><span style="color:#0086b3;">XmlMapper</span><span style="color:#323232;">(); </span><span style="color:#0086b3;">String</span><span style="color:#323232;"> xml </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> xmlMapper.writeValueAsString(</span><span style="font-weight:bold;color:#a71d5d;">new </span><span style="color:#0086b3;">InsertStmt</span><span style="color:#323232;">(</span><span style="color:#183691;">"foo"</span><span style="color:#323232;">, ent)); </span><span style="font-weight:bold;color:#a71d5d;">try </span><span style="color:#323232;">(</span><span style="color:#0086b3;">Statement</span><span style="color:#323232;"> stmt </span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#323232;"> conn.createStatement()) { </span><span style="color:#323232;"> stmt.executeUpdate(xml) </span><span style="color:#323232;">} </span>
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.
dylanTheDeveloper, ![]()
Omg that’s terrible! Link?
httpjames, ![]()
Joins must be a pain in the ass with hooks
RagingRobot, It’s kind of like graphQl you could make a compiler that would work with this.
utopianfiat, but why
SaltyIceteaMaker, ![]()
got no clue abot sql. what is wrong and how is it supposed to look like?
schnurrito, SQL is supposed to look like this: SELECT status, name FROM some_table LIMIT 5
ILikeBoobies, (edited ) Different language
Daxtron2, this basically xml being made to look like SQL. It’s gross and that’s why it’s funny
traches, SQL is run on the server to communicate with a database. The screenshot is jsx, which is a front-end, UI templating language. Writing SQL this way is cursed
SirQuackTheDuck, It could be querying the in-browser database (that’s commonly used, such as with WhatsApp web), which would be seeded by a different part of the application
utopianfiat, Except that’s still a SQL dialect, not JSX. There’s no need to make this JSX.
BoastfulDaedra, I haven’t been this pissed off since LINQ started allowing syntax switches in random-ass places.
Reptorian, I kind of like it. I can understand where it start and end.
NigelFrobisher, Needs JSON embedded in the elements because JSON is best practice.
Add comment