Benjamin-Philip

Benjamin-Philip

Turxo - bindings to the Turso database

Announcing Turxo! Turxo is a library (hex, git repo) for bindings to the Turso database, a SQLite compatible in-process database written in Rust. It has a number of new features over SQLite like multi-version concurrency control (MVCC), io_uring backed async I/O, edge replication, vector support and more. Turxo is the first step towards bringing these improvements to the Elixir ecosystem.

As of now we support the following operations:

  • Open or create a Turso database, including in-memory databases
  • Connect to an open database
  • Execute SQL commands or perform queries on a connection
  • Prepare reusable SQL statements, then execute or query them

Here’s a rough example copied from the README:

alias Turxo.NIF.Wrapped, as: Turso

# Open an in-memory database
{:ok, db} = Turso.db_open(":memory:")

# Establish a connection
{:ok, conn} = Turso.db_connect(db)

# Execute SQL (no parameters)
{:ok, 0} =
  Turso.conn_execute(
    conn,
    "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)",
    []
  )

# Insert using positional parameters
{:ok, 1} =
  Turso.conn_execute(conn, "INSERT INTO users (name, email) VALUES (?1, ?2)", [
    "alice",
    "alice@example.com"
  ])

# Query with positional parameters
{:ok, [["alice@example.com"]]} =
  Turso.conn_query(conn, "SELECT email FROM users WHERE name = (?1)", ["alice"])

# Prepare a statement
{:ok, stmt} =
  Turso.conn_prepare(conn, "INSERT INTO users (name, email) VALUES (:name, :email)", false)

# Execute the prepared statement with named parameters
{:ok, 1} = Turso.stmt_execute(stmt, name: "bob", email: "bob@example.com")

# Query with named parameters
{:ok, [["bob@example.com"]]} =
  Turso.conn_query(conn, "SELECT email FROM users WHERE name = (:name)", name: "bob")

# Prepare a statement for querying
{:ok, qstmt} = Turso.conn_prepare(conn, "SELECT id, name FROM users", false)
{:ok, rows} = Turso.stmt_query(qstmt, [])
# rows = [[1, "alice"], [2, "bob"]]

As you can see, the Turxo v0.1.0 release is at a very early state with only the raw Rust bindings and lacking in docs. I decided to release it nonetheless to make it available to the public for feedback. Here are the immediate features I have on the Roadmap (PRs welcome!):

  • Transactions
  • DBConnection integration
  • Pragmas

Particularly, I would appreciate any help in overhauling my test suite to something more robust and comprehensive than the handwritten example-like test I have now.

I also plan to write Ecto and Ash adapters in separate repositories.

Let me know any feedback you may have.

Most Liked

glauber

glauber

Hello! This is really good. I am the creator of Turso

Any reason why you wouldn’t submit this to the Turso tree? We’ve been keeping the bindings in tree, and that helps a lot with regression tests, making sure features are added to new drivers, etc.

Benjamin-Philip

Benjamin-Philip

Hi Glauber, welcome to Elixirforum!

When I started the project, I didn’t think about it too deeply. Culturally in the Erlang/Elixir ecosystem, we tend to keep bindings/implementations within the Elixir community. In the case of databases, almost none of the database drivers (see the Ecto project) have been upstreamed. There’s a similar pattern with message queue adapters (see the Broadway project), gRPC, Protobuf and even generally in smaller libraries. I’m not sure why this is the accepted practice, but my decision to build outside of the Turso tree is very much just me following established norms. Though, recently I have been trying to change this with my work upstreaming the Erlang implementation of Apache Arrow to the ASF.

However, I’m happy to upstream this to Turso if you’re interested. I think that first party status is generally better for the quality and health of the project.

My original motivations for writing this library do partially clash with upstreaming though. As a young student, I approached this as a learning exercise, not because I needed to use Turso, whilst still addressing a genuine gap in the community. The learning was partially technical, but my primary motivation was to learn what was involved in being a maintainer. Things like:

  • Release processes
  • Handling issues and PRs
  • Maintaining code quality in contributions
  • Growing a userbase as well as contributors

My thought was building something production-grade myself would expose me to these responsibilities. My worry with upstreaming is that I would learn less about maintenance since most of the load would be handled by the Turso team.

That said, I still think upstreaming is what’s best for the library. Maybe if we can come to some understanding over the level of oversight I would have if I were to upstream, perhaps we can work something out.

You’ve clearly not looked at the code. I personally don’t consider it release worthy as-is, and I am quite disgusted with myself over the lack of documentation. It was only after my dad convinced me that a release was more meaningful and useful than a lone git repo, that I released a v0.1.0.

dimitarvp

dimitarvp

I am super close to officially releasing and announcing Xqlite — Xqlite v0.10.0 and now I wonder whether we should join forces and have one adapter that can “quack” multiple breeds of SQLite3. Had my eye on Turso for a long time and almost lost hope they’ll come through. Thanks for the confirmation, @glauber!

Last Post!

DVS_Labs

DVS_Labs

There’s also EctoLibSql based on libSQL. Slightly different to targeting Turso but could still be interesting to some.

Where Next?

Popular in Announcing Top

Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Thank...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19951 141
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 19610 194
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
zoltanszogyenyi
Hey everyone :waving_hand: Excited to join this forum - I am one of the founders and current project maintainers of a popular and open-s...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement