{"id":24469005,"url":"https://github.com/ivanbgd/codecrafters-sqlite-rust","last_synced_at":"2025-03-14T13:24:01.627Z","repository":{"id":272987293,"uuid":"918386909","full_name":"ivanbgd/codecrafters-sqlite-rust","owner":"ivanbgd","description":"SQLite (from a Codecrafters challenge)","archived":false,"fork":false,"pushed_at":"2025-02-19T20:07:07.000Z","size":107,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-19T21:22:29.789Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/ivanbgd.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,"publiccode":null,"codemeta":null}},"created_at":"2025-01-17T20:32:23.000Z","updated_at":"2025-02-19T20:07:10.000Z","dependencies_parsed_at":"2025-02-19T21:20:49.373Z","dependency_job_id":"35d0693c-30a8-44b7-ae60-3270be8bc153","html_url":"https://github.com/ivanbgd/codecrafters-sqlite-rust","commit_stats":null,"previous_names":["ivanbgd/codecrafters-sqlite-rust"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanbgd%2Fcodecrafters-sqlite-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanbgd%2Fcodecrafters-sqlite-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanbgd%2Fcodecrafters-sqlite-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanbgd%2Fcodecrafters-sqlite-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanbgd","download_url":"https://codeload.github.com/ivanbgd/codecrafters-sqlite-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243581778,"owners_count":20314298,"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":[],"created_at":"2025-01-21T07:13:44.625Z","updated_at":"2025-03-14T13:24:01.617Z","avatar_url":"https://github.com/ivanbgd.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![progress-banner](https://backend.codecrafters.io/progress/sqlite/b3b12e89-a536-4604-be71-ddd7dab3056e)](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)\n\nThis is a starting point for Rust solutions to the\n[\"Build Your Own SQLite\" Challenge](https://codecrafters.io/challenges/sqlite).\n\nIn this challenge, you'll build a barebones SQLite implementation that supports\nbasic SQL queries like `SELECT`. Along the way we'll learn about\n[SQLite's file format](https://www.sqlite.org/fileformat.html), how indexed data\nis\n[stored in B-trees](https://jvns.ca/blog/2014/10/02/how-does-sqlite-work-part-2-btrees/)\nand more.\n\n**Note**: If you're viewing this repo on GitHub, head over to\n[codecrafters.io](https://codecrafters.io) to try the challenge.\n\n# Passing the first stage\n\nThe entry point for your SQLite implementation is in `src/main.rs`. Study and\nuncomment the relevant code, and push your changes to pass the first stage:\n\n```sh\ngit commit -am \"pass 1st stage\" # any msg\ngit push origin master\n```\n\nTime to move on to the next stage!\n\n# Stage 2 \u0026 beyond\n\nNote: This section is for stages 2 and beyond.\n\n1. Ensure you have `cargo (1.82)` installed locally\n2. Run `./your_program.sh` to run your program, which is implemented in\n   `src/main.rs`. This command compiles your Rust project, so it might be slow\n   the first time you run it. Subsequent runs will be fast.\n3. Commit your changes and run `git push origin master` to submit your solution\n   to CodeCrafters. Test output will be streamed to your terminal.\n\n# Sample Databases\n\nTo make it easy to test queries locally, we've added a sample database in the\nroot of this repository: `sample.db`.\n\nThis contains two tables: `apples` \u0026 `oranges`. You can use this to test your\nimplementation for the first 6 stages.\n\nYou can explore this database by running queries against it like this:\n\n```sh\n$ sqlite3 sample.db \"select id, name from apples\"\n1|Granny Smith\n2|Fuji\n3|Honeycrisp\n4|Golden Delicious\n```\n\nThere are two other databases that you can use:\n\n1. `superheroes.db`:\n    - This is a small version of the test database used in the table-scan stage.\n    - It contains one table: `superheroes`.\n    - It is ~1MB in size.\n2. `companies.db`:\n    - This is a small version of the test database used in the index-scan stage.\n    - It contains one table: `companies`, and one index: `idx_companies_country`\n    - It is ~7MB in size.\n\nThese aren't included in the repository because they're large in size. You can\ndownload them by running this script:\n\n```sh\n./download_sample_databases.sh\n```\n\nIf the script doesn't work for some reason, you can download the databases\ndirectly from\n[codecrafters-io/sample-sqlite-databases](https://github.com/codecrafters-io/sample-sqlite-databases).\n\n# Running the Program\n\nThe program works from the command line, and supports the so-called dot-commands (CLI commands) as well as\nSQL commands.\n\nSupported SQL commands can be supplied in lower, upper or mixed-case, i.e., they are case-insensitive.  \nThe same is true of the supplied table and column names.\n\nValues in the `WHERE` clause are case-sensitive.\n\nSupported dot-commands are also case-insensitive.\n\n## CLI Commands (dot-commands)\n\n- To emulate `$ sqlite3 sample.db .dbinfo`:\n\n```shell\n$ ./your_program.sh sample.db .dbinfo\ndatabase page size: 4096\nnumber of pages: 4\nnumber of tables: 3\ntext encoding: utf-8\n```\n\n- To emulate `$ sqlite3 sample.db .tables`:\n\n```shell\n$ ./your_program.sh sample.db .tables\napples oranges\n```\n\n- To emulate `$ sqlite3 companies.db .index` or `$ sqlite3 companies.db .indexes`:\n\n```shell\n$ ./your_program.sh companies.db .index\n$ ./your_program.sh companies.db .indexes\nidx_companies_country\n```\n\n## SQL Commands\n\n### Count number of rows in a table\n\n```shell\n$ ./your_program.sh sample.db \"SELECT COUNT(*) FROM apples\"\n4\n```\n\n### Select from a single column\n\n```shell\n$ ./your_program.sh sample.db \"SELECT name FROM apples\"\nGranny Smith\nFuji\nHoneycrisp\nGolden Delicious\n```\n\nAdditionally, `LIMIT` is supported.\n\n```shell\n$ ./your_program.sh sample.db \"SELECT name FROM apples LIMIT 3\"\nGranny Smith\nFuji\nHoneycrisp\n```\n\n### Select from multiple columns\n\n```shell\n$ ./your_program.sh sample.db \"SELECT name, color FROM apples\"\nGranny Smith|Light Green\nFuji|Red\nHoneycrisp|Blush Red\nGolden Delicious|Yellow\n```\n\n```shell\n$ ./your_program.sh sample.db \"SELECT * FROM apples\"\n1|Granny Smith|Light Green\n2|Fuji|Red\n3|Honeycrisp|Blush Red\n4|Golden Delicious|Yellow\n```\n\nAdditionally, `LIMIT` is supported.\n\n```shell\n$ ./your_program.sh sample.db \"SELECT id, name, color FROM apples LIMIT 10\"\n1|Granny Smith|Light Green\n2|Fuji|Red\n3|Honeycrisp|Blush Red\n4|Golden Delicious|Yellow\n```\n\n### Select Using Where\n\n```shell\n$ ./your_program.sh sample.db \"SELECT id, name, color FROM apples WHERE color = 'Blush Red'\"\n3|Honeycrisp|Blush Red\n```\n\nAdditionally, `LIMIT` is supported.\n\n```shell\n$ ./your_program.sh sample.db \"SELECT id, name, color FROM apples WHERE color = 'Blush Red' LIMIT 1\"\n3|Honeycrisp|Blush Red\n```\n\n### Large Databases and Tables\n\nLarge tables, spanning multiple pages, are supported.\n\n```shell\n$ ./your_program.sh superheroes.db \"SELECT id, name FROM superheroes WHERE eye_color = 'Pink Eyes'\"\n297|Stealth (New Earth)\n790|Tobias Whale (New Earth)\n1085|Felicity (New Earth)\n2729|Thrust (New Earth)\n3289|Angora Lapin (New Earth)\n3913|Matris Ater Clementia (New Earth)\n```\n\n### Indexes\n\nIndexes are also supported.\n\nRather than reading all rows in a table and then filtering in-memory,\nwe use an index to perform a more intelligent search.\n\nTo test whether our implementation actually uses an index, their tester uses a database that is ~1GB in size\nand expects our program to return query results in less than 3 seconds.\n\nThe test database contains a `companies` table with an index named `idx_companies_country` on the `country` column.\n\nWe can download a small version of the `companies` database to test locally.\n\n```shell\n$ ./your_program.sh companies.db \"SELECT id, name FROM companies WHERE country = 'micronesia'\"\n1307865|college of micronesia\n3696903|nanofabrica\n4023193|fsm statistics\n6132291|vital energy micronesia\n6387751|fsm development bank\n```\n\nWe can assume that all queries run by the tester will include `country` in the `WHERE` clause,\nso they can be served by the index.\nThe tester will run multiple randomized queries and expect all of them to return results in under 3 seconds.\n\nSince the table `superheroes` is smaller than `companies`, we can add an index to it and also work with it.\n\n```shell\n$ sqlite3 superheroes.db \"CREATE INDEX idx_superheroes_eye_color on superheroes (eye_color)\"\n\n$ ./your_program.sh superheroes.db \"SELECT id, name FROM superheroes LIMIT 10\"\n$ ./your_program.sh superheroes.db \"SELECT id, name FROM superheroes WHERE eye_color = 'Pink Eyes' LIMIT 3\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanbgd%2Fcodecrafters-sqlite-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanbgd%2Fcodecrafters-sqlite-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanbgd%2Fcodecrafters-sqlite-rust/lists"}