←back to thread

620 points tambourine_man | 1 comments | | HN request time: 0.221s | source
Show context
TekMol ◴[] No.43749608[source]
Will this allow neat SQL syntax like the following?

    city = 'London'
    min_age = 21
    # Find all users in London who are 21 or older:
    users = db.get(t'
        SELECT * FROM users
        WHERE city={city} AND age>{min_age}
    ')
If the db.get() function accepts a template, it should, right?

This would be the nicest way to use SQL I have seen yet.

replies(8): >>43749674 #>>43749734 #>>43749906 #>>43749926 #>>43749979 #>>43750037 #>>43751845 #>>43756963 #
fweimer ◴[] No.43749734[source]
The SQLite extension for Tcl offers something similar:

    db1 eval {INSERT INTO t1 VALUES(5,$bigstring)} 
https://sqlite.org/tclsqlite.html#the_eval_method
replies(1): >>43753345 #
1. wizzwizz4 ◴[] No.43753345[source]
As I understand, that's less powerful, because you can do:

    t"INSERT INTO mytable VALUES ({s}, {s[::-1]})"
but you can't do:

    mydb eval {INSERT INTO mytable VALUES ($s, [string reverse $s])}
Instead, you have to write:

    set t [string reverse $s]
    mydb eval {INSERT INTO mytable VALUES ($s, $t)}
There's no reason you couldn't have such power in Tcl, though: it's just that the authors of SQLite didn't.