{"id":15667487,"url":"https://github.com/silas/jdb","last_synced_at":"2025-07-27T07:07:18.227Z","repository":{"id":57604148,"uuid":"137066634","full_name":"silas/jdb","owner":"silas","description":"Simple document database built on the JSON features of MySQL, PostgreSQL, and SQLite","archived":false,"fork":false,"pushed_at":"2019-08-30T21:20:26.000Z","size":224,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T04:26:40.658Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/silas.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-06-12T12:12:45.000Z","updated_at":"2023-07-29T17:49:36.000Z","dependencies_parsed_at":"2022-09-04T13:51:55.257Z","dependency_job_id":null,"html_url":"https://github.com/silas/jdb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/silas/jdb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fjdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fjdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fjdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fjdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/silas","download_url":"https://codeload.github.com/silas/jdb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fjdb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267320254,"owners_count":24068527,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-03T14:03:57.428Z","updated_at":"2025-07-27T07:07:18.186Z","avatar_url":"https://github.com/silas.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jdb\n\njdb is a simple document database built on the JSON features of MySQL,\nPostgreSQL, and SQLite.\n\nIt provides a migration helper, query builder, and struct mapper.\n\nThis package is currently in development and the API is not stable.\n\n## Usage\n\n``` go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/silas/jdb\"\n\t_ \"github.com/silas/jdb/dialect/sqlite3\"\n)\n\ntype Name struct {\n\tGivenName  string   `jdb:\",omitempty\"`\n\tFamilyName string   `jdb:\",omitempty\"`\n\tAliases    []string `jdb:\",omitempty\"`\n}\n\ntype User struct {\n\tKind       string    `jdb:\"-kind\"`\n\tID         string    `jdb:\"-id\"`\n\tEmail      string    `jdb:\",uniquestringkey\"`\n\tName       Name      `jdb:\",omitempty\"`\n\tAge        int       `jdb:\",omitempty\"`\n\tCreateTime time.Time `jdb:\"-createtime\"`\n\tUpdateTime time.Time `jdb:\"-updatetime\"`\n}\n\nfunc (u User) DatabaseNumericKey() (*float64, bool) {\n\tif u.Age \u003e 0 {\n\t\tage := float64(u.Age)\n\t\treturn \u0026age, true\n\t} else {\n\t\treturn nil, true\n\t}\n}\n\nfunc main() {\n\tctx := context.Background()\n\n\tdb, err := jdb.Open(\"sqlite3\", \"test.db?cache=shared\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\terr = db.Migrate(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\terr = db.Tx(ctx, func(tx *jdb.Tx) error {\n\t\tuser := User{\n\t\t\tID:    \"1\",\n\t\t\tEmail: \"jane@example.com\",\n\t\t\tName: Name{\n\t\t\t\tGivenName:  \"Jane\",\n\t\t\t\tFamilyName: \"Doe\",\n\t\t\t\tAliases:    []string{\"Janie\", \"Roe\"},\n\t\t\t},\n\t\t\tAge: 34,\n\t\t}\n\n\t\terr = db.Query(\"user\").Insert(user).Exec(ctx, tx)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\treturn tx.Commit()\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\terr = db.Tx(ctx, func(tx *jdb.Tx) error {\n\t\tvar user User\n\t\terr = db.Query(\"user\").Get(\"1\").Select().First(ctx, tx, \u0026user)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tfmt.Println(user)\n\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\nRun with required sqlite3 flags:\n\n``` sh\n$ go run \\\n  -tags \"libsqlite3 $(uname -s | tr '[:upper:]' '[:lower:]') json1\" \\\n  main.go\n```\n\nThis will result in a row that looks something like the following:\n\n``` sql\nsqlite\u003e SELECT * FROM jdb WHERE kind = 'user' AND id = '1';\n             kind = user\n               id = 1\n      parent_kind = ¤\n        parent_id = ¤\nunique_string_key = jane@example.com\n       string_key = ¤\n      numeric_key = 34.0\n         time_key = ¤\n             data = {\"Email\":\"jane@example.com\",\"Name\":{\"GivenName\":\"Jane\",\"FamilyName\":\"Doe\",\"Aliases\":[\"Janie\",\"Roe\"]},\"Age\":34}\n      create_time = 2018-06-12 12:41:37.035\n      update_time = 2018-06-12 12:41:37.035\n```\n\nWith the following schema (in SQLite):\n\n```\nsqlite\u003e .schema\nCREATE TABLE jdb (\n  kind VARCHAR(64),\n  id VARCHAR(64),\n  parent_kind VARCHAR(64),\n  parent_id VARCHAR(64),\n  unique_string_key VARCHAR(255),\n  string_key VARCHAR(255),\n  numeric_key REAL,\n  time_key DATETIME,\n  data JSON,\n  create_time DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),\n  update_time DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),\n  PRIMARY KEY (kind, id),\n  FOREIGN KEY (parent_kind, parent_id) REFERENCES jdb (kind, id)\n);\nCREATE INDEX jdb_r2 ON jdb (create_time);\nCREATE INDEX jdb_r3 ON jdb (update_time);\nCREATE UNIQUE INDEX jdb_r4 ON jdb (kind, unique_string_key);\nCREATE INDEX jdb_r5 ON jdb (kind, string_key);\nCREATE INDEX jdb_r6 ON jdb (kind, numeric_key);\nCREATE INDEX jdb_r7 ON jdb (kind, time_key);\nCREATE INDEX jdb_r8 ON jdb (kind, create_time);\nCREATE INDEX jdb_r9 ON jdb (kind, update_time);\nCREATE INDEX jdb_r10 ON jdb (kind, id, parent_kind);\nCREATE INDEX jdb_r11 ON jdb (parent_kind, parent_id, kind, unique_string_key);\nCREATE INDEX jdb_r12 ON jdb (parent_kind, parent_id, kind, string_key);\nCREATE INDEX jdb_r13 ON jdb (parent_kind, parent_id, kind, numeric_key);\nCREATE INDEX jdb_r14 ON jdb (parent_kind, parent_id, kind, time_key);\nCREATE INDEX jdb_r15 ON jdb (parent_kind, parent_id, kind, create_time);\nCREATE INDEX jdb_r16 ON jdb (parent_kind, parent_id, kind, update_time);\n```\n\n## License\n\nThis work is licensed under the MIT License (see the LICENSE and NOTICE files).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilas%2Fjdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilas%2Fjdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilas%2Fjdb/lists"}