{"id":36512913,"url":"https://github.com/justinsimmons/sqlmap","last_synced_at":"2026-01-14T10:57:40.655Z","repository":{"id":194316436,"uuid":"690720022","full_name":"justinsimmons/sqlmap","owner":"justinsimmons","description":"Convert a native go datatype to and from its sql null datatype equivalent.","archived":false,"fork":false,"pushed_at":"2024-01-22T20:34:00.000Z","size":59,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-12T05:12:20.868Z","etag":null,"topics":["golang","sql","sqlc"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justinsimmons.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-09-12T18:29:42.000Z","updated_at":"2026-01-08T07:36:14.000Z","dependencies_parsed_at":"2024-01-22T23:48:14.951Z","dependency_job_id":"8fa3221b-21c8-4a04-b2d8-ee8edfcfc57e","html_url":"https://github.com/justinsimmons/sqlmap","commit_stats":null,"previous_names":["justsimmons/sqlmap","justinsimmons/sqlmap"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/justinsimmons/sqlmap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinsimmons%2Fsqlmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinsimmons%2Fsqlmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinsimmons%2Fsqlmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinsimmons%2Fsqlmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justinsimmons","download_url":"https://codeload.github.com/justinsimmons/sqlmap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinsimmons%2Fsqlmap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28417780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","sql","sqlc"],"created_at":"2026-01-12T02:38:12.371Z","updated_at":"2026-01-14T10:57:40.650Z","avatar_url":"https://github.com/justinsimmons.png","language":"Go","readme":"# sqlmap\n\nConvert a native go datatype to and from its sql null datatype equivalent.\n\n## Why does this exist?\n\nRecently I started using a tool called [sqlc](https://sqlc.dev/) as a pseudo-ORM in one of my projects. Its a great tool but it has a couple of quirks. This package addresses one of those quirks. \n\nIf your database schema contains a null value, the generated code requires you to transform a pointer value to a `sql.NulXYZ` type.\n```golang\n    // We have a string pointer but need a sql.NullString type.\n    var biz *string\n\n    str := sql.NullString{}\n\n    if biz != nil {\n\t\tstr.String = *in\n\t\tstr.Valid = true\n\t}\n\n    // the str var is only initialized if biz is not null.\n\n    // insertRowInDatabase(context.Context, sql.NullString)\n    err := insertRowInDatabase(ctx, str)\n```\n\nThis package provides helper code to enable you to do the conversion inline.\n\n```golang\n    // We have a string pointer but need a sql.NullString type.\n    var biz *string\n\n    // insertRowInDatabase(context.Context, sql.NullString) (sql.NullString, error)\n    val, _ := insertRowInDatabase(ctx, sqlmap.ToNullString(biz))\n\n\t// It also allows you to \"unwrap\" the resultant `sql.NulXYZ` value to make it actually usable.\n\tbiz = sqlmap.UnwrapString(val)\n```\n\n\n## Example\n\nSay you have a database schema with a null column like so, and would like to insert some data into the table.\n\n```sql\n-- schema.sql\n\nCREATE TABLE foo (\n\tbar VARCHAR(128) NULL,\n    biz VARCHAR(400) NOT NULL\n);\n```\n```sql\n-- query.sql\n\n-- Insert a Foo into the foo table.\n-- name: CreateFoo :one\nINSERT INTO foo (\n\tbar,\n    biz\n) VALUES (\n\t$1,\n\t$2\n)\n```\n\nThis will generate some code:\n\n```golang\n// models.go\n\ntype Foo struct {\n\tBar sql.NullString\n\tBiz string\n}\n```\n\n```golang\n// query.sql.go\n\nconst createFoo = `-- name: CreateFoo :one\nINSERT INTO foo (\n\tbar,\n    biz\n) VALUES (\n\t$1,\n\t$2\n)\nRETURNING bar, biz\n`\n\ntype CreateFooParams struct {\n\tBar sql.NullString\n\tBiz string\n}\n\n// Insert a Foo into the foo table.\nfunc (q *Queries) CreateFoo(ctx context.Context, arg CreateFooParams) (Foo, error) {\n\trow := q.db.QueryRowContext(ctx, createFoo, arg.Bar, arg.Biz)\n\tvar i Foo\n\terr := row.Scan(\u0026i.Bar, \u0026i.Biz)\n\treturn i, err\n}\n```\n\nUse sqlmap inline with your params to avoid boilerplate code. Super useful for CRUD operations where you need to map a request to your datastores representation.\n\n```golang\nfunc main() {\n    var db *sql.db\n    // Assume you have connected to db.\n\n    queries := datastore.New(db)\n\n    var biz *string\n\n\tfoo, err := queries.CreateFoo(ctx, datastore.CreateFooParams{\n\t\tBar: sqlmap.NullString(biz),\n\t\tBiz: \"This is biz\",\n\t})\n\n\t// Note: foo.Bar is of type sql.NullString, which isn't really useful to us. \n\t// So we make use of the unwrap function to convert it to a more canonical go datatype.\n\tbiz = sqlmap.UnwrapString(foo.Bar)\n}\n```\n\n## License\n\nThis program is released under the GNU Lesser General Public License v3 or later.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinsimmons%2Fsqlmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustinsimmons%2Fsqlmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinsimmons%2Fsqlmap/lists"}