Skip to content

Commit 0fa68a3

Browse files
committed
feat: add Typescript support using deno runtime.
Add package.json support.
1 parent 0418228 commit 0fa68a3

28 files changed

+392
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/sqlite.png)
2+
3+
This is a starting point for TypeScript solutions to the
4+
["Build Your Own SQLite" Challenge](https://codecrafters.io/challenges/sqlite).
5+
6+
In this challenge, you'll build a barebones SQLite implementation that supports
7+
basic SQL queries like `SELECT`. Along the way we'll learn about
8+
[SQLite's file format](https://www.sqlite.org/fileformat.html), how indexed data
9+
is
10+
[stored in B-trees](https://jvns.ca/blog/2014/10/02/how-does-sqlite-work-part-2-btrees/)
11+
and more.
12+
13+
**Note**: If you're viewing this repo on GitHub, head over to
14+
[codecrafters.io](https://codecrafters.io) to try the challenge.
15+
16+
# Passing the first stage
17+
18+
The entry point for your SQLite implementation is in `app/main.ts`. Study and
19+
uncomment the relevant code, and push your changes to pass the first stage:
20+
21+
```sh
22+
git add .
23+
git commit -m "pass 1st stage" # any msg
24+
git push origin master
25+
```
26+
27+
Time to move on to the next stage!
28+
29+
# Stage 2 & beyond
30+
31+
Note: This section is for stages 2 and beyond.
32+
33+
1. Ensure you have `deno (1.42)` installed locally
34+
1. Run `./your_sqlite3.sh` to run your program, which is implemented in
35+
`app/main.ts`.
36+
1. Commit your changes and run `git push origin master` to submit your solution
37+
to CodeCrafters. Test output will be streamed to your terminal.
38+
39+
# Sample Databases
40+
41+
To make it easy to test queries locally, we've added a sample database in the
42+
root of this repository: `sample.db`.
43+
44+
This contains two tables: `apples` & `oranges`. You can use this to test your
45+
implementation for the first 6 stages.
46+
47+
You can explore this database by running queries against it like this:
48+
49+
```sh
50+
$ sqlite3 sample.db "select id, name from apples"
51+
1|Granny Smith
52+
2|Fuji
53+
3|Honeycrisp
54+
4|Golden Delicious
55+
```
56+
57+
There are two other databases that you can use:
58+
59+
1. `superheroes.db`:
60+
- This is a small version of the test database used in the table-scan stage.
61+
- It contains one table: `superheroes`.
62+
- It is ~1MB in size.
63+
1. `companies.db`:
64+
- This is a small version of the test database used in the index-scan stage.
65+
- It contains one table: `companies`, and one index: `idx_companies_country`
66+
- It is ~7MB in size.
67+
68+
These aren't included in the repository because they're large in size. You can
69+
download them by running this script:
70+
71+
```sh
72+
./download_sample_databases.sh
73+
```
74+
75+
If the script doesn't work for some reason, you can download the databases
76+
directly from
77+
[codecrafters-io/sample-sqlite-databases](https://github.com/codecrafters-io/sample-sqlite-databases).
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const databaseFilePath: string = Deno.args[0];
2+
const command: string = Deno.args[1];
3+
4+
if (command === ".dbinfo") {
5+
const databaseFileHandler = await Deno.open(databaseFilePath, { read: true });
6+
const buffer = new Uint8Array(100);
7+
await databaseFileHandler.read(buffer);
8+
9+
// You can use print statements as follows for debugging, they'll be visible when running tests.
10+
console.log("Logs from your program will appear here!");
11+
12+
// Uncomment this to pass the first stage
13+
// const pageSize = new DataView(buffer.buffer, 0, buffer.byteLength).getUint16(16);
14+
// console.log(`database page size: ${pageSize}`);
15+
16+
databaseFileHandler.close();
17+
} else {
18+
throw new Error(`Unknown command ${command}`);
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the TypeScript version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: deno-1.42
11+
language_pack: deno-1.42
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
echo "Downloading superheroes.db: ~1MB (used in stage 7)"
4+
curl -Lo superheroes.db https://raw.githubusercontent.com/codecrafters-io/sample-sqlite-databases/master/superheroes.db
5+
6+
echo "Downloading companies.db: ~7MB (used in stage 8)"
7+
curl -Lo companies.db https://raw.githubusercontent.com/codecrafters-io/sample-sqlite-databases/master/companies.db
8+
9+
echo "Sample databases downloaded."
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@codecrafters/build-your-own-sqlite",
3+
"description": "Build your own SQLite challenge, from CodeCrafters",
4+
"type": "module",
5+
"scripts": {
6+
"dev": "deno run --allow-all app/main.ts"
7+
},
8+
"dependencies": {}
9+
}
16 KB
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
#
3+
# DON'T EDIT THIS!
4+
#
5+
# CodeCrafters uses this file to test your code. Don't make any changes here!
6+
#
7+
# DON'T EDIT THIS!
8+
exec deno run --allow-all ./app/main.ts "$@"

course-definition.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ languages:
4444
- slug: "zig"
4545
- slug: "java"
4646
release_status: "beta"
47+
- slug: "typescript"
48+
release_status: "beta"
4749

4850
marketing:
4951
difficulty: hard

0 commit comments

Comments
 (0)