ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - florinpatrascu/neo4j_sips_models: Neo4j models, for Neo4j.Sips
Neo4j models, for Neo4j.Sips. Contribute to florinpatrascu/neo4j_sips_models development by creating an account on GitHub.
Visit Site

GitHub - florinpatrascu/neo4j_sips_models: Neo4j models, for Neo4j.Sips

GitHub - florinpatrascu/neo4j_sips_models: Neo4j models, for Neo4j.Sips

Neo4j.Sips.Models

Minimalistic Model support for the Neo4j.Sips Elixir driver.

Install

If available on Hex.pm, edit the mix.ex configuration file and add the neo4j_sips_models dependency to the deps/1 function:

defp deps do
  [{:neo4j_sips_models, "~> 0.1"}]
end

or Github:

defp deps do
  [{:neo4j_sips_models, github: "florinpatrascu/neo4j_sips_models"}]
end

Or, if you're using a local development copy:

defp deps do
  [{:neo4j_sips_models, path: "../neo4j_sips_models"}]
end

Then add the neo4j_sips_models dependency the applications list:

def application do
  [applications: [:logger, :neo4j_sips_models]]
end

Edit the config/config.exs and describe a Neo4j server endpoint, example:

config :neo4j_sips, Neo4j,
  url: "http://localhost:7474",
  pool_size: 5,
  max_overflow: 2,
  timeout: 30

Run mix do deps.get, deps.compile

If your server requires basic authentication, add this to your config file:

basic_auth: [username: "foo", password: "bar"]

Or:

token_auth: "bmVvNGo6dGVzdA==" # if using an authentication token?!

Usage

You can easily define your own Neo4j Models like this:

defmodule Person do
  use Neo4j.Sips.Model

  field :name, required: true
  field :email, required: true, unique: true, format: ~r/\b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}\b/
  field :age, type: :integer
  field :doe_family, type: :boolean, default: false # used for testing
  field :neo4j_sips, type: :boolean, default: true

  validate_with :check_age

  relationship :FRIEND_OF, Person
  relationship :MARRIED_TO, Person

  def check_age(model) do
    if model.age == nil || model.age <= 0 do
      {:age, "model.validation.invalid_age"}
    end
  end
end

and use in various scenarios. Example from various tests file:

assert {:ok, john} = Person.create(name: "John DOE", email: "[email protected]",
                                   age: 30, doe_family: true,
                                   enable_validations: true)
assert john != nil
assert {:ok, jane} = Person.create(name: "Jane DOE", email: "[email protected]",
                                   age: 25, enable_validations: true, doe_family: true,
                                   married_to: john)
on_exit({john, jane}, fn ->
    assert :ok = Person.delete(john)
    assert :ok = Person.delete(jane)
  end)

...

# model find
test "find Jane DOE" do
  persons = Person.find!(name: "Jane DOE")
  assert length(persons) == 1

  person = List.first(persons)
  assert person.name == "Jane DOE"
  assert person.email == "[email protected]"
  assert person.age == 25
end

test "find John DOE" do
  persons = Person.find!(name: "John DOE")
  assert length(persons) == 1

  person = List.first(persons)
  assert person.name == "John DOE"
  assert person.email == "[email protected]"
  assert person.age == 30
end

...

# serialization
Person.to_json(jane)  

# support for relationships
relationship_names = Person.metadata.relationships |> Enum.map(&(&1.name))
relationship_related_models = Person.metadata.relationships |> Enum.map(&(&1.related_model))
assert relationship_names == [:FRIEND_OF, :MARRIED_TO]
assert relationship_related_models == [Person, Person]

...

#support for validation
test "invalid mail format" do
  {:nok, nil, person} = Person.create(name: "John Doe", email: "johndoe.example.com", age: 30)
  assert Enum.find(person.errors[:email], &(&1 == "model.validation.invalid")) != nil
end

test "invalid age value" do
  {:nok, nil, person} = Person.create(name: "John Doe", email: "[email protected]", age: -30)
  assert Enum.find(person.errors[:age], &(&1 == "model.validation.invalid_age")) != nil
end


## and more

For more examples, see the test suites.

Contributing

To contribute you need to compile Mongo.Ecto from source and test it:

$ git clone https://github.com/florinpatrascu/neo4j_sips_models
$ cd neo4j_sips_models
$ mix test

Special thanks

This project is based on the work started by: Rawane ZOSSOU. Thank you, @raw1z!

License

  • Neo4j.Sips.Model - MIT, check LICENSE file for more information.
  • Neo4j - Dual free software/commercial license, see http://neo4j.org/

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory