4 ms·
Is there something like YeSQL for Go?
by learc83 12y ago
Is there something like YeSQL for Go?
- elithrar 12y agoNot that I've seen, but I've love to see it. You could probably build it with something like text/template and write: SELECT id, title, expiry_date FROM posts WHERE id = {{ id }} AND expiry_date > {{ date }} ORDER BY expiry_date This would give you some flexibility--the template tags would be replaced by ? or $1 or :name depending on the database driver set on parse--and leans on the stdlib. This would tie in nicely with https://github.com/jmoiron/sqlx https://github.com/jmoiron/sqlx and its struct tag/marshaling behaviour. Access could be handled by a map[string]string, with the key as the filename and the value as the SQL (as a first thought).
- NDizzle 12y agoForgive my ignorance as I'm not very familiar with golang, but what you're describing above looks (to me) like a parameterized query. Nothing real fancy about that. I'd assume that Go has support for parameterized queries already.
- cmelbye 12y agogetUser, _ := db.Prepare("select * from users where username=$1 limit 1") row := getUser.QueryRow("john")