From 9244572e0f5757a45cf037963866f333d1a916b7 Mon Sep 17 00:00:00 2001 From: Nik Date: Wed, 2 Aug 2023 11:47:34 -0400 Subject: [PATCH] change repl language from `elixir` to `iex` (#161) --- lib/edgedb.ex | 20 +++++++++--------- lib/edgedb/types/config_memory.ex | 2 +- lib/edgedb/types/date_duration.ex | 2 +- lib/edgedb/types/named_tuple.ex | 8 +++---- lib/edgedb/types/object.ex | 6 +++--- lib/edgedb/types/range.ex | 6 +++--- lib/edgedb/types/relative_duration.ex | 2 +- lib/edgedb/types/set.ex | 4 ++-- pages/md/custom-codecs.md | 4 ++-- pages/md/usage.md | 20 +++++++++--------- pages/rst/api/api.rst | 20 +++++++++--------- pages/rst/api/edgedb-types.rst | 30 +++++++++++++-------------- pages/rst/custom-codecs.rst | 4 ++-- pages/rst/usage.rst | 20 +++++++++--------- 14 files changed, 74 insertions(+), 74 deletions(-) diff --git a/lib/edgedb.ex b/lib/edgedb.ex index 9d3bc971..f8489e34 100644 --- a/lib/edgedb.ex +++ b/lib/edgedb.ex @@ -7,7 +7,7 @@ defmodule EdgeDB do A simple example of how to use it: - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query!(client, "\"\" ...(2)> select Person{ @@ -181,7 +181,7 @@ defmodule EdgeDB do If the first argument is a string, it will be assumed to be the DSN or instance name and passed as `[dsn: dsn]` keyword list to connect. - ```elixir + ```iex iex(1)> {:ok, _client} = EdgeDB.start_link("edgedb://edgedb:edgedb@localhost:5656/edgedb") ``` @@ -189,7 +189,7 @@ defmodule EdgeDB do Otherwise, if the first argument is a list, it will be used as is to connect. See `t:EdgeDB.start_option/0` for supported connection options. - ```elixir + ```iex iex(1)> {:ok, _client} = EdgeDB.start_link(instance: "edgedb_elixir") ``` @@ -223,7 +223,7 @@ defmodule EdgeDB do `[dsn: dsn]` keyword list along with other options to connect. See `t:EdgeDB.start_option/0` for supported connection options. - ```elixir + ```iex iex(1)> {:ok, _client} = EdgeDB.start_link("edgedb://edgedb:edgedb@localhost:5656/edgedb", tls_security: :insecure) ``` @@ -260,7 +260,7 @@ defmodule EdgeDB do Execute the query on the client and return the results as a `{:ok, set}` tuple if successful, where `set` is `EdgeDB.Set`. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, %EdgeDB.Set{} = set} = EdgeDB.query(client, "select 42") iex(3)> set @@ -270,7 +270,7 @@ defmodule EdgeDB do If an error occurs, it will be returned as a `{:error, exception}` tuple where `exception` is `EdgeDB.Error`. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:error, %EdgeDB.Error{} = error} = EdgeDB.query(client, "select UndefinedType") iex(2)> raise error @@ -280,14 +280,14 @@ defmodule EdgeDB do If a query has arguments, they can be passed as a list for a query with positional arguments or as a list of keywords for a query with named arguments. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, %EdgeDB.Set{} = set} = EdgeDB.query(client, "select $0", [42]) iex(3)> set #EdgeDB.Set<{42}> ``` - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, %EdgeDB.Set{} = set} = EdgeDB.query(client, "select $arg", arg: 42) iex(3)> set @@ -538,7 +538,7 @@ defmodule EdgeDB do `EdgeDB.transaction/3` calls **cannot** be nested more than once. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, tickets} = EdgeDB.transaction(client, fn client -> ...(2)> EdgeDB.query!(client, "insert Ticket{ number := 2}") @@ -581,7 +581,7 @@ defmodule EdgeDB do See `t:EdgeDB.rollback_option/0` for supported options. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:error, :tx_rollback} = ...(2)> EdgeDB.transaction(client, fn tx_conn -> diff --git a/lib/edgedb/types/config_memory.ex b/lib/edgedb/types/config_memory.ex index 05b11b8c..352ad262 100644 --- a/lib/edgedb/types/config_memory.ex +++ b/lib/edgedb/types/config_memory.ex @@ -2,7 +2,7 @@ defmodule EdgeDB.ConfigMemory do @moduledoc """ An immutable value represeting an EdgeDB `cfg::memory` value as a quantity of memory storage. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> mem = EdgeDB.query_required_single!(client, "select '5KiB'") #EdgeDB.ConfigMemory<"5KiB"> diff --git a/lib/edgedb/types/date_duration.ex b/lib/edgedb/types/date_duration.ex index 58e1b7dd..e06031f3 100644 --- a/lib/edgedb/types/date_duration.ex +++ b/lib/edgedb/types/date_duration.ex @@ -3,7 +3,7 @@ defmodule EdgeDB.DateDuration do @moduledoc """ An immutable value represeting an EdgeDB `cal::date_duration` value. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query_required_single!(client, "select '1 year 2 days'") #EdgeDB.DateDuration<"P1Y2D"> diff --git a/lib/edgedb/types/named_tuple.ex b/lib/edgedb/types/named_tuple.ex index 3960403c..1eb4eed1 100644 --- a/lib/edgedb/types/named_tuple.ex +++ b/lib/edgedb/types/named_tuple.ex @@ -5,7 +5,7 @@ defmodule EdgeDB.NamedTuple do `EdgeDB.NamedTuple` implements `Access` behavior to access fields by index or key and `Enumerable` protocol for iterating over tuple values. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])") #EdgeDB.NamedTuple @@ -33,7 +33,7 @@ defmodule EdgeDB.NamedTuple do @doc """ Convert a named tuple to a regular erlang tuple. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])") iex(3)> EdgeDB.NamedTuple.to_tuple(nt) @@ -51,7 +51,7 @@ defmodule EdgeDB.NamedTuple do @doc """ Convert a named tuple into a regular map. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])") iex(3)> EdgeDB.NamedTuple.to_map(nt) @@ -66,7 +66,7 @@ defmodule EdgeDB.NamedTuple do @doc """ Get named tuple keys. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])") iex(3)> EdgeDB.NamedTuple.keys(nt) diff --git a/lib/edgedb/types/object.ex b/lib/edgedb/types/object.ex index 49dc74b5..e16896b9 100644 --- a/lib/edgedb/types/object.ex +++ b/lib/edgedb/types/object.ex @@ -4,7 +4,7 @@ defmodule EdgeDB.Object do `EdgeDB.Object` implements `Access` behavior to access properties by key. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Object{} = object = iex(2)> EdgeDB.query_required_single!(client, "\"\" @@ -28,7 +28,7 @@ defmodule EdgeDB.Object do Links can also have their own properties (denoted as `@` in EdgeQL syntax). You can use the same property name as in the query to access them from the links. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Object{} = object = iex(2)> EdgeDB.query_required_single!(client, "\"\" @@ -214,7 +214,7 @@ defmodule EdgeDB.Object do @doc """ Convert an object into a regular map. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> object = iex(2)> EdgeDB.query_required_single!(client, "\"\" diff --git a/lib/edgedb/types/range.ex b/lib/edgedb/types/range.ex index 694653fc..d30b1d77 100644 --- a/lib/edgedb/types/range.ex +++ b/lib/edgedb/types/range.ex @@ -3,7 +3,7 @@ defmodule EdgeDB.Range do @moduledoc """ A value representing some interval of values. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query_required_single!(client, "select range(1, 10)") #EdgeDB.Range<[1, 10)> @@ -71,7 +71,7 @@ defmodule EdgeDB.Range do @doc """ Create an empty range. - ```elixir + ```iex iex(1)> EdgeDB.Range.empty() #EdgeDB.Range ``` @@ -84,7 +84,7 @@ defmodule EdgeDB.Range do @doc """ Create new range. - ```elixir + ```iex iex(1)> EdgeDB.Range.new(1.1, 3.3, inc_upper: true) #EdgeDB.Range<[1.1, 3.3]> ``` diff --git a/lib/edgedb/types/relative_duration.ex b/lib/edgedb/types/relative_duration.ex index 4edbe1bc..9b341b90 100644 --- a/lib/edgedb/types/relative_duration.ex +++ b/lib/edgedb/types/relative_duration.ex @@ -2,7 +2,7 @@ defmodule EdgeDB.RelativeDuration do @moduledoc """ An immutable value represeting an EdgeDB `cal::relative_duration` value. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query_required_single!(client, "select '45.6 seconds'") #EdgeDB.RelativeDuration<"PT45.6S"> diff --git a/lib/edgedb/types/set.ex b/lib/edgedb/types/set.ex index a77b009b..272c9439 100644 --- a/lib/edgedb/types/set.ex +++ b/lib/edgedb/types/set.ex @@ -5,7 +5,7 @@ defmodule EdgeDB.Set do `EdgeDB.Set` implements `Enumerable` protocol for iterating over set values. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Set{} = iex(2)> EdgeDB.query!(client, "\"\" @@ -31,7 +31,7 @@ defmodule EdgeDB.Set do @doc """ Check if set is empty. - ```elixir + ```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Set{} = set = EdgeDB.query!(client, "select Ticket") iex(3)> EdgeDB.Set.empty?(set) diff --git a/pages/md/custom-codecs.md b/pages/md/custom-codecs.md index a2a3e4cb..8127d349 100644 --- a/pages/md/custom-codecs.md +++ b/pages/md/custom-codecs.md @@ -106,11 +106,11 @@ end Now let's test this codec: -```elixir +```iex iex(1)> {:ok, client} = EdgeDB.start_link(codecs: [MyApp.EdgeDB.Codecs.JSONPayload]) iex(2)> payload = %MyApp.Users.Payload{public_id: 1, first_name: "Harry", last_name: "Potter"} iex(3)> EdgeDB.query!(client, "insert User { name := $username, payload := $payload }", username: "user", payload: payload) -iex(4) EdgeDB.Object{} = EdgeDB.query_required_single!(client, "select User {name, payload} filter .name = 'user' limit 1") +iex(4)> EdgeDB.Object{} = EdgeDB.query_required_single!(client, "select User {name, payload} filter .name = 'user' limit 1") #EdgeDB.Object {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query!(client, """ ...(2)> WITH @@ -105,7 +105,7 @@ If you want to receive an `EdgeDB.Set` from your query, just use the `EdgeDB.que Let's query all existing posts with their bodies: -```elixir +```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, posts} = EdgeDB.query(client, "select Post { body }") {:ok, @@ -116,7 +116,7 @@ iex(2)> {:ok, posts} = EdgeDB.query(client, "select Post { body }") We can iterate over `EdgeDB.Set` and inspect each object separately: -```elixir +```iex iex(3)> Enum.each(posts, fn %EdgeDB.Object{} = post -> ...(3)> IO.inspect(post[:body], label: "post (#{inspect(post.id)})") ...(3)> end) @@ -135,7 +135,7 @@ If you know that the query will return only one element or none, you can use `Ed Let's query a post with a link to the Elixir client for EdgeDB: -```elixir +```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Object{} = post = EdgeDB.query_single!(client, "select Post filter contains(.body, 'https://hex.pm/packages/edgedb') limit 1") iex(3)> post.id @@ -144,7 +144,7 @@ iex(3)> post.id If we try to select a `Post` that does not exist, `nil` will be returned: -```elixir +```iex iex(4)> EdgeDB.query_single!(client, "select Post filter .body = 'lol' limit 1") nil ``` @@ -154,7 +154,7 @@ nil In case we want to ensure that the requested element must exist, we can use the functions `EdgeDB.query_required_single/4` and `EdgeDB.query_required_single!/4`. Instead of returning `nil` they will return `EdgeDB.Error` in case of a missing element: -```elixir +```iex iex(5)> EdgeDB.query_required_single!(client, "select Post filter .body = 'lol' limit 1") ** (EdgeDB.Error) NoDataError: expected result, but query did not return any data ``` @@ -167,7 +167,7 @@ iex(5)> EdgeDB.query_required_single!(client, "select Post filter .body = 'lol' The API for transactions is provided by the `EdgeDB.transaction/3` function: -```elixir +```iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, user} = ...(2)> EdgeDB.transaction(client, fn conn -> @@ -178,7 +178,7 @@ iex(2)> {:ok, user} = Transactions can be rollbacked using the `EdgeDB.rollback/2` function or automatically if an error has occurred inside a transaction block: -```elixir +```iex iex(3)> {:error, :rollback} = ...(3)> EdgeDB.transaction(client, fn conn -> ...(3)> %EdgeDB.Object{} = EdgeDB.query_required_single!(conn, "insert User { name := $username }", username: "wrong_username") @@ -198,7 +198,7 @@ The following types of errors can be retried retried: As an example, let's create a transaction conflict to show how this works. In the first example, we will disable retries: -```elixir +```iex iex(5)> callback = fn conn, body -> ...(5)> Process.sleep(500) ...(5)> EdgeDB.query!(conn, "update Post filter .author.id = $user_id set { body := $new_body }", user_id: user.id, new_body: body) @@ -214,7 +214,7 @@ iex(7)> EdgeDB.transaction(client, &callback.(&1, "new_body_2"), retry: [transac Now let's execute the same thing but with enabled retries: -```elixir +```iex iex(8)> spawn(fn -> ...(8)> {:ok, client} = EdgeDB.start_link() ...(8)> EdgeDB.transaction(client, &callback.(&1, "new_body_1")) diff --git a/pages/rst/api/api.rst b/pages/rst/api/api.rst index 4dc9eb06..f1b6520e 100644 --- a/pages/rst/api/api.rst +++ b/pages/rst/api/api.rst @@ -12,7 +12,7 @@ EdgeDB client for Elixir. A simple example of how to use it: -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query!(client, """ @@ -262,7 +262,7 @@ See ``EdgeDB.query_option/0`` for supported options. Execute the query on the client and return the results as a ``{:ok, set}`` tuple if successful, where ``set`` is ``EdgeDB.Set``. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, %EdgeDB.Set{} = set} = EdgeDB.query(client, "select 42") @@ -271,7 +271,7 @@ Execute the query on the client and return the results as a ``{:ok, set}`` tuple If an error occurs, it will be returned as a ``{:error, exception}`` tuple where ``exception`` is ``EdgeDB.Error``. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:error, %EdgeDB.Error{} = error} = EdgeDB.query(client, "select UndefinedType") @@ -281,14 +281,14 @@ If an error occurs, it will be returned as a ``{:error, exception}`` tuple where If a query has arguments, they can be passed as a list for a query with positional arguments or as a list of keywords for a query with named arguments. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, %EdgeDB.Set{} = set} = EdgeDB.query(client, "select $0", [42]) iex(3)> set #EdgeDB.Set<{42}> -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, %EdgeDB.Set{} = set} = EdgeDB.query(client, "select $arg", arg: 42) @@ -481,7 +481,7 @@ Rollback an open transaction. See ``EdgeDB.rollback_option/0`` for supported options. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:error, :tx_rollback} = @@ -501,13 +501,13 @@ Creates a pool of EdgeDB connections linked to the current process. If the first argument is a string, it will be assumed to be the DSN or instance name and passed as ``[dsn: dsn]`` keyword list to connect. -.. code:: elixir +.. code:: iex iex(1)> {:ok, _client} = EdgeDB.start_link("edgedb://edgedb:edgedb@localhost:5656/edgedb") Otherwise, if the first argument is a list, it will be used as is to connect. See ``EdgeDB.start_option/0`` for supported connection options. -.. code:: elixir +.. code:: iex iex(1)> {:ok, _client} = EdgeDB.start_link(instance: "edgedb_elixir") @@ -523,7 +523,7 @@ Creates a pool of EdgeDB connections linked to the current process. The first argument is the string which will be assumed as the DSN and passed as ``[dsn: dsn]`` keyword list along with other options to connect. See ``EdgeDB.start_option/0`` for supported connection options. -.. code:: elixir +.. code:: iex iex(1)> {:ok, _client} = EdgeDB.start_link("edgedb://edgedb:edgedb@localhost:5656/edgedb", tls_security: :insecure) @@ -547,7 +547,7 @@ To rollback an open transaction, use ``EdgeDB.rollback/2``. ``EdgeDB.transaction/3`` calls **cannot** be nested more than once. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, tickets} = EdgeDB.transaction(client, fn client -> diff --git a/pages/rst/api/edgedb-types.rst b/pages/rst/api/edgedb-types.rst index 7444c982..84401dc1 100644 --- a/pages/rst/api/edgedb-types.rst +++ b/pages/rst/api/edgedb-types.rst @@ -10,7 +10,7 @@ An immutable representation of an object instance returned from a query. ``EdgeDB.Object`` implements ``Access`` behavior to access properties by key. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Object{} = object = @@ -34,7 +34,7 @@ In EdgeDB, objects can have links to other objects or a set of objects. You can properties. Links can also have their own properties (denoted as ``@`` in EdgeQL syntax). You can use the same property name as in the query to access them from the links. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Object{} = object = @@ -179,7 +179,7 @@ See ``EdgeDB.Object.properties_option/0`` for supported options. Convert an object into a regular map. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> object = @@ -204,7 +204,7 @@ A representation of an immutable set of values returned by a query. Nested sets ``EdgeDB.Set`` implements ``Enumerable`` protocol for iterating over set values. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Set{} = @@ -245,7 +245,7 @@ Functions Check if set is empty. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Set{} = set = EdgeDB.query!(client, "select Ticket") @@ -260,7 +260,7 @@ An immutable value representing an EdgeDB named tuple value. ``EdgeDB.NamedTuple`` implements ``Access`` behavior to access fields by index or key and ``Enumerable`` protocol for iterating over tuple values. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])") @@ -300,7 +300,7 @@ Functions Get named tuple keys. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])") @@ -316,7 +316,7 @@ Get named tuple keys. Convert a named tuple into a regular map. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])") @@ -332,7 +332,7 @@ Convert a named tuple into a regular map. Convert a named tuple to a regular erlang tuple. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> nt = EdgeDB.query_required_single!(client, "select (a := 1, b := 'a', c := [3])") @@ -344,7 +344,7 @@ EdgeDB.RelativeDuration An immutable value represeting an EdgeDB ``cal::relative_duration`` value. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query_required_single!(client, "select '45.6 seconds'") @@ -379,7 +379,7 @@ EdgeDB.DateDuration An immutable value represeting an EdgeDB ``cal::date_duration`` value. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query_required_single!(client, "select '1 year 2 days'") @@ -409,7 +409,7 @@ EdgeDB.ConfigMemory An immutable value represeting an EdgeDB ``cfg::memory`` value as a quantity of memory storage. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> mem = EdgeDB.query_required_single!(client, "select '5KiB'") @@ -450,7 +450,7 @@ EdgeDB.Range A value representing some interval of values. -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query_required_single!(client, "select range(1, 10)") @@ -531,7 +531,7 @@ Functions Create an empty range. -.. code:: elixir +.. code:: iex iex(1)> EdgeDB.Range.empty() #EdgeDB.Range @@ -545,7 +545,7 @@ Create an empty range. Create new range. -.. code:: elixir +.. code:: iex iex(1)> EdgeDB.Range.new(1.1, 3.3, inc_upper: true) #EdgeDB.Range<[1.1, 3.3]> diff --git a/pages/rst/custom-codecs.rst b/pages/rst/custom-codecs.rst index bd18b6c4..39ee6ff5 100644 --- a/pages/rst/custom-codecs.rst +++ b/pages/rst/custom-codecs.rst @@ -110,12 +110,12 @@ The implementation of the codec itself: Now let’s test this codec: -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link(codecs: [MyApp.EdgeDB.Codecs.JSONPayload]) iex(2)> payload = %MyApp.Users.Payload{public_id: 1, first_name: "Harry", last_name: "Potter"} iex(3)> EdgeDB.query!(client, "insert User { name := $username, payload := $payload }", username: "user", payload: payload) - iex(4) EdgeDB.Object{} = EdgeDB.query_required_single!(client, "select User {name, payload} filter .name = 'user' limit 1") + iex(4)> EdgeDB.Object{} = EdgeDB.query_required_single!(client, "select User {name, payload} filter .name = 'user' limit 1") #EdgeDB.Object {:ok, client} = EdgeDB.start_link() iex(2)> EdgeDB.query!(client, """ @@ -107,7 +107,7 @@ between the two functions is that ``EdgeDB.query/4`` will return an ``:ok`` tupl Let’s query all existing posts with their bodies: -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, posts} = EdgeDB.query(client, "select Post { body }") @@ -118,7 +118,7 @@ Let’s query all existing posts with their bodies: We can iterate over ``EdgeDB.Set`` and inspect each object separately: -.. code:: elixir +.. code:: iex iex(3)> Enum.each(posts, fn %EdgeDB.Object{} = post -> ...(3)> IO.inspect(post[:body], label: "post (#{inspect(post.id)})") @@ -137,7 +137,7 @@ This function will automatically unpack the underlying ``EdgeDB.Set`` and return Let’s query a post with a link to the Elixir client for EdgeDB: -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> %EdgeDB.Object{} = post = EdgeDB.query_single!(client, "select Post filter contains(.body, 'https://hex.pm/packages/edgedb') limit 1") @@ -146,7 +146,7 @@ Let’s query a post with a link to the Elixir client for EdgeDB: If we try to select a ``Post`` that does not exist, ``nil`` will be returned: -.. code:: elixir +.. code:: iex iex(4)> EdgeDB.query_single!(client, "select Post filter .body = 'lol' limit 1") nil @@ -157,7 +157,7 @@ Querying a required single element In case we want to ensure that the requested element must exist, we can use the functions ``EdgeDB.query_required_single/4`` and ``EdgeDB.query_required_single!/4``. Instead of returning ``nil`` they will return ``EdgeDB.Error`` in case of a missing element: -.. code:: elixir +.. code:: iex iex(5)> EdgeDB.query_required_single!(client, "select Post filter .body = 'lol' limit 1") ** (EdgeDB.Error) NoDataError: expected result, but query did not return any data @@ -172,7 +172,7 @@ Transactions The API for transactions is provided by the ``EdgeDB.transaction/3`` function: -.. code:: elixir +.. code:: iex iex(1)> {:ok, client} = EdgeDB.start_link() iex(2)> {:ok, user} = @@ -182,7 +182,7 @@ The API for transactions is provided by the ``EdgeDB.transaction/3`` function: Transactions can be rollbacked using the ``EdgeDB.rollback/2`` function or automatically if an error has occurred inside a transaction block: -.. code:: elixir +.. code:: iex iex(3)> {:error, :rollback} = ...(3)> EdgeDB.transaction(client, fn conn -> @@ -202,7 +202,7 @@ The following types of errors can be retried retried: As an example, let’s create a transaction conflict to show how this works. In the first example, we will disable retries: -.. code:: elixir +.. code:: iex iex(5)> callback = fn conn, body -> ...(5)> Process.sleep(500) @@ -218,7 +218,7 @@ As an example, let’s create a transaction conflict to show how this works. In Now let’s execute the same thing but with enabled retries: -.. code:: elixir +.. code:: iex iex(8)> spawn(fn -> ...(8)> {:ok, client} = EdgeDB.start_link()