3 ms·
Thank you. I'm using SQLite3 to keep deployment simple, which unfortunately doesn't support stored procedures. Do you have any other suggestions to improve this
by bbkane 4y ago
Thank you. I'm using SQLite3 to keep deployment simple, which unfortunately doesn't support stored procedures. Do you have any other suggestions to improve this code?
- cryptonector 4y agoSQLite3 very much supports something like stored procedures though! Only, instead of calling them that it calls them `INSTEAD OF INSERT` triggers. So, you'd do something like: CREATE VIEW IF NOT EXISTS things AS ...; CREATE TRIGGER IF NOT EXISTS create_thing INSTEAD OF INSERT ON things FOR EACH ROW BEGIN ... END; and to invoke such a "stored procedure" you'd INSERT INTO things (...) VALUES (...), ...; or `INSERT .. SELECT ..;`. Now, with SQLite3 you don't get reflection via SQL, like you do in PG via the `pg_catalog` schema, but you do get reflection via the API. Also, because it's SQLite3, you don't get strong typing, and you get very few types, so even with reflection via the API, generating type-safe stub functions to invoke the "stored procedure" is not exactly easy or possible. FYI, SQLite3 is Turing-complete. You can loop via recursive triggers. And you can do conditionals via `WHERE` clauses on the statements in your trigger bodies (and also via `OR IGNORE` and such). EDIT: I made a post of this: https://news.ycombinator.com/item?id=31913062 https://news.ycombinator.com/item?id=31913062