A second connection made from the first - #21
Merged
Merged
Conversation
duplicate() is another connection to the same database, made from a connection rather than from a path, which is how a pool is written. It forks off the database the connection already holds rather than opening the file again, so it costs a schema load and no path lookup, and it works on a database in memory, where there is no path to open a second time. Each of the two has its own prepared statements, its own caches and its own transaction, and closing one does not close the other. What they share is the write side. Two of them also read at once, where two statements on one connection queue, which is the other reason to reach for this. The switches come across, including bigIntMode and temporal, because a pool handing out connections that answered differently from the one it was seeded with would be a trap. Other clients spell this call cursor(), after the way every embedded database has spelled it for thirty years. That name is taken here by the cursor over the rows of one statement, so this one says what it does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Milestone tamnd/zu#169, item 6:
cursor()in both clients, which is how a pool is written. The engine half is tamnd/zu#409 and the Python half is tamnd/zu-python#28, and this pins the engine.conn.duplicate()gives back anotherConnectionon the same database. The name is notcursor()here, which is what the other clients call it:conn.cursor()in this client is already a cursor over the rows of one statement, and a different thing entirely, so this one says what it does. The README says so where a reader coming from Python will look.It forks off the database the connection already holds rather than opening the file again, so it costs a schema load and no path lookup, and it works on a database in memory, where there is no path to open a second time. That was the gap worth closing: a pool that seeds itself and lets the first connection go had no way to a second one at all.
The two are connections in every sense rather than two names for one. Each has its own prepared statements, its own caches and its own transaction, so a task taking one from a pool is not in whatever transaction the last borrower left open, and closing one does not close the other. What they share is the write side, so they queue behind each other to write and each sees what the other has committed. Two of them read at once, where two statements on one connection queue, and there is a test that runs a pair through
Promise.all.It is a task like every other call that reaches the engine, because a schema load on the runtime's thread is the loop stopped for the length of one. The switches come across, including
bigIntModeandtemporal, and there is a test that a duplicate of abigIntMode: 'number'connection still answers numbers.Eight tests: the pool case both ways, the properties carried across, a duplicate outliving the connection it was made from, a transaction of its own, the spelling carried across, two reading at once, a closed connection refused by name, and
await usingon a duplicate. Plus the README program.npm test,npm run check:types,npm run check:api,cargo clippy -- -D warningsandcargo fmt --checkall green locally.