{"id":18602810,"url":"https://github.com/obgnail/sqlite-toy","last_synced_at":"2025-05-16T18:12:24.590Z","repository":{"id":220254866,"uuid":"619895049","full_name":"obgnail/sqlite-toy","owner":"obgnail","description":"研究目的的，基于内存的，完全原生实现的，有限支持 SQL 查询的关系型数据库","archived":false,"fork":false,"pushed_at":"2023-03-27T16:25:29.000Z","size":43,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-18T01:42:00.111Z","etag":null,"topics":["bptree","database","golang","learning-by-doing","native-base","sql","sqlite-database"],"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/obgnail.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-27T16:14:15.000Z","updated_at":"2024-08-15T02:19:24.000Z","dependencies_parsed_at":"2024-02-01T04:44:53.402Z","dependency_job_id":"a181b66e-6760-4b1a-8e43-2550494889de","html_url":"https://github.com/obgnail/sqlite-toy","commit_stats":null,"previous_names":["obgnail/sqlite-toy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obgnail%2Fsqlite-toy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obgnail%2Fsqlite-toy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obgnail%2Fsqlite-toy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obgnail%2Fsqlite-toy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/obgnail","download_url":"https://codeload.github.com/obgnail/sqlite-toy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582909,"owners_count":22095519,"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":["bptree","database","golang","learning-by-doing","native-base","sql","sqlite-database"],"created_at":"2024-11-07T02:12:36.995Z","updated_at":"2025-05-16T18:12:24.572Z","avatar_url":"https://github.com/obgnail.png","language":"Go","readme":"# sqlite-toy\n\n\n\n## 简介\n\n`sqlite-toy` 是一个**以研究为目的的**，**基于内存的**，**完全原生实现的**，有限支持 SQL 查询的关系型数据库。\n\n主要的目标是为了向数据库爱好者展示一个关系型数据库的基本原理和关键设计。因此，为了便于理解，采取了很多取巧但不是很严谨的设计，代码量控制在 2000 行以内。\n\n\n\n## 特性列表\n\n纯 Golang 实现，不依赖任何第三方包。\n\n\n\n#### 存储引擎\n\n基于 B+Tree 的数据检索结构。\n\n#### SQL Parser\n\n1. Tokenizer 基于 text/scanner 实现。\n2. 支持简单的 SELECT、INSERT、UPDATE、DELETE、CREARE TABLE 语法。\n   1. SELECT、UPDATE、DELETE 支持数值类型的 WHERE。\n   2. 支持 LIMIT，但暂不支持 ORDER BY。\n3. 距离实现 SQL-2011 标准有十万八千里远。\n\n#### 执行计划 Planner\n\n基于火山模型（Volcano Model）的 Select 实现。\n\n\n\n## 实现的局限\n\n1. 有限支持 SQL 语法。\n2. 以研究为目的，没有严格的单元测试。\n3. Tokenizer 由于是基于 Golang 语言本身的一个取巧实现，对于一些字符串里的特殊字符支持会出现问题，可以通过加 `\"` 解决。\n\n\n\n## 使用\n\n```go\nfunc main() {\n\tdb := sqlite.NewDB()\n\terr := db.Exec(`\n\tCREATE TABLE user (\n\t\temail      VARCHAR(255)   NOT NULL  DEFAULT \"default@gmail.com\",\n\t\tusername   VARCHAR(16)    NOT NULL,\n\t\tid         INTEGER        NOT NULL,\n\t\tPRIMARY KEY (id)\n\t);`)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tfor i := 1; i != 30; i++ {\n\t\tsql := fmt.Sprintf(`INSERT INTO user (id, username, email) VALUES (%d, \"userName-%d\", \"User-%d@gmail.com\")`, i, i, i)\n\t\tif err = db.Exec(sql); err != nil {\n\t\t\tlog.Fatalln(err)\n\t\t}\n\t}\n\n\tresult, err := db.Query(`SELECT email, id, username FROM user WHERE id \u003e 3 LIMIT 10`)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\tfmt.Println(result)\n\n\terr = db.Exec(`UPDATE user SET username = \"newName222\", email = \"NewEmail111\" WHERE username = \"userName-27\";`)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\terr = db.Exec(`DELETE FROM user WHERE username = \"newName222\" AND email = \"NewEmail111\";`)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\terr = db.Exec(`DELETE FROM user WHERE id \u003c 25;`)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tresult, err = db.Query(`SELECT email, id, username FROM user WHERE id \u003e 26`)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\tfmt.Println(result)\n}\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobgnail%2Fsqlite-toy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobgnail%2Fsqlite-toy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobgnail%2Fsqlite-toy/lists"}