c4lliope
Hello! I think the Rust [sparrowdb] crate is a superb choice for modern graph dbs; I’m hoping to package this up in an elixir pkg.
[sparrowdb]: crates.io: Rust Package Registry
Here’s the sample code from their README:
let db = GraphDb::open(std::path::Path::new("social.db"))?;
db.execute("CREATE (alice:Person {name: 'Alice', age: 30})")?;
db.execute("CREATE (bob:Person {name: 'Bob', age: 25})")?;
db.execute("MATCH (a:Person {name:'Alice'}), (b:Person {name:'Bob'}) CREATE (a)-[:KNOWS]->(b)")?;
// Who does Alice know? Who do *they* know?
let fof = db.execute("MATCH (a:Person {name:'Alice'})-[:KNOWS*1..2]->(f) RETURN DISTINCT f.name")?;
// -> [["Bob"], ["Carol"]] (Carol is a friend-of-friend)
let _ = fof;
Ok(())
I can think of some simple changes to make this more approachable as an elixir module. Primarily, loading the db variable should be done in one function call, and each call to execute should be another function call.
I’ve come across this in another rust db package; how does one keep a reference to a rust object, such as db, loaded from a rustler function call? How do future rustler-bound functions refer to the same rust object (db) without leaking or cleaning up the memory address?
I’m new to Rust so I probably need to learn some lifetime attribute concepts. If there are common themes from other rustler packages that I can learn from, I’d be thrilled to find something that I can repurpose across the language boundary.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #iex
- #graphql
- #elixirconf-us
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kevinschweikert
That’s a
resourcein rustler. Have a look at this thread: Rustler return and pass reference from Rust to Elixir and back to Rustc4lliope
At the risk of forking another thread to discuss the same problem, I’m including my progress from today. There seems to have been a bunch of discussion on this before!
In my case, I’m bouncing between two different errors as I decide if I need to
impl Resourceor if I need to make a new type that mimicsGraphDbwith the necessary trait (seems likely).base code:
I may be soooooo off here, this is a hodgepodge from combining examples.
Then, if I include this
impl Resource, the error changes:kevinschweikert
The
rustlerAPI seems to have changed a bit. Functions now get auto registered when defining the#[rustler::nif]macro.You can only define traits for structs when you either define the trait or define the struct. But here the trait is defined by
rustlerand the struct defined bysparrowdb. So we have to wrap it in our own type.rustleralso converts aResulttype automatically to a tagged tuple in Elixir. Either{:ok, _}or{:error, _}.With the example from the
sparrowdbREADME:Happy hacking!
c4lliope
Amazing! I copied your code and was able to spin it up on a greyhound bus. I found a helpful example also in ryugraph_ex, and I’m bringing in pieces that seem useful.
sparrowseems to miss some of the cypher spec, so I could perhaps make a benchmark using the opencypher cucumber specs. I’d like to also produce a Neo4j-compatible harness, to make use of their explorer and visualization ecology.For people going through the same burrow, my first rabbit hole with rust embedded databases was
fjallcrates.io: Rust Package Registry - I assume this approach will be useful there also.