View Source LadybugEx.Schema (LadybugEx v0.2.0)
Schema management functions for LadybugDB databases.
This module provides functions to create and manage node tables, relationship tables, and indexes in a LadybugDB database.
Summary
Functions
Creates an index on specified columns of a table.
Creates an index on specified columns, raising on error.
Creates a node table with the specified properties.
Creates a node table, raising on error.
Creates a relationship table with the specified properties.
Creates a relationship table, raising on error.
Gets information about a table's schema.
Drops a node table.
Drops a node table, raising on error.
Drops a relationship table.
Drops a relationship table, raising on error.
Lists all node tables in the database.
Lists all relationship tables in the database.
Types
@type property_def() :: {atom() | String.t(), property_type()} | {atom() | String.t(), property_type(), keyword()}
@type property_type() :: :string | :int8 | :int16 | :int32 | :int64 | :uint8 | :uint16 | :uint32 | :uint64 | :int128 | :float | :double | :float_array | :double_array | :bool | :date | :timestamp | :timestamp_tz | :timestamp_ns | :timestamp_ms | :timestamp_sec | :interval | :uuid | :blob | :decimal | {:list, property_type()} | {:array, property_type()} | {:array, property_type(), pos_integer()} | {:map, property_type(), property_type()}
Functions
@spec create_index( LadybugEx.Connection.t(), String.t(), atom() | String.t() | [atom() | String.t()] ) :: {:ok, :created} | {:error, String.t()}
Creates an index on specified columns of a table.
Parameters
conn- A connection referencetable_name- The name of the tablecolumns- Column or list of columns to index
Examples
iex> LadybugEx.Schema.create_index(conn, "Person", :email)
{:ok, :created}
iex> LadybugEx.Schema.create_index(conn, "Person", [:age, :city])
{:ok, :created}
@spec create_index!( LadybugEx.Connection.t(), String.t(), atom() | String.t() | [atom() | String.t()] ) :: :created
Creates an index on specified columns, raising on error.
Same as create_index/3 but raises an exception on error.
@spec create_node_table( LadybugEx.Connection.t(), String.t(), [property_def()], keyword() ) :: {:ok, :created} | {:error, String.t()}
Creates a node table with the specified properties.
Parameters
conn- A connection referencetable_name- The name of the node table to createproperties- A list of property definitionsopts- Table creation options
Property Definition
Properties can be defined as:
{name, type}- Simple property definition{name, type, opts}- Property with options like primary key
Options
:primary_key- Specify the primary key column(s)
Examples
iex> LadybugEx.Schema.create_node_table(conn, "Person", [
...> {:name, :string},
...> {:age, :int64},
...> {:email, :string}
...> ], primary_key: [:name])
{:ok, :created}
iex> LadybugEx.Schema.create_node_table(conn, "Product", [
...> {:id, :int64, primary_key: true},
...> {:name, :string},
...> {:price, :double},
...> {:tags, {:list, :string}}
...> ])
{:ok, :created}
@spec create_node_table!( LadybugEx.Connection.t(), String.t(), [property_def()], keyword() ) :: :created
Creates a node table, raising on error.
Same as create_node_table/4 but raises an exception on error.
@spec create_rel_table( LadybugEx.Connection.t(), String.t(), String.t(), String.t(), [property_def()], keyword() ) :: {:ok, :created} | {:error, String.t()}
Creates a relationship table with the specified properties.
Parameters
conn- A connection referencetable_name- The name of the relationship table to createfrom_table- The source node tableto_table- The destination node tableproperties- A list of property definitionsopts- Table creation options
Options
:multiplicity- Can be:one_to_one,:one_to_many,:many_to_many(default)
Examples
iex> LadybugEx.Schema.create_rel_table(conn, "KNOWS",
...> "Person", "Person",
...> [
...> {:since, :date},
...> {:strength, :double}
...> ]
...> )
{:ok, :created}
iex> LadybugEx.Schema.create_rel_table(conn, "OWNS",
...> "Person", "Product",
...> [
...> {:quantity, :int64},
...> {:purchase_date, :date}
...> ],
...> multiplicity: :one_to_many
...> )
{:ok, :created}
@spec create_rel_table!( LadybugEx.Connection.t(), String.t(), String.t(), String.t(), [property_def()], keyword() ) :: :created
Creates a relationship table, raising on error.
Same as create_rel_table/6 but raises an exception on error.
@spec describe_table(LadybugEx.Connection.t(), String.t()) :: {:ok, map()} | {:error, String.t()}
Gets information about a table's schema.
Parameters
conn- A connection referencetable_name- The name of the table
Examples
iex> LadybugEx.Schema.describe_table(conn, "Person")
{:ok, %{
name: "Person",
type: "NODE",
columns: [
%{name: "name", type: "STRING", is_primary: true},
%{name: "age", type: "INT64", is_primary: false}
]
}}
@spec drop_node_table(LadybugEx.Connection.t(), String.t(), keyword()) :: {:ok, :dropped} | {:error, String.t()}
Drops a node table.
Parameters
conn- A connection referencetable_name- The name of the table to dropopts- Drop options
Options
:cascade- Not currently supported by LadybugDB (ignored)
Examples
iex> LadybugEx.Schema.drop_node_table(conn, "Person")
{:ok, :dropped}
iex> LadybugEx.Schema.drop_node_table(conn, "Person", cascade: true)
{:ok, :dropped}
@spec drop_node_table!(LadybugEx.Connection.t(), String.t(), keyword()) :: :dropped
Drops a node table, raising on error.
Same as drop_node_table/3 but raises an exception on error.
@spec drop_rel_table(LadybugEx.Connection.t(), String.t(), keyword()) :: {:ok, :dropped} | {:error, String.t()}
Drops a relationship table.
Parameters
conn- A connection referencetable_name- The name of the relationship table to dropopts- Drop options
Examples
iex> LadybugEx.Schema.drop_rel_table(conn, "KNOWS")
{:ok, :dropped}
@spec drop_rel_table!(LadybugEx.Connection.t(), String.t(), keyword()) :: :dropped
Drops a relationship table, raising on error.
Same as drop_rel_table/3 but raises an exception on error.
@spec list_node_tables(LadybugEx.Connection.t()) :: {:ok, [String.t()]} | {:error, String.t()}
Lists all node tables in the database.
Parameters
conn- A connection reference
Examples
iex> LadybugEx.Schema.list_node_tables(conn)
{:ok, ["Person", "Product", "Order"]}
@spec list_rel_tables(LadybugEx.Connection.t()) :: {:ok, [String.t()]} | {:error, String.t()}
Lists all relationship tables in the database.
Parameters
conn- A connection reference
Examples
iex> LadybugEx.Schema.list_rel_tables(conn)
{:ok, ["KNOWS", "OWNS", "PURCHASED"]}