programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

akash_rawal, in no.. just no

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.

Sanchokan, (edited ) in The Holy Trinity of JavaScript

A few years back I came to the conclusion that the holy trinity in Christianity are three levels of abstraction: the son => God walks on earth and tangible, the father => God in heaven untangible but still reachable by speech, holy spirit => God in who knows where.

Then I thought that as a way of imparting the thought that any level of abstraction of the universe would also be inhabitated by God, those which we can sense, and those where our senses can't reach. The idea that omniprescense is not only limited to our dimension.

I'm not sure if that is the original meaning but is a way of seeing it that I can relate to, since I've always been akeen to a more abstract idea of God, and not so much to a figure that praises itself of thought, which is a human attribute.

yannic,
CanadaPlus,

As far as I can tell, the doctrine of the trinity served political rather than logical purposes back when it was put in writing in late antiquity, and since then it’s just been the doctrine. If you want to believe, you just have to believe and not think about it too hard, like the video says.

normalexit, in no.. just no

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.

mvirts, in no.. just no

Remember kids, JSX is just function calls. It can’t hurt you.

Thcdenton,

Oh it can and it did.

mlg, in no.. just no
@mlg@lemmy.world avatar

“HTTP and the Web is a totally reliable and easy to use internet protocol”

expr, in no.. just no

Not only is this really gross, it’s also straight up wrong. It’s missing a from clause, and it makes no sense for a where clause to be nested under the select. The select list selects columns from rows that have already been filtered by the where clause. Same for the limit.

Also just gonna go ahead and assume the JSX parser will happily allow SQL injection attacks…

nephs,

Booooo

CanadaPlus,

I like the format, though.

ReluctantMuskrat,

Clearly you’ve not had to write and maintain much XML.

CanadaPlus,

I have not. I just thought it looks less goofy than a nested SQL statement split over multiple lines.

What are the issues with XML?

adhocfungus, in no.. just no
gravitas_deficiency, in no.. just no

I want to hate this. I really do. But the problem is… I think I like it.

lorty,
@lorty@lemmygrad.ml avatar

This needs a bit of work but it could be interesting

naonintendois,

But how do I know if the WHERE clause is AND or OR?

gravitas_deficiency, (edited )

Fair. The constraint nodes should probably exist under an And or Or node.

akash_rawal,

We can say default is and and add an Or node for or. Similar to SoP notation, you only write +.

victorz,

How about an or boolean attribute.

uid0gid0, in The Holy Trinity of JavaScript

Violating the transitive property? Go home JavaScript, you’re drunk.

Thcdenton, in The Holy Trinity of JavaScript

Fuck this language with a pineapple

Thcdenton, in no.. just no
mindbleach, in The Holy Trinity of JavaScript

“The trinity makes as much sense as Javascript” is a vulgar condemnation of Christian dogma.

leftzero, in no.. just no

Of course not… where’s the damn <From> tag…?

cupcakezealot, in no.. just no
@cupcakezealot@lemmy.blahaj.zone avatar

please kindly send all javascript into the sun and explode it

db2,

That’s XML though… not that I’m disagreeing.

huginn,

Not XML. JSX. It’s javascript’s answer to markup.

db2,

Gross.

dukk,

The worst of both worlds…

karmiclychee,

It’s like a weaponized grade of whatever they made CSS in JS out of

dan,
@dan@upvote.au avatar

deleted_by_author

  • Loading...
  • huginn,

    If you put it into an XML parser it will throw an error, so it’s no longer XML.

    Sure it was based on it, but it’s not xml.

    namelivia, (edited ) in no.. just no

    When you are assigned to write database queries at work and your academical background is that online react bootcamp

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programmer_humor@programming.dev
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #