diff --git a/compiled_starters/elixir/.codecrafters/compile.sh b/compiled_starters/elixir/.codecrafters/compile.sh new file mode 100755 index 0000000..08567dc --- /dev/null +++ b/compiled_starters/elixir/.codecrafters/compile.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +mix escript.build +mv codecrafters_sqlite /tmp/codecrafters-build-sqlite-elixir diff --git a/compiled_starters/elixir/.codecrafters/run.sh b/compiled_starters/elixir/.codecrafters/run.sh new file mode 100755 index 0000000..e60a47e --- /dev/null +++ b/compiled_starters/elixir/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec /tmp/codecrafters-build-sqlite-elixir "$@" diff --git a/compiled_starters/elixir/.formatter.exs b/compiled_starters/elixir/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/compiled_starters/elixir/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/compiled_starters/elixir/.gitattributes b/compiled_starters/elixir/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/elixir/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/elixir/.gitignore b/compiled_starters/elixir/.gitignore new file mode 100644 index 0000000..8a51ccd --- /dev/null +++ b/compiled_starters/elixir/.gitignore @@ -0,0 +1,30 @@ +# Database files used for testing +*.db + +# Ignore the compiled binary +/codecrafters_sqlite + +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +app-*.tar + diff --git a/compiled_starters/elixir/README.md b/compiled_starters/elixir/README.md new file mode 100644 index 0000000..c954016 --- /dev/null +++ b/compiled_starters/elixir/README.md @@ -0,0 +1,76 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/sqlite.png) + +This is a starting point for Elixir solutions to the +["Build Your Own SQLite" Challenge](https://codecrafters.io/challenges/sqlite). + +In this challenge, you'll build a barebones SQLite implementation that supports +basic SQL queries like `SELECT`. Along the way we'll learn about +[SQLite's file format](https://www.sqlite.org/fileformat.html), how indexed data +is +[stored in B-trees](https://jvns.ca/blog/2014/10/02/how-does-sqlite-work-part-2-btrees/) +and more. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your SQLite implementation is in `lib/main.ex`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git commit -am "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `mix` installed locally +1. Run `./your_program.sh` to run your program, which is implemented in + `lib/main.ex`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. + +# Sample Databases + +To make it easy to test queries locally, we've added a sample database in the +root of this repository: `sample.db`. + +This contains two tables: `apples` & `oranges`. You can use this to test your +implementation for the first 6 stages. + +You can explore this database by running queries against it like this: + +```sh +$ sqlite3 sample.db "select id, name from apples" +1|Granny Smith +2|Fuji +3|Honeycrisp +4|Golden Delicious +``` + +There are two other databases that you can use: + +1. `superheroes.db`: + - This is a small version of the test database used in the table-scan stage. + - It contains one table: `superheroes`. + - It is ~1MB in size. +1. `companies.db`: + - This is a small version of the test database used in the index-scan stage. + - It contains one table: `companies`, and one index: `idx_companies_country` + - It is ~7MB in size. + +These aren't included in the repository because they're large in size. You can +download them by running this script: + +```sh +./download_sample_databases.sh +``` + +If the script doesn't work for some reason, you can download the databases +directly from +[codecrafters-io/sample-sqlite-databases](https://github.com/codecrafters-io/sample-sqlite-databases). diff --git a/compiled_starters/elixir/codecrafters.yml b/compiled_starters/elixir/codecrafters.yml new file mode 100644 index 0000000..c286f69 --- /dev/null +++ b/compiled_starters/elixir/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Elixir version used to run your code +# on Codecrafters. +# +# Available versions: elixir-1.18 +language_pack: elixir-1.18 diff --git a/compiled_starters/elixir/download_sample_databases.sh b/compiled_starters/elixir/download_sample_databases.sh new file mode 100755 index 0000000..03e0573 --- /dev/null +++ b/compiled_starters/elixir/download_sample_databases.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +echo "Downloading superheroes.db: ~1MB (used in stage 7)" +curl -Lo superheroes.db https://raw.githubusercontent.com/codecrafters-io/sample-sqlite-databases/master/superheroes.db + +echo "Downloading companies.db: ~7MB (used in stage 8)" +curl -Lo companies.db https://raw.githubusercontent.com/codecrafters-io/sample-sqlite-databases/master/companies.db + +echo "Sample databases downloaded." diff --git a/compiled_starters/elixir/lib/main.ex b/compiled_starters/elixir/lib/main.ex new file mode 100644 index 0000000..928e4de --- /dev/null +++ b/compiled_starters/elixir/lib/main.ex @@ -0,0 +1,21 @@ +defmodule CLI do + def main(args) do + case args do + [database_file_path, command] -> + case command do + ".dbinfo" -> + file = File.open!(database_file_path, [:read, :binary]) + + # You can use print statements as follows for debugging, they'll be visible when running tests. + IO.puts(:stderr, "Logs from your program will appear here!") + + # Uncomment this to pass the first stage + # :file.position(file, 16) # Skip the first 16 bytes of the header + # <> = IO.binread(file, 2) + # IO.puts("database page size: #{page_size}") + end + _ -> + IO.puts("Usage: your_program ") + end + end +end diff --git a/compiled_starters/elixir/mix.exs b/compiled_starters/elixir/mix.exs new file mode 100644 index 0000000..a0852f1 --- /dev/null +++ b/compiled_starters/elixir/mix.exs @@ -0,0 +1,30 @@ +defmodule App.MixProject do + # NOTE: You do not need to change anything in this file. + use Mix.Project + + def project do + [ + app: :codecrafters_sqlite, + version: "1.0.0", + elixir: "~> 1.18", + start_permanent: Mix.env() == :prod, + deps: deps(), + escript: [main_module: CLI] + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + # {:dep_from_hexpm, "~> 0.3.0"}, + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + ] + end +end diff --git a/compiled_starters/elixir/your_program.sh b/compiled_starters/elixir/your_program.sh new file mode 100755 index 0000000..bdc15b6 --- /dev/null +++ b/compiled_starters/elixir/your_program.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# +# Use this script to run your program LOCALLY. +# +# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit early if any commands fail + +# Copied from .codecrafters/compile.sh +# +# - Edit this to change how your program compiles locally +# - Edit .codecrafters/compile.sh to change how your program compiles remotely +( + cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory + mix escript.build + mv codecrafters_sqlite /tmp/codecrafters-build-sqlite-elixir +) + +# Copied from .codecrafters/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +exec /tmp/codecrafters-build-sqlite-elixir "$@" diff --git a/course-definition.yml b/course-definition.yml index 25edb01..76eae95 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -33,6 +33,7 @@ languages: - slug: "c" - slug: "cpp" - slug: "csharp" + - slug: "elixir" - slug: "gleam" - slug: "go" - slug: "java" diff --git a/dockerfiles/elixir-1.18.Dockerfile b/dockerfiles/elixir-1.18.Dockerfile new file mode 100644 index 0000000..87762ff --- /dev/null +++ b/dockerfiles/elixir-1.18.Dockerfile @@ -0,0 +1,25 @@ +# syntax=docker/dockerfile:1.7-labs +FROM elixir:1.18.3-alpine + +# Ensures the container is re-built if dependency files change +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="mix.exs" + +WORKDIR /app + +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app + +# install hex + rebar +RUN mix local.hex --force && \ + mix local.rebar --force + +# install and compile mix dependencies +RUN mix deps.get && \ + mix deps.compile + +# Install & cache deps +RUN .codecrafters/compile.sh + +RUN mkdir -p /app-cached +RUN if [ -d "/app/_build" ]; then mv /app/_build /app-cached; fi +RUN if [ -d "/app/deps" ]; then mv /app/deps /app-cached; fi diff --git a/solutions/elixir/01-dr6/code/.codecrafters/compile.sh b/solutions/elixir/01-dr6/code/.codecrafters/compile.sh new file mode 100755 index 0000000..08567dc --- /dev/null +++ b/solutions/elixir/01-dr6/code/.codecrafters/compile.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +mix escript.build +mv codecrafters_sqlite /tmp/codecrafters-build-sqlite-elixir diff --git a/solutions/elixir/01-dr6/code/.codecrafters/run.sh b/solutions/elixir/01-dr6/code/.codecrafters/run.sh new file mode 100755 index 0000000..e60a47e --- /dev/null +++ b/solutions/elixir/01-dr6/code/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec /tmp/codecrafters-build-sqlite-elixir "$@" diff --git a/solutions/elixir/01-dr6/code/.formatter.exs b/solutions/elixir/01-dr6/code/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/solutions/elixir/01-dr6/code/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/solutions/elixir/01-dr6/code/.gitattributes b/solutions/elixir/01-dr6/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/elixir/01-dr6/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/elixir/01-dr6/code/.gitignore b/solutions/elixir/01-dr6/code/.gitignore new file mode 100644 index 0000000..8a51ccd --- /dev/null +++ b/solutions/elixir/01-dr6/code/.gitignore @@ -0,0 +1,30 @@ +# Database files used for testing +*.db + +# Ignore the compiled binary +/codecrafters_sqlite + +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +app-*.tar + diff --git a/solutions/elixir/01-dr6/code/README.md b/solutions/elixir/01-dr6/code/README.md new file mode 100644 index 0000000..c954016 --- /dev/null +++ b/solutions/elixir/01-dr6/code/README.md @@ -0,0 +1,76 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/sqlite.png) + +This is a starting point for Elixir solutions to the +["Build Your Own SQLite" Challenge](https://codecrafters.io/challenges/sqlite). + +In this challenge, you'll build a barebones SQLite implementation that supports +basic SQL queries like `SELECT`. Along the way we'll learn about +[SQLite's file format](https://www.sqlite.org/fileformat.html), how indexed data +is +[stored in B-trees](https://jvns.ca/blog/2014/10/02/how-does-sqlite-work-part-2-btrees/) +and more. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your SQLite implementation is in `lib/main.ex`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git commit -am "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `mix` installed locally +1. Run `./your_program.sh` to run your program, which is implemented in + `lib/main.ex`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. + +# Sample Databases + +To make it easy to test queries locally, we've added a sample database in the +root of this repository: `sample.db`. + +This contains two tables: `apples` & `oranges`. You can use this to test your +implementation for the first 6 stages. + +You can explore this database by running queries against it like this: + +```sh +$ sqlite3 sample.db "select id, name from apples" +1|Granny Smith +2|Fuji +3|Honeycrisp +4|Golden Delicious +``` + +There are two other databases that you can use: + +1. `superheroes.db`: + - This is a small version of the test database used in the table-scan stage. + - It contains one table: `superheroes`. + - It is ~1MB in size. +1. `companies.db`: + - This is a small version of the test database used in the index-scan stage. + - It contains one table: `companies`, and one index: `idx_companies_country` + - It is ~7MB in size. + +These aren't included in the repository because they're large in size. You can +download them by running this script: + +```sh +./download_sample_databases.sh +``` + +If the script doesn't work for some reason, you can download the databases +directly from +[codecrafters-io/sample-sqlite-databases](https://github.com/codecrafters-io/sample-sqlite-databases). diff --git a/solutions/elixir/01-dr6/code/codecrafters.yml b/solutions/elixir/01-dr6/code/codecrafters.yml new file mode 100644 index 0000000..c286f69 --- /dev/null +++ b/solutions/elixir/01-dr6/code/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Elixir version used to run your code +# on Codecrafters. +# +# Available versions: elixir-1.18 +language_pack: elixir-1.18 diff --git a/solutions/elixir/01-dr6/code/download_sample_databases.sh b/solutions/elixir/01-dr6/code/download_sample_databases.sh new file mode 100755 index 0000000..03e0573 --- /dev/null +++ b/solutions/elixir/01-dr6/code/download_sample_databases.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +echo "Downloading superheroes.db: ~1MB (used in stage 7)" +curl -Lo superheroes.db https://raw.githubusercontent.com/codecrafters-io/sample-sqlite-databases/master/superheroes.db + +echo "Downloading companies.db: ~7MB (used in stage 8)" +curl -Lo companies.db https://raw.githubusercontent.com/codecrafters-io/sample-sqlite-databases/master/companies.db + +echo "Sample databases downloaded." diff --git a/solutions/elixir/01-dr6/code/lib/main.ex b/solutions/elixir/01-dr6/code/lib/main.ex new file mode 100644 index 0000000..24729a1 --- /dev/null +++ b/solutions/elixir/01-dr6/code/lib/main.ex @@ -0,0 +1,17 @@ +defmodule CLI do + def main(args) do + case args do + [database_file_path, command] -> + case command do + ".dbinfo" -> + file = File.open!(database_file_path, [:read, :binary]) + + :file.position(file, 16) # Skip the first 16 bytes of the header + <> = IO.binread(file, 2) + IO.puts("database page size: #{page_size}") + end + _ -> + IO.puts("Usage: your_program ") + end + end +end diff --git a/solutions/elixir/01-dr6/code/mix.exs b/solutions/elixir/01-dr6/code/mix.exs new file mode 100644 index 0000000..a0852f1 --- /dev/null +++ b/solutions/elixir/01-dr6/code/mix.exs @@ -0,0 +1,30 @@ +defmodule App.MixProject do + # NOTE: You do not need to change anything in this file. + use Mix.Project + + def project do + [ + app: :codecrafters_sqlite, + version: "1.0.0", + elixir: "~> 1.18", + start_permanent: Mix.env() == :prod, + deps: deps(), + escript: [main_module: CLI] + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + # {:dep_from_hexpm, "~> 0.3.0"}, + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + ] + end +end diff --git a/solutions/elixir/01-dr6/code/your_program.sh b/solutions/elixir/01-dr6/code/your_program.sh new file mode 100755 index 0000000..bdc15b6 --- /dev/null +++ b/solutions/elixir/01-dr6/code/your_program.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# +# Use this script to run your program LOCALLY. +# +# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit early if any commands fail + +# Copied from .codecrafters/compile.sh +# +# - Edit this to change how your program compiles locally +# - Edit .codecrafters/compile.sh to change how your program compiles remotely +( + cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory + mix escript.build + mv codecrafters_sqlite /tmp/codecrafters-build-sqlite-elixir +) + +# Copied from .codecrafters/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +exec /tmp/codecrafters-build-sqlite-elixir "$@" diff --git a/solutions/elixir/01-dr6/diff/lib/main.ex.diff b/solutions/elixir/01-dr6/diff/lib/main.ex.diff new file mode 100644 index 0000000..99772ee --- /dev/null +++ b/solutions/elixir/01-dr6/diff/lib/main.ex.diff @@ -0,0 +1,25 @@ +@@ -1,21 +1,17 @@ + defmodule CLI do + def main(args) do + case args do + [database_file_path, command] -> + case command do + ".dbinfo" -> + file = File.open!(database_file_path, [:read, :binary]) + +- # You can use print statements as follows for debugging, they'll be visible when running tests. +- IO.puts(:stderr, "Logs from your program will appear here!") +- +- # Uncomment this to pass the first stage +- # :file.position(file, 16) # Skip the first 16 bytes of the header +- # <> = IO.binread(file, 2) +- # IO.puts("database page size: #{page_size}") ++ :file.position(file, 16) # Skip the first 16 bytes of the header ++ <> = IO.binread(file, 2) ++ IO.puts("database page size: #{page_size}") + end + _ -> + IO.puts("Usage: your_program ") + end + end + end diff --git a/solutions/elixir/01-dr6/explanation.md b/solutions/elixir/01-dr6/explanation.md new file mode 100644 index 0000000..f5df671 --- /dev/null +++ b/solutions/elixir/01-dr6/explanation.md @@ -0,0 +1,18 @@ +The entry point for your SQLite implementation is in `lib/main.ex`. + +Study and uncomment the relevant code: + +```elixir +# Uncomment this to pass the first stage +:file.position(file, 16) # Skip the first 16 bytes of the header +<> = IO.binread(file, 2) +IO.puts("database page size: #{page_size}") +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` diff --git a/starter_templates/elixir/code/.codecrafters/compile.sh b/starter_templates/elixir/code/.codecrafters/compile.sh new file mode 100755 index 0000000..08567dc --- /dev/null +++ b/starter_templates/elixir/code/.codecrafters/compile.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +mix escript.build +mv codecrafters_sqlite /tmp/codecrafters-build-sqlite-elixir diff --git a/starter_templates/elixir/code/.codecrafters/run.sh b/starter_templates/elixir/code/.codecrafters/run.sh new file mode 100755 index 0000000..e60a47e --- /dev/null +++ b/starter_templates/elixir/code/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec /tmp/codecrafters-build-sqlite-elixir "$@" diff --git a/starter_templates/elixir/code/.formatter.exs b/starter_templates/elixir/code/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/starter_templates/elixir/code/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/starter_templates/elixir/code/.gitignore b/starter_templates/elixir/code/.gitignore new file mode 100644 index 0000000..ba2ee52 --- /dev/null +++ b/starter_templates/elixir/code/.gitignore @@ -0,0 +1,27 @@ +# Ignore the compiled binary +/codecrafters_sqlite + +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +app-*.tar + diff --git a/starter_templates/elixir/code/lib/main.ex b/starter_templates/elixir/code/lib/main.ex new file mode 100644 index 0000000..928e4de --- /dev/null +++ b/starter_templates/elixir/code/lib/main.ex @@ -0,0 +1,21 @@ +defmodule CLI do + def main(args) do + case args do + [database_file_path, command] -> + case command do + ".dbinfo" -> + file = File.open!(database_file_path, [:read, :binary]) + + # You can use print statements as follows for debugging, they'll be visible when running tests. + IO.puts(:stderr, "Logs from your program will appear here!") + + # Uncomment this to pass the first stage + # :file.position(file, 16) # Skip the first 16 bytes of the header + # <> = IO.binread(file, 2) + # IO.puts("database page size: #{page_size}") + end + _ -> + IO.puts("Usage: your_program ") + end + end +end diff --git a/starter_templates/elixir/code/mix.exs b/starter_templates/elixir/code/mix.exs new file mode 100644 index 0000000..a0852f1 --- /dev/null +++ b/starter_templates/elixir/code/mix.exs @@ -0,0 +1,30 @@ +defmodule App.MixProject do + # NOTE: You do not need to change anything in this file. + use Mix.Project + + def project do + [ + app: :codecrafters_sqlite, + version: "1.0.0", + elixir: "~> 1.18", + start_permanent: Mix.env() == :prod, + deps: deps(), + escript: [main_module: CLI] + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + # {:dep_from_hexpm, "~> 0.3.0"}, + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + ] + end +end diff --git a/starter_templates/elixir/config.yml b/starter_templates/elixir/config.yml new file mode 100644 index 0000000..1d5ecf8 --- /dev/null +++ b/starter_templates/elixir/config.yml @@ -0,0 +1,3 @@ +attributes: + required_executable: "mix" + user_editable_file: "lib/main.ex"