Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/betrybe/neo4_ecto
Neo4j Adapter for Ecto
https://github.com/betrybe/neo4_ecto
ecto-adapter elixir hacktoberfest
Last synced: about 1 month ago
JSON representation
Neo4j Adapter for Ecto
- Host: GitHub
- URL: https://github.com/betrybe/neo4_ecto
- Owner: betrybe
- License: apache-2.0
- Created: 2021-04-16T19:34:26.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-19T16:49:42.000Z (11 months ago)
- Last Synced: 2024-10-30T00:34:11.247Z (about 2 months ago)
- Topics: ecto-adapter, elixir, hacktoberfest
- Language: Elixir
- Homepage: https://hex.pm/packages/neo4_ecto
- Size: 43 KB
- Stars: 59
- Watchers: 11
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Neo4Ecto
Neo4Ecto is an Ecto adapter that sits on top of [Bolt.Sips](https://github.com/florinpatrascu/bolt_sips) driver.
It allows you to deal with a [Neo4j](http://neo4j.com) database through Ecto.
Check out the ([documentation](https://hex.pm/packages/neo4_ecto))
## Installation
Add the lib to your `mix.exs`
```elixir
def deps do
[
{:neo4_ecto, "~> 0.0.2"}
]
end
```run: `mix dep.get`
setup your database config:
```elixir
# config/dev.exsconfig :my_app, ecto_repos: [MyApp.Repo]
config :my_app, MyApp.Repo,
hostname: "localhost",
basic_auth: [username: "neo4j", password: "neo4j"],
pool_size: 5# lib/my_app/repo.ex
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapters.Neo4Ecto
end
```## Usage
It's currently available the following Ecto modules: [Schema, Changeset, Repo]
For example:
```elixir
# lib/my_app/accounts/user.ex
defmodule Accounts.User do
use Ecto.Schema
import Ecto.Changesetschema "user" do
field :name, :string
enddef changeset(user, attrs) do
user
|> cast(attrs, [:name])
end
end# lib/my_app/accounts.ex
defmodule Accounts do
alias Accounts.User
alias MyApp.Repodef create_user(attrs) do
%User{}
|> User.changeset(attrs)
|> Repo.insert()
end
end# lib/my_app/app.ex
defmodule Example.App do
alias Example.Repodef get_user_by_id do
Repo.query("MATCH (u:User {id: $user_id}) RETURN u;", %{user_id: 1})
enddef get_user_followers! do
Repo.query!("MATCH (u:User)-[:FOLLOWS]->(:User {id: $user_id}) RETURN u;", %{user_id: 1})
end
end
```## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.Please make sure to update tests as appropriate.
## Running containerized tests with Earthly
It is also possible to run tests under a containerized environment using [earthly](https://earthly.dev/get-earthly):
$ earthly -P +setup-code-check
$ earthly -P +test-neo4ectoYou can also use this to interactively debug any tests with diferent images of Neo4j and Elixir.
$ earthly -P -i --build-arg ELIXIR_BASE=1.12.0-rc.1-erlang-24.0-alpine-3.13.3 +setup-code-check
$ earthly -P -i --build-arg ELIXIR_BASE=1.8.2-erlang-20.3.8.26-alpine-3.11.6 --build-arg NEO4J=4.1 +test-neo4ecto## Copyright and License
The source code is under the Apache 2 License.
Copyright (c) 2021 Trybe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.