Household planning and management software meant to organise and streamline neurodivergent households.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add squirrel and use it for existing queries

nnuuvv e7f2a205 68ee66a9

+133 -22
+6
mise.toml
··· 22 22 sources = ["sweetnhouse_server/**/*.{gleam,json}", "sweetnhouse_shared/src/**/*.gleam"] 23 23 run = ["gleam build --target erlang"] 24 24 25 + [tasks.update_sql] 26 + description = "Updates sql.gleam files based on *.sql files using squirrel" 27 + dir = "sweetnhouse_server" 28 + run = ["gleam run -m squirrel"] 29 + env = { DATABASE_URL = "postgres://sweetnhome_dev:sweetnhome_dev@localhost:5432/sweetnhome_dev"} 30 + 25 31 [tasks.build_dashboard] 26 32 description = "Build the dashboard static files" 27 33 tools.bun = "latest"
+1
sweetnhouse_server/gleam.toml
··· 25 25 26 26 [dev-dependencies] 27 27 gleeunit = ">= 1.0.0 and < 2.0.0" 28 + squirrel = ">= 4.6.0 and < 5.0.0"
+17
sweetnhouse_server/manifest.toml
··· 2 2 # You typically do not need to edit this file 3 3 4 4 packages = [ 5 + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, 5 6 { name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" }, 6 7 { name = "directories", version = "1.2.0", build_tools = ["gleam"], requirements = ["envoy", "gleam_stdlib", "platform", "simplifile"], otp_app = "directories", source = "hex", outer_checksum = "D13090CFCDF6759B87217E8DDD73A75903A700148A82C1D33799F333E249BF9E" }, 7 8 { name = "dot_env", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "simplifile"], otp_app = "dot_env", source = "hex", outer_checksum = "F2B4815F1B5AF8F20A6EADBB393E715C4C35203EBD5BE8200F766EA83A0B18DE" }, 8 9 { name = "envoy", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "850DA9D29D2E5987735872A2B5C81035146D7FE19EFC486129E44440D03FD832" }, 10 + { name = "eval", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "eval", source = "hex", outer_checksum = "264DAF4B49DF807F303CA4A4E4EBC012070429E40BE384C58FE094C4958F9BDA" }, 9 11 { name = "exception", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "329D269D5C2A314F7364BD2711372B6F2C58FA6F39981572E5CA68624D291F8C" }, 10 12 { name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" }, 13 + { name = "glam", version = "2.0.3", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "237C2CE218A2A0A5D46D625F8EF5B78F964BC91018B78D692B17E1AB84295229" }, 14 + { name = "gleam_community_ansi", version = "1.4.3", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_regexp", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "8A62AE9CC6EA65BEA630D95016D6C07E4F9973565FA3D0DE68DC4200D8E0DD27" }, 15 + { name = "gleam_community_colour", version = "2.0.2", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "E34DD2C896AC3792151EDA939DA435FF3B69922F33415ED3C4406C932FBE9634" }, 11 16 { name = "gleam_crypto", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "50774BAFFF1144E7872814C566C5D653D83A3EBF23ACC3156B757A1B6819086E" }, 12 17 { name = "gleam_erlang", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "1124AD3AA21143E5AF0FC5CF3D9529F6DB8CA03E43A55711B60B6B7B3874375C" }, 13 18 { name = "gleam_http", version = "4.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "82EA6A717C842456188C190AFB372665EA56CE13D8559BF3B1DD9E40F619EE0C" }, 14 19 { name = "gleam_json", version = "3.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "44FDAA8847BE8FC48CA7A1C089706BD54BADCC4C45B237A992EDDF9F2CDB2836" }, 15 20 { name = "gleam_otp", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "BA6A294E295E428EC1562DC1C11EA7530DCB981E8359134BEABC8493B7B2258E" }, 21 + { name = "gleam_regexp", version = "1.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "9C215C6CA84A5B35BB934A9B61A9A306EC743153BE2B0425A0D032E477B062A9" }, 16 22 { name = "gleam_stdlib", version = "0.68.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "F7FAEBD8EF260664E86A46C8DBA23508D1D11BB3BCC6EE1B89B3BC3E5C83FF1E" }, 17 23 { name = "gleam_time", version = "1.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_time", source = "hex", outer_checksum = "0DF3834D20193F0A38D0EB21F0A78D48F2EC276C285969131B86DF8D4EF9E762" }, 18 24 { name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" }, 19 25 { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" }, 26 + { name = "glexer", version = "2.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "splitter"], otp_app = "glexer", source = "hex", outer_checksum = "40A1FB0919FA080AD6C5809B4C7DBA545841CAAC8168FACDFA0B0667C22475CC" }, 20 27 { name = "glisten", version = "8.0.3", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib", "logging", "telemetry"], otp_app = "glisten", source = "hex", outer_checksum = "86B838196592D9EBDE7A1D2369AE3A51E568F7DD2D168706C463C42D17B95312" }, 21 28 { name = "gramps", version = "6.0.0", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gramps", source = "hex", outer_checksum = "8B7195978FBFD30B43DF791A8A272041B81E45D245314D7A41FC57237AA882A0" }, 22 29 { name = "houdini", version = "1.2.0", build_tools = ["gleam"], requirements = [], otp_app = "houdini", source = "hex", outer_checksum = "5DB1053F1AF828049C2B206D4403C18970ABEF5C18671CA3C2D2ED0DD64F6385" }, 23 30 { name = "hpack_erl", version = "0.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "hpack", source = "hex", outer_checksum = "D6137D7079169D8C485C6962DFE261AF5B9EF60FBC557344511C1E65E3D95FB0" }, 31 + { name = "justin", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "7FA0C6DB78640C6DC5FBFD59BF3456009F3F8B485BF6825E97E1EB44E9A1E2CD" }, 24 32 { name = "logging", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "1098FBF10B54B44C2C7FDF0B01C1253CAFACDACABEFB4B0D027803246753E06D" }, 25 33 { name = "marceau", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "2D1C27504BEF45005F5DFB18591F8610FB4BFA91744878210BDC464412EC44E9" }, 26 34 { name = "mist", version = "5.0.4", build_tools = ["gleam"], requirements = ["exception", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "gleam_yielder", "glisten", "gramps", "hpack_erl", "logging"], otp_app = "mist", source = "hex", outer_checksum = "7CED4B2D81FD547ADB093D97B9928B9419A7F58B8562A30A6CC17A252B31AD05" }, 35 + { name = "mug", version = "3.1.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "mug", source = "hex", outer_checksum = "C01279D98E40371DA23461774B63F0E3581B8F1396049D881B0C7EB32799D93F" }, 36 + { name = "non_empty_list", version = "2.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "non_empty_list", source = "hex", outer_checksum = "1CA43D18C07E98E9ED5A60D9CB2FFE0FF40DEFFA45D58A3FF589589F05658F7B" }, 27 37 { name = "opentelemetry_api", version = "1.5.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "F53EC8A1337AE4A487D43AC89DA4BD3A3C99DDF576655D071DEED8B56A2D5DDA" }, 28 38 { name = "pg_types", version = "0.6.0", build_tools = ["rebar3"], requirements = [], otp_app = "pg_types", source = "hex", outer_checksum = "9949A4849DD13408FA249AB7B745E0D2DFDB9532AEE2B9722326E33CD082A778" }, 29 39 { name = "pgo", version = "0.20.0", build_tools = ["rebar3"], requirements = ["backoff", "opentelemetry_api", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "2F11E6649CEB38E569EF56B16BE1D04874AE5B11A02867080A2817CE423C683B" }, 30 40 { name = "platform", version = "1.0.0", build_tools = ["gleam"], requirements = [], otp_app = "platform", source = "hex", outer_checksum = "8339420A95AD89AAC0F82F4C3DB8DD401041742D6C3F46132A8739F6AEB75391" }, 31 41 { name = "pog", version = "4.1.0", build_tools = ["gleam"], requirements = ["exception", "gleam_erlang", "gleam_otp", "gleam_stdlib", "gleam_time", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "E4AFBA39A5FAA2E77291836C9683ADE882E65A06AB28CA7D61AE7A3AD61EBBD5" }, 32 42 { name = "simplifile", version = "2.3.2", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "E049B4DACD4D206D87843BCF4C775A50AE0F50A52031A2FFB40C9ED07D6EC70A" }, 43 + { name = "splitter", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "splitter", source = "hex", outer_checksum = "3DFD6B6C49E61EDAF6F7B27A42054A17CFF6CA2135FF553D0CB61C234D281DD0" }, 44 + { name = "squirrel", version = "4.6.0", build_tools = ["gleam"], requirements = ["argv", "envoy", "eval", "filepath", "glam", "gleam_community_ansi", "gleam_crypto", "gleam_json", "gleam_regexp", "gleam_stdlib", "gleam_time", "glexer", "justin", "mug", "non_empty_list", "pog", "simplifile", "term_size", "tom", "tote", "youid"], otp_app = "squirrel", source = "hex", outer_checksum = "0ED10A868BDD1A5D4B68D99CD1C72DC3F23C6E36E16D33454C5F0C31BAC9CB1E" }, 33 45 { name = "telemetry", version = "1.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "telemetry", source = "hex", outer_checksum = "7015FC8919DBE63764F4B4B87A95B7C0996BD539E0D499BE6EC9D7F3875B79E6" }, 46 + { name = "term_size", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "term_size", source = "hex", outer_checksum = "D00BD2BC8FB3EBB7E6AE076F3F1FF2AC9D5ED1805F004D0896C784D06C6645F1" }, 47 + { name = "tom", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_time"], otp_app = "tom", source = "hex", outer_checksum = "90791DA4AACE637E30081FE77049B8DB850FBC8CACC31515376BCC4E59BE1DD2" }, 48 + { name = "tote", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tote", source = "hex", outer_checksum = "A249892E26A53C668897F8D47845B0007EEE07707A1A03437487F0CD5A452CA5" }, 34 49 { name = "wisp", version = "2.1.1", build_tools = ["gleam"], requirements = ["directories", "exception", "filepath", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_stdlib", "houdini", "logging", "marceau", "mist", "simplifile"], otp_app = "wisp", source = "hex", outer_checksum = "46E2E31DECD61A3748CF6CB317D9AC432BBC8D8A6E65655A9E787BDC69389DE0" }, 50 + { name = "youid", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_stdlib", "gleam_time"], otp_app = "youid", source = "hex", outer_checksum = "580E909FD704DB16416D5CB080618EDC2DA0F1BE4D21B490C0683335E3FFC5AF" }, 35 51 ] 36 52 37 53 [requirements] ··· 42 58 gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 43 59 mist = { version = ">= 2.0.0 and < 6.0.0" } 44 60 pog = { version = ">= 4.1.0 and < 5.0.0" } 61 + squirrel = { version = ">= 4.6.0 and < 5.0.0" } 45 62 wisp = { version = ">= 2.1.1 and < 3.0.0" }
+2 -8
sweetnhouse_server/src/sweetnhouse_server.gleam
··· 6 6 import pog 7 7 import sweetnhouse_server/config 8 8 import sweetnhouse_server/router 9 + import sweetnhouse_server/sql 9 10 import sweetnhouse_server/web 10 11 import wisp 11 12 import wisp/wisp_mist ··· 20 21 { 21 22 let conn = pog.named_connection(ctx.db_pool_name) 22 23 23 - let setup_query = 24 - " 25 - CREATE TABLE IF NOT EXISTS app_config ( 26 - key TEXT PRIMARY KEY, 27 - value TEXT NOT NULL 28 - )" 29 - 30 - case pog.query(setup_query) |> pog.execute(conn) { 24 + case sql.setup_database(conn) { 31 25 Ok(_) -> Nil 32 26 Error(_e) -> { 33 27 panic as "Could not create app_config table."
+4 -14
sweetnhouse_server/src/sweetnhouse_server/config.gleam
··· 1 - import gleam/dynamic/decode 2 1 import pog 2 + import sweetnhouse_server/sql 3 3 import sweetnhouse_server/web 4 4 5 5 /// Retrieve a configuration value by key from the database, ··· 12 12 ) -> #(String, Bool) { 13 13 let conn = pog.named_connection(ctx.db_pool_name) 14 14 15 - case 16 - pog.query("SELECT value FROM app_config WHERE key = $1") 17 - |> pog.parameter(pog.text(key)) 18 - |> pog.returning(decode.at([0], decode.string)) 19 - |> pog.execute(conn) 20 - { 15 + case sql.find_app_config(conn, key) { 21 16 Ok(res) if res.count > 0 -> { 22 17 let z = "Could not retrieve " <> key <> " from database." 23 18 let assert [val, ..] = res.rows as z 24 - #(val, False) 19 + #(val.value, False) 25 20 } 26 - 27 21 _ -> { 28 22 let new_val = default() 29 - let assert Ok(_) = 30 - pog.query("INSERT INTO app_config (key, value) VALUES ($1, $2)") 31 - |> pog.parameter(pog.text(key)) 32 - |> pog.parameter(pog.text(new_val)) 33 - |> pog.execute(conn) 23 + let assert Ok(_) = sql.insert_app_config(conn, key, new_val) 34 24 #(new_val, True) 35 25 } 36 26 }
+89
sweetnhouse_server/src/sweetnhouse_server/sql.gleam
··· 1 + //// This module contains the code to run the sql queries defined in 2 + //// `./src/sweetnhouse_server/sql`. 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 + //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 + //// 6 + 7 + import gleam/dynamic/decode 8 + import pog 9 + 10 + /// A row you get from running the `find_app_config` query 11 + /// defined in `./src/sweetnhouse_server/sql/find_app_config.sql`. 12 + /// 13 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 14 + /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 15 + /// 16 + pub type FindAppConfigRow { 17 + FindAppConfigRow(value: String) 18 + } 19 + 20 + /// Find app_config by key 21 + /// 22 + /// > 🐿️ This function was generated automatically using v4.6.0 of 23 + /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 24 + /// 25 + pub fn find_app_config( 26 + db: pog.Connection, 27 + arg_1: String, 28 + ) -> Result(pog.Returned(FindAppConfigRow), pog.QueryError) { 29 + let decoder = { 30 + use value <- decode.field(0, decode.string) 31 + decode.success(FindAppConfigRow(value:)) 32 + } 33 + 34 + "-- Find app_config by key 35 + SELECT 36 + value 37 + FROM 38 + app_config 39 + WHERE 40 + key = $1 41 + " 42 + |> pog.query 43 + |> pog.parameter(pog.text(arg_1)) 44 + |> pog.returning(decoder) 45 + |> pog.execute(db) 46 + } 47 + 48 + /// Insert new app_config 49 + /// 50 + /// > 🐿️ This function was generated automatically using v4.6.0 of 51 + /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 52 + /// 53 + pub fn insert_app_config( 54 + db: pog.Connection, 55 + arg_1: String, 56 + arg_2: String, 57 + ) -> Result(pog.Returned(Nil), pog.QueryError) { 58 + let decoder = decode.map(decode.dynamic, fn(_) { Nil }) 59 + 60 + "-- Insert new app_config 61 + INSERT INTO app_config (key, value) VALUES ($1, $2) 62 + " 63 + |> pog.query 64 + |> pog.parameter(pog.text(arg_1)) 65 + |> pog.parameter(pog.text(arg_2)) 66 + |> pog.returning(decoder) 67 + |> pog.execute(db) 68 + } 69 + 70 + /// Create app_config table if it doesnt exist yet 71 + /// 72 + /// > 🐿️ This function was generated automatically using v4.6.0 of 73 + /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 74 + /// 75 + pub fn setup_database( 76 + db: pog.Connection, 77 + ) -> Result(pog.Returned(Nil), pog.QueryError) { 78 + let decoder = decode.map(decode.dynamic, fn(_) { Nil }) 79 + 80 + "-- Create app_config table if it doesnt exist yet 81 + CREATE TABLE IF NOT EXISTS app_config ( 82 + key TEXT PRIMARY KEY, 83 + value TEXT NOT NULL 84 + ) 85 + " 86 + |> pog.query 87 + |> pog.returning(decoder) 88 + |> pog.execute(db) 89 + }
+7
sweetnhouse_server/src/sweetnhouse_server/sql/find_app_config.sql
··· 1 + -- Find app_config by key 2 + SELECT 3 + value 4 + FROM 5 + app_config 6 + WHERE 7 + key = $1
+2
sweetnhouse_server/src/sweetnhouse_server/sql/insert_app_config.sql
··· 1 + -- Insert new app_config 2 + INSERT INTO app_config (key, value) VALUES ($1, $2)
+5
sweetnhouse_server/src/sweetnhouse_server/sql/setup_database.sql
··· 1 + -- Create app_config table if it doesnt exist yet 2 + CREATE TABLE IF NOT EXISTS app_config ( 3 + key TEXT PRIMARY KEY, 4 + value TEXT NOT NULL 5 + )