Julia’s database story is not “pick an ORM”. It is three separate layers that people keep confusing with each other: a driver that speaks the wire protocol, a query builder that produces SQL, and an ORM that maps rows to structs. Choose the wrong layer and you end up writing string-concatenated SQL in a language that has a compiler capable of checking your types.

Here is the short version of what changed in 2026: LibPQ.jl pushed a commit on 2026-12-05, FunSQL.jl on 2026-12-01, Octo.jl on 2026-09-20 and SearchLight.jl on 2026-10-05 — all four are alive, which was not true two years ago. That makes this a real choice instead of a maintenance gamble.

TL;DR — the quick verdict

Use FunSQL.jl if your queries are dynamic. It builds SQL compositionally, so a filter that only applies when the user picked one gets added as a fragment instead of being bolted onto a string. This is the library for reports, dashboards and anything with optional predicates.

Use Octo.jl if you want Ecto-style structs and CRUD without hand-written SQL. Repo.insert!, Repo.update! and Schema.model give you an object-ish layer over Postgres, SQLite, MySQL and DuckDB.

Use LibPQ.jl if you want a driver you can trust and nothing more. It explicitly refuses to emit SQL, parse SQL or abstract transactions — and that narrowness is why it is the most predictable option for bulk inserts and streaming.

Use SearchLight.jl only inside Genie. It is a competent ORM, but it is scoped to the Genie ecosystem.

If you only remember one line: FunSQL for composing, Octo for CRUD, LibPQ for throughput.

Julia database libraries

The numbers, pulled from GitHub today

DimensionFunSQL.jlOcto.jlLibPQ.jlSearchLight.jl
Stars174170226149
Last commit2026-12-012026-09-202026-12-052026-10-05
LayerQuery builder (SQL)Query DSL + thin repoDriverORM
Emits SQLYes, dialect-awareYesNo, by designYes
Row → struct mappingManual / Tables.jlSchema.model + RepoTables.jl streamYes
DatabasesPostgres, SQLite, MySQL, DuckDB, BigQuery, SparkPostgres, SQLite, MySQL, DuckDBPostgreSQL onlyPostgres, MySQL, SQLite
License (GitHub metadata)other (MIT per README)other (unspecified)MITMIT
TransactionsDBInterface.transactionVia adapterexecute / transactionYes

A note on those license fields: GitHub reports other for FunSQL and Octo, which usually means no machine-detectable license file at the repo root. FunSQL’s README carries an MIT badge; Octo does not declare one prominently. If license hygiene matters to your legal review, read both LICENSE files before you ship.

Decision matrix

Your situationPickWhy
Dashboard with 12 optional filtersFunSQL.jlFragments compose; no string surgery
CRUD admin panel over PostgresOcto.jlRepo covers insert/update/delete with structs
Bulk insert 10M rows from a DataFrameLibPQ.jlBinary COPY and executemany without an ORM in the path
Analytics over Parquet + DuckDBFunSQL.jlDuckDB dialect is supported
Full web app already on GenieSearchLight.jlNative integration, migrations included
Read-only service that streams resultsLibPQ.jlTables.jl streaming, no materialisation
You need MySQL plus structsOcto.jlLibPQ is Postgres-only

FunSQL.jl — SQL as composable data

FunSQL’s pitch is that SQL is hard to write modularly, so the library exposes SQL’s expressive power through composable nodes instead of strings. The canonical example from the README — “when was the last time each person born between 1930 and 1940 in Illinois was seen by a provider?” — reads like a pipeline because it is one:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@funsql begin
    from(person)
    filter(1930 <= year_of_birth <= 1940)
    join(
        from(location).filter(state == "IL").as(location),
        on = location_id == location.location_id)
    left_join(
        from(visit_occurrence).group(person_id).as(visit_group),
        on = person_id == visit_group.person_id)
    select(
        person_id,
        latest_visit_date => visit_group.max(visit_start_date))
end

What makes that useful in application code is the composition, not the syntax. A base query lives in a function, each request-specific predicate is a fragment appended with +, and the final render call produces SQL for the target dialect together with the parameter vector:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
using FunSQL: FunSQL, Agg, SQLTable, From, Get, Where, Select, LeftJoin, render

const person = SQLTable(:person, columns = [:person_id, :year_of_birth, :location_id])

# Reusable base — no SQL string, no interpolation, no escaping bugs.
const base = From(person)

# Request-specific fragment, added only when the filter is present.
adults_only = q -> q + Where(FunSQL.Between(Get.year_of_birth, 1930, 1940))

sql, params = render(adults_only(base), dialect = :postgresql)

Three practical properties follow from the design:

  1. Parameters are generated, not concatenated. You get a params vector back, which is what makes the pattern safe by construction rather than by discipline.
  2. Dialects are a render-time concern. The same pipeline can target PostgreSQL, SQLite, MySQL, DuckDB, BigQuery or Spark — useful when the warehouse and the app database differ.
  3. It does not map rows to structs. You still need DBInterface.execute plus your own conversion, or funnels through Tables.jl. FunSQL is a builder, not an ORM — treating it as an ORM is the most common misuse.

The cost is verbosity. A five-line SQL statement becomes twelve lines of Julia. For a fixed query that never changes, that trade is bad. For a query with optional predicates, it is the difference between a maintainable report layer and a pile of if statements concatenating " AND x = $x".

Octo.jl — Ecto-style structs for Julia

Octo is explicitly influenced by Ecto (Elixir), and it shows: you declare a schema on a struct, then use a query DSL or Repo helpers. The README’s session is the best documentation of the design:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
using Octo.Adapters.SQL

struct User
end

Schema.model(User, table_name = "users")
# primary_key | table_name
# id          | users

u = from(User)
[SELECT * FROM u]
# SELECT * FROM users

[SELECT (u.name, u.salary) FROM u WHERE u.id == 2]
# SELECT name, salary FROM users WHERE id = 2

to_sql([SELECT * FROM u WHERE u.id == 2])
# "SELECT * FROM users WHERE id = 2"

That bracket syntax is the interesting part: [SELECT ... FROM u] is a macro that turns Julia expression syntax into SQL, with to_sql available when you need the string. It is more readable than a chain of function calls for simple statements, and it keeps the query in Julia rather than in a heredoc.

The Repo layer is what makes Octo a candidate for CRUD applications:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
using Octo.Adapters.PostgreSQL

Repo.debug_sql()   # log the SQL Octo generates

Repo.connect(
    adapter = Octo.Adapters.PostgreSQL,
    dbname = "postgresqltest",
    user = "postgres",
)

struct Employee
end

# Repo.get / Repo.insert! / Repo.update! / Repo.delete! work across adapters

Supported drivers, per the README: PostgreSQL (via Postgres.jl), SQLite (via SQLite.jl), MySQL (via MySQL.jl) and DuckDB (via duckdb’s Julia package). That multi-database coverage is Octo’s main advantage over LibPQ — and its main weakness, because each adapter inherits the maturity of the package beneath it.

Pick Octo when your application is CRUD-shaped and you want structs without a full ORM. Do not pick it if you need migrations: there is no Flyway equivalent in this stack, so schema changes stay in SQL files you run yourself.

LibPQ.jl — the driver that refuses to be clever

LibPQ wraps PostgreSQL’s libpq C library and installs it via BinaryBuilder on macOS, Linux and Windows. Its feature list is exactly what a driver should have: connections via DSN or connection string, parameterised queries, asynchronous execution, prepared statements, and streaming results through Tables.jl.

Its non-goals are the most valuable documentation in the repo:

LibPQ.jl will not: parse SQL, emit SQL, provide an interface for handling transactions or cursors, provide abstractions over common SQL patterns.

Read that as a feature. Nothing in LibPQ will rewrite your query, guess your types or hold a transaction open behind your back. You write SQL, you pass parameters, you get a Tables.jl-compatible result:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
using LibPQ, Tables

conn = LibPQ.Connection("dbname=app host=localhost user=app")

result = execute(conn, """
    INSERT INTO events (id, kind, payload)
    VALUES (\$1, \$2, \$3)
""", ["42", "click", "{}"])

# Streaming: iterate instead of materialising the whole result set
for row in Tables.rows(execute(conn, "SELECT * FROM events ORDER BY id"))
    @show row
end

close(conn)

Two things to know before you build on it:

  • It is Postgres-only. That is not a limitation you can work around; it is the point. Asynchronous execution and binary protocol support are Postgres features.
  • Pooling is your job. LibPQ.Connection is a connection, not a pool. Under a web server you need DBInterface plus a pool, or you will open a connection per request and hit max_connections at the worst possible moment.

For bulk loading, LibPQ is the only option here that does not become the bottleneck: prepared statements plus executemany, or Postgres COPY, executed without an ORM translating rows into structs and back.

Where SearchLight fits

SearchLight is Genie’s ORM: models, associations, validations, migrations, all integrated with the framework. If your app already runs Genie, using SearchLight is not a compromise — it is the path of least resistance, and its commit history (last push 2026-10-05) shows it is maintained alongside Genie. Outside Genie, it competes directly with Octo and loses on portability, because Octo covers more drivers with less framework coupling.

Our Julia web frameworks comparison covers the Genie side in detail; if you are not on Genie, treat SearchLight as optional context rather than a candidate.

Pitfalls that bite in production

Do not interpolate values into SQL strings — not even “just this once”. FunSQL hands you a parameter vector for a reason; Octo’s bracket macro exists so you never touch a string; LibPQ’s execute takes parameters explicitly. The one place people break this rule is dynamic ORDER BY clauses. Whitelist column names against a known set instead of interpolating user input.

Connection lifecycle beats query style. All three libraries are fast; none of them manages connections for you in an application server. Decide up front whether you are opening a connection per request, using a pool, or holding a long-lived connection in a worker — and write it in one place.

Dialect differences are real even when the API is uniform. FunSQL will render for six dialects, but LIMIT/OFFSET, date arithmetic and window function support still diverge. If you support two databases, test the generated SQL against both in CI rather than assuming the builder normalises everything.

Octo’s adapter quality tracks the driver below it. If a driver is stale, the adapter inherits the staleness. Pin versions in Project.toml and read the adapter’s test suite before you trust it with money or audit data.

Bulk operations need a different code path. The ORM path is optimised for one row at a time. Loading a CSV into a table through Repo.insert! in a loop is the classic 100x slowdown; drop to COPY or executemany for anything above a few thousand rows.

Testing this locally is a two-container compose file, and you should keep it in the repo so the choice is reproducible:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
services:
  db:
    image: postgres:17-alpine
    environment:
      POSTGRES_PASSWORD: app
      POSTGRES_DB: app
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      retries: 10

  analytics:
    image: duckdb/duckdb:latest
    entrypoint: ["duckdb", "/data/warehouse.db"]
    volumes:
      - ./data:/data

FAQ

Which Julia database library is fastest?

For raw insert and select throughput, LibPQ.jl wins because it is a thin wrapper over libpq with no row-to-struct translation and support for prepared statements and COPY. FunSQL and Octo both generate SQL that runs on the same engine, so their overhead is in query construction, not execution — measurable at millions of calls, irrelevant at thousands.

Is FunSQL.jl an ORM?

No. FunSQL is a compositional SQL query builder: it produces SQL text and parameters for a chosen dialect. It does not map rows to Julia structs, does not manage schema and does not provide a repository abstraction. If you need object mapping, pair it with your own conversion layer, use Octo.jl, or use SearchLight inside Genie.

Can Octo.jl talk to MySQL and SQLite, or only PostgreSQL?

The README lists four adapters: PostgreSQL (via Postgres.jl), SQLite (via SQLite.jl), MySQL (via MySQL.jl) and DuckDB (via duckdb’s Julia package). That multi-database coverage is the main reason to choose Octo over LibPQ, which is deliberately PostgreSQL-only.

Does LibPQ.jl handle transactions?

LibPQ does not provide a transaction abstraction as part of its non-goals — it will not manage cursors or wrap your work in a transaction for you. You issue BEGIN, COMMIT and ROLLBACK as SQL through execute, or use DBInterface.transaction around your statements. This is intentional: the driver refuses to be clever about state.

How do I avoid SQL injection in Julia database code?

Never build SQL by interpolating values. Use parameterised execution: LibPQ’s execute(conn, sql, params), FunSQL’s rendered parameter vector, or Octo’s bracket macro. Arbitrary fragments such as column names or sort direction cannot be parameterised, so validate them against an allowlist before inclusion.

Do I need a separate migration tool?

Yes, for anything beyond prototypes. Octo and LibPQ do not ship migrations, and SearchLight’s migration support is tied to Genie. The pragmatic pattern in the Julia ecosystem is plain .sql migration files applied in order by a small runner script and tracked in a schema_migrations table — the same approach used by Flyway and Sqitch in other ecosystems. Our Clojure database libraries comparison shows the same split between query DSLs and migration tooling.


💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com