From efa3e7063788b4df9ca522568dcef0fe359b7021 Mon Sep 17 00:00:00 2001 From: Roman Heinrich Date: Tue, 23 Jan 2024 19:47:29 +0100 Subject: [PATCH] Chore: working surrealdb example --- .env | 7 +++++++ config/runtime.exs | 11 +++++++++++ lib/surrealix_demo/application.ex | 6 ++++++ mix.exs | 3 +++ mix.lock | 1 + 5 files changed, 28 insertions(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..3ff2a2f --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +### SurrealDB +SURREALDB_PORT=8000 +SURREALDB_HOST=localhost +SURREALDB_USER=root +SURREALDB_PASS=root +SURREALDB_NS=demo +SURREALDB_DB=demo diff --git a/config/runtime.exs b/config/runtime.exs index 3eedb1a..3d6dfca 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -20,6 +20,17 @@ if System.get_env("PHX_SERVER") do config :surrealix_demo, SurrealixDemoWeb.Endpoint, server: true end +dot_env_path = Path.expand(Path.join(__DIR__, "../.env")) + +if config_env() == :dev do + DotenvParser.load_file(dot_env_path) + config :logger, level: :debug +end + +if config_env() == :test do + DotenvParser.load_file(dot_env_path) +end + if config_env() == :prod do database_url = System.get_env("DATABASE_URL") || diff --git a/lib/surrealix_demo/application.ex b/lib/surrealix_demo/application.ex index 31f073f..5654f2f 100644 --- a/lib/surrealix_demo/application.ex +++ b/lib/surrealix_demo/application.ex @@ -16,6 +16,12 @@ defmodule SurrealixDemo.Application do {Finch, name: SurrealixDemo.Finch}, # Start a worker by calling: SurrealixDemo.Worker.start_link(arg) # {SurrealixDemo.Worker, arg}, + + ## For SurrealDB + {Surreal.ClientSupervisor, []}, + {Surreal.ConnSupervisor, []}, + %{id: Surreal.Repo, start: {Surreal.Repo, :start_link, [[]]}}, + # Start to serve requests, typically the last entry SurrealixDemoWeb.Endpoint ] diff --git a/mix.exs b/mix.exs index 822c60c..8e9f625 100644 --- a/mix.exs +++ b/mix.exs @@ -52,6 +52,9 @@ defmodule SurrealixDemo.MixProject do {:dns_cluster, "~> 0.1.1"}, {:plug_cowboy, "~> 2.5"}, + # Misc + {:dotenv_parser, "~> 2.0"}, + ## DB - SurrealDB {:surrealix, "~> 0.1"}, {:token_operator, "~> 0.3.1"} diff --git a/mix.lock b/mix.lock index ac2114b..61219f6 100644 --- a/mix.lock +++ b/mix.lock @@ -6,6 +6,7 @@ "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "dns_cluster": {:hex, :dns_cluster, "0.1.2", "3eb5be824c7888dadf9781018e1a5f1d3d1113b333c50bce90fb1b83df1015f2", [:mix], [], "hexpm", "7494272040f847637bbdb01bcdf4b871e82daf09b813e7d3cb3b84f112c6f2f8"}, + "dotenv_parser": {:hex, :dotenv_parser, "2.0.0", "0f999196857e4ee18cbba1413018d5e4980ab16b397e3a2f8d0cf541fe683181", [:mix], [], "hexpm", "e769bde2dbff5b0cd0d9d877a9ccfd2c6dd84772dfb405d5a43cceb4f93616c5"}, "ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"}, "ecto_sql": {:hex, :ecto_sql, "3.11.1", "e9abf28ae27ef3916b43545f9578b4750956ccea444853606472089e7d169470", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ce14063ab3514424276e7e360108ad6c2308f6d88164a076aac8a387e1fea634"}, "esbuild": {:hex, :esbuild, "0.8.1", "0cbf919f0eccb136d2eeef0df49c4acf55336de864e63594adcea3814f3edf41", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "25fc876a67c13cb0a776e7b5d7974851556baeda2085296c14ab48555ea7560f"},