Created
October 15, 2018 22:53
-
-
Save hoehrmann/c7aab203b2723d3e567dd338558dc62b to your computer and use it in GitHub Desktop.
Poor man's Stored Procedures with SQLite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP VIEW IF EXISTS stored_procedure_do; | |
CREATE VIEW IF NOT EXISTS stored_procedure_do | |
AS SELECT NULL AS json_args LIMIT 1; | |
DROP TABLE IF EXISTS stored_procedure_result; | |
CREATE TABLE IF NOT EXISTS stored_procedure_result( | |
json_result | |
); | |
DROP TRIGGER IF EXISTS stored_procedure_impl; | |
CREATE TRIGGER stored_procedure_impl | |
INSTEAD OF UPDATE ON stored_procedure_do | |
BEGIN | |
DELETE FROM stored_procedure_result; | |
INSERT INTO stored_procedure_result | |
SELECT json_array(key,value) | |
FROM json_each(NEW.json_args); | |
END; | |
UPDATE stored_procedure_do SET json_args = '{"a":3,"z":4}'; | |
SELECT * FROM stored_procedure_result; | |
-- ["a",3] | |
-- ["z",4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment