{"id":19866008,"url":"https://github.com/multiprocessio/go-sqlite3-stdlib","last_synced_at":"2025-07-13T18:30:38.737Z","repository":{"id":37479590,"uuid":"491730573","full_name":"multiprocessio/go-sqlite3-stdlib","owner":"multiprocessio","description":"A standard library for mattn/go-sqlite3 including best-effort date parsing, url parsing, math/string functions, and stats aggregation functions","archived":false,"fork":false,"pushed_at":"2023-08-18T03:44:12.000Z","size":767,"stargazers_count":125,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-12T15:32:02.346Z","etag":null,"topics":["golang","sqlite","sqlite3","sqlite3-extension"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/multiprocessio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-13T02:22:39.000Z","updated_at":"2024-10-25T07:17:01.000Z","dependencies_parsed_at":"2024-06-18T19:48:10.137Z","dependency_job_id":"69dbe73b-cc85-4051-94a3-7dd60b33f197","html_url":"https://github.com/multiprocessio/go-sqlite3-stdlib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiprocessio%2Fgo-sqlite3-stdlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiprocessio%2Fgo-sqlite3-stdlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiprocessio%2Fgo-sqlite3-stdlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiprocessio%2Fgo-sqlite3-stdlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/multiprocessio","download_url":"https://codeload.github.com/multiprocessio/go-sqlite3-stdlib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225906273,"owners_count":17543129,"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":["golang","sqlite","sqlite3","sqlite3-extension"],"created_at":"2024-11-12T15:24:44.588Z","updated_at":"2024-11-22T13:34:53.491Z","avatar_url":"https://github.com/multiprocessio.png","language":"Go","readme":"# A standard library for mattn/go-sqlite3\n\nAs an alternative to compiling C extensions like\n[extension-functions.c](https://www.sqlite.org/contrib) and\n[sqlean](https://github.com/nalgeon/sqlean) into\n[mattn/go-sqlite3](https://github.com/mattn/go-sqlite3), this package\nimplements many of these functions (and more from PostgreSQL) in Go.\n\nThese are in addition to [all builtin\nfunctions](https://www.sqlite.org/lang_corefunc.html) provided by\nSQLite.\n\nContinue reading for all functions, notes and examples.\n\n# Why would I use this?\n\nThis library is used in\n[DataStation](https://github.com/multiprocessio/datastation) and\n[dsq](https://github.com/multiprocessio/dsq) to simplify and power\ndata analysis in SQL.\n\n![Analyzing logs with SQL in DataStation](./screenshot.png)\n\nRead the [DataStation blog\npost](https://datastation.multiprocess.io/docs/0.11.0-release-notes.html)\nto better understand the background.\n\n# Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"database/sql\"\n\n\t_ \"github.com/mattn/go-sqlite3\"\n\tstdlib \"github.com/multiprocessio/go-sqlite3-stdlib\"\n)\n\nfunc main() {\n\tstdlib.Register(\"sqlite3_ext\")\n\tdb, err := sql.Open(\"sqlite3_ext\", \":memory:\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tvar s string\n\terr = db.QueryRow(\"SELECT repeat('x', 2)\").Scan(\u0026s)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(s)\n}\n```\n\nAlternatively if you want to be able to add your own additional\nextensions you can just use the `ConnectHook`:\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\t\"fmt\"\n\n\tsqlite3 \"github.com/mattn/go-sqlite3\"\n\tstdlib \"github.com/multiprocessio/go-sqlite3-stdlib\"\n)\n\nfunc main() {\n\tsql.Register(\"sqlite3_ext\",\n\t\t\u0026sqlite3.SQLiteDriver{\n\t\t\tConnectHook: stdlib.ConnectHook,\n\t\t})\n\tdb, err := sql.Open(\"sqlite3_ext\", \":memory:\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tvar s string\n\terr = db.QueryRow(\"SELECT repeat('x', 2)\").Scan(\u0026s)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(s)\n}\n```\n\n# Functions\n\n## Strings\n\n| Name(s)           | Notes                                                     | Example                                                        |\n| ----------------- | --------------------------------------------------------- | -------------------------------------------------------------- |\n| repeat, replicate |                                                           | `repeat('f', 5) = 'fffff'`                                     |\n| strpos, charindex | 0-indexed position of substring in string                 | `strpos('abc', 'b') = 1`                                       |\n| reverse           |                                                           | `reverse('abc') = 'cba'`                                       |\n| lpad              | Omit the third argument to default to padding with spaces | `lpad('22', 3, '0') = '022'`                                   |\n| rpad              | Omit the third argument to default to padding with spaces | `rpad('22', 3, '0') = '220'`                                   |\n| len               | Shorthand for `length`                                    | `len('my string') = '9'`                                       |\n| split_part        | Split string an take nth split piece                      | `split('1,2,3', ',', 0) = '1'`, `split('1,2,3', ',' -1) = '3'` |\n| regexp            | Go's regexp package, not PCRE                             | `x REGEXP '[a-z]+$'`, `REGEXP('[a-z]+$', x)`                   |\n| regexp_count      | Number of times the regexp matches in string              | `regexp_count('abc1', '[a-z]1') = '1'`                         |\n| regexp_split_part | Regexp equivalent of `split_part`                         | `regexp_split_part('ab12', '[a-z]1', 0) = 'a'`                 |\n\n## Aggregation\n\nMost of these are implemented as bindings to\n[gonum](https://gonum.org/v1/gonum).\n\n| Name(s)                                                                                                                                                                                                    | Notes      | Example                        |\n| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------ |\n| stddev, stdev, stddev_pop                                                                                                                                                                                  |            | `stddev(n)`                    |\n| mode                                                                                                                                                                                                       |            | `mode(n)`                      |\n| median                                                                                                                                                                                                     |            | `median(n)`                    |\n| percentile, perc                                                                                                                                                                                           | Discrete   | `perc(response_time, 95)`      |\n| percentile_25, perc_25, percentile_50, perc_50, percentile_75, perc_75, percentile_90, perc_90, percentile_95, perc_95, percentile_99, perc_99                                                             | Discrete   | `perc_99(response_time)`       |\n| percentile_cont, perc_cont                                                                                                                                                                                 | Continuous | `perc_cont(response_time, 95)` |\n| percentile_cont_25, perc_cont_25, percentile_cont_50, perc_cont_50, percentile_cont_75, perc_cont_75, percentile_cont_90, perc_cont_90, percentile_cont_95, perc_cont_95, percentile_cont_99, perc_cont_99 | Continuous | `perc_cont_99(response_time)`  |\n\n## Net\n\n| Name(s)      | Notes | Example                                                                               |\n| ------------ | ----- | ------------------------------------------------------------------------------------- |\n| url_scheme   |       | `url_scheme('https://x.com:90/home.html') = 'https'`                                  |\n| url_host     |       | `url_host('https://x.com:90/home.html') = 'x.com:90'`                                 |\n| url_port     |       | `url_port('https://x.com:90/home.html') = '90'`                                       |\n| url_path     |       | `url_path('https://x.com/some/path.html?p=123') = '/some/path.html'`                  |\n| url_param    |       | `url_param('https://x.com/home.html?p=123\u0026z=%5B1%2C2%5D#section-1', 'z') = '[1,2]'`   |\n| url_fragment |       | `url_fragment('https://x.com/home.html?p=123\u0026z=%5B1%2C2%5D#section-1') = 'section-1'` |\n\n## Date\n\nBest effort family of date parsing (uses\n[dateparse](https://github.com/araddon/dateparse)) and date part\nretrieval. Results will differ depending on your computer's timezone.\n\n| Name(s)      | Notes               | Example                                                      |\n| ------------ | ------------------- | ------------------------------------------------------------ |\n| date_year    |                     | `date_year('2021-04-05') = 2021`                             |\n| date_month   | January is 1, not 0 | `date_month('May 6, 2021') = 5`                              |\n| date_day     |                     | `date_day('May 6, 2021') = 6`                                |\n| date_yearday | Day offset in year  | `date_yearday('May 6, 2021') = 127`                          |\n| date_hour    | 24-hour             | `date_hour('May 6, 2021 4:50 PM') = 16`                      |\n| date_minute  |                     | `date_minute('May 6, 2021 4:50') = 50`                       |\n| date_second  |                     | `date_second('May 6, 2021 4:50:20') = 20`                    |\n| date_unix    |                     | `date_unix('May 6, 2021 4:50:20') = 1588740620`              |\n| date_rfc3339 |                     | `date_rfc3339('May 6, 2021 4:50:20') = 2020-05-06T04:50:20Z` |\n\n## Math\n\n| Name(s)         | Notes                                                    | Example                                    |\n| --------------- | -------------------------------------------------------- | ------------------------------------------ |\n| acos            |                                                          | `acos(n)`                                  |\n| acosh           |                                                          | `acosh(n)`                                 |\n| asin            |                                                          | `asin(n)`                                  |\n| asinh           |                                                          | `asinh(n)`                                 |\n| atan            |                                                          | `atan(n)`                                  |\n| atanh           |                                                          | `atanh(n)`                                 |\n| ceil, ceiling   |                                                          | `ceil(n)`                                  |\n| cos             |                                                          | `ceil(n)`                                  |\n| cosh            |                                                          | `cosh(n)`                                  |\n| degrees         |                                                          | `degrees(radians)`                         |\n| exp             | e^n                                                      | `exp(n)`                                   |\n| floor           |                                                          | `floor(n)`                                 |\n| ln, log         |                                                          | `log(x)`                                   |\n| log10           |                                                          | `log10(x)`                                 |\n| log2            |                                                          | `log2(x)`                                  |\n| mod             |                                                          | `mod(num, denom)`                          |\n| pi              |                                                          | `pi()`                                     |\n| pow, power      |                                                          | `pow(base, exp)`                           |\n| radians         |                                                          | `radians(degrees)`                         |\n| sin             |                                                          | `sin(n)`                                   |\n| sinh            |                                                          | `sinh(n)`                                  |\n| sqrt            |                                                          | `sqrt(n)`                                  |\n| tan             |                                                          | `tan(n)`                                   |\n| tanh            |                                                          | `tanh(n)`                                  |\n| trunc, truncate | Rounds up to zero if negative, down to zero if positive. | `trunc(-10.9) = -10`, `trunc(10.4) = 10.0` |\n\n## Encoding\n\n| Name(s)     | Notes                         | Example          |\n| ----------- | ----------------------------- | ---------------- |\n| base64      | Convert string to base64      | `base64(s)`      |\n| from_base64 | Convert string from base64    | `from_base64(s)` |\n| base32      | Convert string to base32      | `base32(s)`      |\n| from_base32 | Convert string from base32    | `from_base32(s)` |\n| md5         | Hex md5 sum of string         | `md5(s)`         |\n| sha1        | Hex sha1 sum of string        | `sha1(s)`        |\n| sha256      | Hex sha256 sum of string      | `sha256(s)`      |\n| sha512      | Hex sha512 sum of string      | `sha512(s)`      |\n| sha3_256    | Hex sha3_256 sum of string    | `sha3_256(s)`    |\n| sha3_512    | Hex sha3_512 sum of string    | `sha3_512(s)`    |\n| blake2b_256 | Hex blake2b_256 sum of string | `blake2b_256(s)` |\n| blake2b_512 | Hex blake2b_512 sum of string | `blake2b_512(s)` |\n\n# How is this tested?\n\nThere is 95% test coverage and automated tests on Windows, macOS and\nLinux.\n\n# I just want to use it as a CLI or GUI\n\nSee [dsq](https://github.com/multiprocessio/dsq) (a command-line tool\nfor executing SQL on data files) and\n[DataStation](https://github.com/multiprocessio/datastation), a GUI\napplication for querying and building reports with data from\ndatabases, servers, and files.\n\n# Contribute\n\nJoin the [#dev channel on the Multiprocess Labs\nDiscord](https://discord.gg/22ZCpaS9qm).\n\nIf you have an idea for a new function, say so on the Discord channel\nor open an issue here.\n\nMake sure the function doesn't already exist in dsq (or the sqlite3\nCLI).\n\n# License\n\nThis software is licensed under an Apache 2.0 license.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultiprocessio%2Fgo-sqlite3-stdlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultiprocessio%2Fgo-sqlite3-stdlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultiprocessio%2Fgo-sqlite3-stdlib/lists"}