Comments (1)
Nope, you got it right 😄
When you call Bolt.Sips.conn
, there is indeed a new connection created, provided there are available slots (in the pool) - one of the ways, in Elixir, we limit the consumers, otherwise you can easily exhaust the server resources (and yours too) if you allow concurrent processes to run arbitrarily.
People are often asking me: "-Hey, in Java we have a session for stuff like this!" Not here, not needed (most of the time). If you want to reuse a conn (if it's expensive?) then simply reuse it! Same thing happens in Phoenix - via the Plug.Conn; you pass around the connection until you're done with it.
conn = Bolt.Sips.conn
my_awesome_method(conn)
my_very_cool_method(conn)
# and so on
For example, it is very important to reuse the Bolt.Sips connection, when planning to use transactions! Example:
test "commit statements in an open transaction" do
try do
conn = Bolt.Sips.begin(Bolt.Sips.conn)
book = Bolt.Sips.query(conn, "CREATE (x:XactCommit {foo: 'bar'}) return x")
assert {:ok, [row]} = book
assert row["x"].properties["foo"] == "bar"
# Main connection should not see this new node.
{:ok, results} = Bolt.Sips.query(Bolt.Sips.conn, "MATCH (x:XactCommit) RETURN x")
assert is_list(results)
assert Enum.count(results) == 0,
"Main connection should not be able to see transactional changes"
# Now, commit...
Bolt.Sips.commit(conn)
# And we should see it now with the main connection.
{:ok, [%{"x" => node}]} = Bolt.Sips.query(Bolt.Sips.conn, "MATCH (x:XactCommit) RETURN x")
assert node.labels == ["XactCommit"]
assert node.properties["foo"] == "bar"
after
# Delete any XactCommit nodes that were succesfully committed!
Bolt.Sips.query(Bolt.Sips.conn, "MATCH (x:XactCommit) DETACH DELETE x")
end
end
Anyway, that's the story of it. Bolt.Sips is simple, as advertised.
I am open to accept PRs implementing different pools, if you find one where is happening what you need (see: fishcakez/connection, as a possible example) but even then you'll have to manage the pool in your own client code i.e.close(conn)
, Session.close(conn)
and so on. And you'll still have to pass the connection/session/etc around, to reuse it, as you know.
HTH
Florin
from bolt_sips.
Related Issues (20)
- Config field for `timeout` not reflected in query timeouts HOT 12
- Just need some clarity about Bolt.Sips.conn
- Connection difficulty -- Bolt.Sips.Internals.Error Port #Port<0.n> is closed HOT 7
- Connection loses after a while: ** (Bolt.Sips.Exception) Port {:sslsocket, {:gen_tcp, #Port<0.25>, :tls_connection, :undefined}, [#PID<0.2789.0>, #PID<0.2786.0>]} is closed HOT 5
- Is routing mode enabled with neo4j+s protocol? HOT 6
- Prepared statements for queries when not possible to use parameters HOT 3
- Looking for new maintainers HOT 10
- Neo4j version 4 support HOT 5
- Going forward HOT 5
- Consistent bad connection state after malformed query: "... You need to\n`ACK_FAILURE` or `RESET` ..." HOT 7
- Road to neo4j 4 and streaming HOT 5
- Bolt.Sips.Protocol disconnected: ** (DBConnection.ConnectionError) HOT 13
- Unable to connect when using authentication HOT 14
- No write operations are allowed directly on this database. Writes must pass through the leader. The role of this server is: FOLLOWER HOT 3
- Hiding credentials in `Bolt.Sips.info`? HOT 3
- Request: guidance on parameterized queries HOT 4
- Response.profile is empty with a query with "PROFILE"
- (Bolt.Sips.Exception) unable to encode value: -128 HOT 1
- Outgoing SSL connection hangs, cannot be dropped and re-established HOT 2
- Feature request: auto reconnect HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bolt_sips.