• Stars
    star
    6
  • Rank 2,456,300 (Top 50 %)
  • Language
    Elixir
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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/

More Repositories

1

bolt_sips

Neo4j driver for Elixir
Elixir
256
star
2

micro

a modular micro MVC framework for Java web applications
Java
86
star
3

neo4j_sips

Elixir driver for the Neo4j graph database server
Elixir
81
star
4

movies_elixir_phoenix

Neo4j with Elixir, Phoenix and Neo4j.Sips - The Movies Example Application
Elixir
37
star
5

closure_table

Closure Table for Elixir - a simple solution for storing and manipulating complex hierarchies.
Elixir
28
star
6

bolt_movies_elixir_phoenix

A very simple web application using Neo4j with Elixir, Phoenix, and: Bolt.Sips; an Elixir driver for Neo4j’s Bolt newest network protocol.
Elixir
20
star
7

vscode-elixir-snippets

Elixir code snippets for VS Code
18
star
8

elixir_grafana_loki_tempo

A very simple Elixir demo/project used for experimenting with Grafana Tempo and Loki #opentelemetry #observability #tracing
Elixir
12
star
9

libcluster_gig

A libcluster strategy for Google Managed Instance Groups
Elixir
10
star
10

jrack

a port of Rack to Java
Java
8
star
11

jpublish

JPublish provides a powerful system for managing your web site's content as well as your web site's application logic.
Java
7
star
12

micro-examples

Examples of web applications or deployment solutions using the Micro MVC framework
Java
5
star
13

fixex

support for integrating ExUnit with external apps/cli, as external fixtures providers, or for mimicking external services
Elixir
4
star
14

Sinatra-HART

A Sinatra Haml, Activerecord, RSPEC and Twitter bootstrap boilerplate, with SimpleCov flavour :)
JavaScript
3
star
15

pomo-chrono

A simple yet versatile stateful jQuery Pomodori countdown timer plugin
JavaScript
2
star
16

silw

a simple ruby gem utility that allows one user to monitor several remote systems, provided he has the proper credentials and the authorization to execute remote commands
Ruby
2
star
17

bpl

A very simple gem to help you track your blood pressure
Ruby
1
star
18

mongo_fe

A simple Sinatra based web front-end that can be used for experimenting and learning MongoDB. It is also a Ruby gem :)
JavaScript
1
star
19

dnsimple_touch

a very simple DNSimple - jQTouch prototype
JavaScript
1
star
20

micro-docs

This is the Documentation web site for the Micro framework; using Micro for publishing.
CSS
1
star
21

google_playground

A repository containing small scripts that I use to manage some GCP infrastructure chores, notes, etc. Mostly Elixir of course =)
Elixir
1
star