{"id":25953587,"url":"https://github.com/ruby0b/sqlite-simple-interpolate","last_synced_at":"2025-07-01T03:06:53.955Z","repository":{"id":62436417,"uuid":"496007590","full_name":"ruby0b/sqlite-simple-interpolate","owner":"ruby0b","description":"Safe interpolated SQLite queries in Haskell","archived":false,"fork":false,"pushed_at":"2023-01-13T02:28:23.000Z","size":37,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-11T20:49:15.981Z","etag":null,"topics":["database","haskell","sqlite","string-interpolation"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/sqlite-simple-interpolate","language":"Haskell","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby0b.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-24T22:33:42.000Z","updated_at":"2023-01-13T02:44:21.000Z","dependencies_parsed_at":"2023-02-09T14:16:19.909Z","dependency_job_id":null,"html_url":"https://github.com/ruby0b/sqlite-simple-interpolate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ruby0b/sqlite-simple-interpolate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby0b%2Fsqlite-simple-interpolate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby0b%2Fsqlite-simple-interpolate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby0b%2Fsqlite-simple-interpolate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby0b%2Fsqlite-simple-interpolate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby0b","download_url":"https://codeload.github.com/ruby0b/sqlite-simple-interpolate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby0b%2Fsqlite-simple-interpolate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259860230,"owners_count":22922979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","haskell","sqlite","string-interpolation"],"created_at":"2025-03-04T15:29:16.873Z","updated_at":"2025-07-01T03:06:53.909Z","avatar_url":"https://github.com/ruby0b.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003esqlite-simple-interpolate\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://hackage.haskell.org/package/sqlite-simple-interpolate\"\u003e\u003cimg src=\"https://img.shields.io/hackage/v/sqlite-simple-interpolate\" alt=\"Hackage\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ruby0b/sqlite-simple-interpolate/actions/workflows/haskell-ci.yml\"\u003e\u003cimg src=\"https://github.com/ruby0b/sqlite-simple-interpolate/actions/workflows/haskell-ci.yml/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/simmsb/calamity/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/ruby0b/sqlite-simple-interpolate\" alt=\"License\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://hackage.haskell.org/package/sqlite-simple-interpolate\"\u003e\u003cimg src=\"https://img.shields.io/hackage-deps/v/sqlite-simple-interpolate\" alt=\"Hackage-Deps\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nWrite natural SQL statements in Haskell using QuasiQuoters!\n\nThe QuasiQuoters support 3 methods of interpolation that can be mixed freely:\n\n- `{}`: injection-safe field interpolation, e.g. `{myName}` gets replaced with `?` which gets substituted with `toField myName`.\n- `@{}`: injection-safe row interpolation, e.g. `@{myPerson}` gets replaced with `(?,?)` (assuming `Person` has two fields) which gets substituted with `toRow myPerson`.\n- `!{}`: injection-_vulnerable_ raw string interpolation. **Never use this for user input!** Intended for use cases that the anti-injection mechanisms won't allow, e.g. table names: `!{myTableName}` gets replaced with the value of `myTableName :: String`.\n\n```haskell\n{-# LANGUAGE QuasiQuotes #-}\n\nmodule Main where\n\nimport Control.Exception (bracket)\nimport Data.Char (toLower)\nimport Data.Function ((\u0026))\nimport qualified Database.SQLite.Simple as SQL\nimport Database.SQLite.Simple.Interpolate\n\ndata Person = Person {name :: String, age :: Integer}\n\ninstance SQL.ToRow Person where\n  toRow p = SQL.toRow (name p, age p)\n\ntable :: String\ntable = \"people\"\n\nmain :: IO ()\nmain = bracket (SQL.open \":memory:\") SQL.close $ \\conn -\u003e do\n  -- Create a table, interpolating safe string constants like table names with !{}\n  conn \u0026 [iexecute|CREATE TABLE !{table} (name TEXT, age INTEGER)|]\n\n  -- Insert a person, safely interpolating a field using {}\n  let name = \"clive\"\n  conn \u0026 [iexecute|INSERT INTO !{table} VALUES ({name}, 40)|]\n\n  -- Insert a person, safely interpolating an entire row type using @{} (gets replaced with \"(?,?)\")\n  let clara = Person {name = \"clara\", age = 25}\n  conn \u0026 [iexecute|INSERT INTO !{table} VALUES @{clara}|]\n\n  -- Use ifold to fold some rows into their sum in haskell\n  ageHaskellSum \u003c- conn \u0026 [ifold|SELECT age FROM !{table}|] 0 (\\acc (SQL.Only x) -\u003e pure (acc + x))\n  print (ageHaskellSum :: Int)\n\n  -- Let's calculate the average age of people that are at least 20 years old\n  let minAge = 20 :: Int\n  [ageAvg] \u003c- conn \u0026 [iquery|SELECT AVG(age) FROM !{table} WHERE age \u003e= {minAge}|]\n  print (ageAvg :: SQL.Only Double)\n\n  -- You can always use 'isql' directly but you'll have to use uncurry:\n  (uncurry $ SQL.execute conn) [isql|INSERT OR REPLACE INTO !{table} VALUES ({name}, 41)|]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby0b%2Fsqlite-simple-interpolate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby0b%2Fsqlite-simple-interpolate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby0b%2Fsqlite-simple-interpolate/lists"}