ex_orient v0.1.2 ExOrient.DB.CRUD

Provides CRUD commands

Summary

Functions

Run a delete command. Examples

Insert into the database. Compatible with various styles of syntax. Examples

Shortcut function to easily select by Record ID. Takes a string or a %MarcoPolo.Rid{}

Perform a select operation. Examples

Passes a truncate command off to the correct function

Truncate a class

Truncate a cluster

Truncate a record

Perform an update command. Examples

Functions

delete(opts \\ [])

Run a delete command. Examples:

> DB.delete(from: "#10:0")

> DB.delete(from: ProgrammingLanguage)
insert(opts)

Insert into the database. Compatible with various styles of syntax. Examples:

> ExOrient.DB.insert(into: ProgrammingLanguage, values: {[:name], ["Elixir"]})
%MarcoPolo.Document{class: "ProgrammingLanguage", fields: %{"name" => "Elixir"}, rid: _, version: _}

> ExOrient.DB.insert(into: ProgrammingLanguage, set: [name: "Elixir"])
%MarcoPolo.Document{class: "ProgrammingLanguage", fields: %{"name" => "Elixir"}, rid: _, version: _}

> ExOrient.DB.insert(into: ProgrammingLanguage, content: %{name: "Elixir"})
%MarcoPolo.Document{class: "ProgrammingLanguage", fields: %{"name" => "Elixir"}, rid: _, version: _}

> ExOrient.DB.insert(into: ProgrammingLanguage, content: %{name: "Elixir"}, return: "@rid")
[9, 224]
rid(rid)

Shortcut function to easily select by Record ID. Takes a string or a %MarcoPolo.Rid{}.

> ExOrient.DB.rid("#9:0")
%MarcoPolo.Document{}

> ExOrient.DB.rid(%MarcoPolo.RID{cluster_id: 9, position: 0})
%MarcoPolo.Document{}
select(fields \\ [], opts)

Perform a select operation. Examples:

> ExOrient.DB.select(from: ProgrammingLanguage)

> ExOrient.DB.select([:name], from: {ProgrammingLanguage})

> ExOrient.DB.select(from: ProgrammingLanguage, where: %{name: "Elixir"})

> ExOrient.DB.select(from: ProgrammingLanguage, where: %{name: "Elixir", type: "Awesome"})

> ExOrient.DB.select(from: ProgrammingLanguage, where: %{name: "Elixir", type: "Awesome"}, logical: "OR")

> ExOrient.DB.select(from: ProgrammingLanguage, where: %{"name.toLowerCase()" => "lolcode"})

> ExOrient.DB.select(from: ProgrammingLanguage, where: {"name.length()", ">", 10})

> ExOrient.DB.select(from: ProgrammingLanguage,
                 where: [{"name.length()", ">", 10},
                         {"name.left(2)", "=", "El"}],
                 logical: "OR")
truncate(opts \\ [])

Passes a truncate command off to the correct function

truncate_class(opts \\ [])

Truncate a class

> ExOrient.DB.truncate(class: Person)
truncate_cluster(opts \\ [])

Truncate a cluster

> ExOrient.DB.truncate(cluster: "Germany")
truncate_record(opts \\ [])

Truncate a record

> ExOrient.DB.truncate(record: "#11:2")

> ExOrient.DB.truncate(record: ["#11:2", "#11:3"])
update(obj, opts \\ [])

Perform an update command. Examples:

> ExOrient.DB.update("#9:568", set: [name: "C"])
1

> ExOrient.DB.update(ProgrammingLanguage, where: %{name: "C"}, merge: %{type: ["Old", "Fast"]}, return: :after)
[%MarcoPolo.Document{class: "ProgrammingLanguage", fields: %{"name" => "C", "type" => ["Old", "Fast"]}, _, version: _}, ...]

> ExOrient.DB.update("#9:568", remove: [type: "Old"])
1

> ExOrient.DB.update(Person, set: [name: "Bob"], where: %{name: "Bob"}, upsert: true, return: :after)
[%MarcoPolo.Document{class: "Person", fields: %{"name" => "Bob"}, rid: _, version: _}]