Mach Database for PostgreSQL examples
MachSQL speaks the PostgreSQL, MySQL and SQL Server (TDS) protocols on the server side (docs/ZERO-MIGRATION.md, docs/FRONTENDS.md). Every example below is an ordinary program for the original database with its usual driver or ORM. Moving it to MachSQL is a one-line change of the host in the connection string:
DATABASE_URL=postgres://app:${DB_PASSWORD}@old-postgres:5432/appDATABASE_URL=postgres://app:${DB_PASSWORD}@machsql-host:5432/appNo new library, no driver change, no code change, no SQL change. machsql-host is any MachSQL node, a load balancer, the MachSQL router or a DNS name in front of a cluster (docs/SCALING.md).
Every example connects, creates a small todo table if it does not exist, inserts a row and counts open rows, printing inserted todo <id>, <n> open. Passwords come from the environment, never from files. The examples are tested against every release by the EXM backlog area (plan/tasks/28-examples.md); they are not run on development machines (no local database servers).
| Example | Stack | Protocol | Versions |
|---|---|---|---|
| python-psycopg | Python: psycopg | PostgreSQL | Python 3.15, psycopg 3.3.6 |
| python-sqlalchemy | Python: SQLAlchemy | PostgreSQL | Python 3.15, SQLAlchemy 2.1.6, psycopg 3.3.6 |
| python-django | Python: Django ORM | PostgreSQL | Python 3.15, Django 6.1.2, psycopg 3.3.6 |
| node-pg | Node.js / TypeScript: pg | PostgreSQL | Node.js 26 LTS, pg 8.23.1, TypeScript 7.0.2, tsx 4.23.15 |
| node-prisma | Node.js / TypeScript: Prisma | PostgreSQL | Node.js 26 LTS, Prisma 7.10.1 with @prisma/adapter-pg 7.10.1, TypeScript 7.0.2, tsx 4.23.15 |
| go-pgx | Go: pgx | PostgreSQL | Go 1.27, pgx v5.11.0 |
| go-database-sql | Go: database/sql | PostgreSQL | Go 1.27, pgx v5.11.0 (stdlib driver) |
| java-jdbc | Java: JDBC | PostgreSQL | Java 25 (LTS), PostgreSQL JDBC driver 42.7.14, Maven (compiler plugin 3.16.0, exec plugin 3.6.4) |
| java-spring-boot | Java: Spring Boot, Spring Data JPA, Hibernate | PostgreSQL | Java 25 (LTS), Spring Boot 4.1.2 (Hibernate ORM 7 and the PostgreSQL JDBC driver from its dependency management) |
| dotnet-npgsql | C# / .NET: Npgsql | PostgreSQL | .NET 10, Npgsql 10.0.3 |
| dotnet-efcore | C# / .NET: Entity Framework Core | PostgreSQL | .NET 10, Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3 (EF Core 10) |
| php-pdo | PHP: PDO (pgsql) | PostgreSQL | PHP 8.5 with the pdo_pgsql extension |
| php-laravel | PHP: Laravel (Eloquent) | PostgreSQL | PHP 8.5 with pdo_pgsql, illuminate/database 13.39 (the database layer of Laravel 13) |
| ruby-pg | Ruby: pg | PostgreSQL | Ruby 4.0, pg 1.7.0 |
| ruby-activerecord | Ruby: Rails Active Record | PostgreSQL | Ruby 4.0, activerecord 8.1.4 (Rails 8.1), pg 1.7.0 |
| rust-sqlx | Rust: sqlx | PostgreSQL | Rust (latest stable, edition 2024), sqlx 0.9.0, tokio 1.54.1 |
| rust-tokio-postgres | Rust: tokio-postgres | PostgreSQL | Rust (latest stable, edition 2024), tokio-postgres 0.7.18, tokio 1.54.1 |
| kotlin-jdbc | Kotlin: JDBC | PostgreSQL | Kotlin 2.4.21 on Java 25 (LTS), PostgreSQL JDBC driver 42.7.14, Gradle 9.8 |
| elixir-ecto | Elixir: Ecto | PostgreSQL | Elixir 1.20 on Erlang/OTP 29, ecto_sql 3.14, postgrex 0.22 |
| python-mysqlclient | Python: mysqlclient (MySQL) | MySQL | Python 3.15, mysqlclient 2.3.0 |
| node-mysql2 | Node.js / TypeScript: mysql2 (MySQL) | MySQL | Node.js 26 LTS, mysql2 3.24.6, TypeScript 7.0.2, tsx 4.23.15 |
| go-mysql | Go: go-sql-driver/mysql (MySQL) | MySQL | Go 1.27, go-sql-driver/mysql v1.10.1 |
| java-mysql | Java: MySQL Connector/J | MySQL | Java 25 (LTS), MySQL Connector/J 26.10.0, Maven (compiler plugin 3.16.0, exec plugin 3.6.4) |
| dotnet-mysqlconnector | C# / .NET: MySqlConnector (MySQL) | MySQL | .NET 10, MySqlConnector 2.6.2 |
| php-pdo-mysql | PHP: PDO (mysql) | MySQL | PHP 8.5 with the pdo_mysql extension |
| python-pyodbc | Python: pyodbc (SQL Server / TDS) | TDS | Python 3.15, pyodbc 5.3.0, Microsoft ODBC Driver 18 for SQL Server (or newer) |
| dotnet-sqlclient | C# / .NET: Microsoft.Data.SqlClient (SQL Server / TDS) | TDS | .NET 10, Microsoft.Data.SqlClient 7.1.1 |
Conventions
Section titled “Conventions”- Dependencies are pinned to the latest stable versions at the time of writing;
EXM-0004keeps them current. - PostgreSQL examples need a database created with the PostgreSQL dialect, MySQL examples one with the MySQL dialect, TDS examples one with the T-SQL dialect.
- Multi-host and read/write split connection strings that drivers already support (libpq
target_session_attrs, pgJDBCtargetServerType, Connector/Jloadbalance, SqlClientApplicationIntent=ReadOnly) work the same way: see docs/SCALING.md, “Connection strings drivers already support”.
All examples
Section titled “All examples”| Protocol | Language | Example |
|---|---|---|
| MySQL | C# / .NET (mysqlconnector) | C# / .NET: MySqlConnector (MySQL) |
| MySQL | Go (mysql) | Go: go-sql-driver/mysql (MySQL) |
| MySQL | Java (mysql) | Java: MySQL Connector/J |
| MySQL | Node.js / TypeScript (mysql2) | Node.js / TypeScript: mysql2 (MySQL) |
| MySQL | PHP (pdo-mysql) | PHP: PDO (mysql) |
| MySQL | Python (mysqlclient) | Python: mysqlclient (MySQL) |
| PostgreSQL | C# / .NET (efcore) | C# / .NET: Entity Framework Core |
| PostgreSQL | C# / .NET (npgsql) | C# / .NET: Npgsql |
| PostgreSQL | Elixir (ecto) | Elixir: Ecto |
| PostgreSQL | Go (database-sql) | Go: database/sql |
| PostgreSQL | Go (pgx) | Go: pgx |
| PostgreSQL | Java (jdbc) | Java: JDBC |
| PostgreSQL | Java (spring-boot) | Java: Spring Boot, Spring Data JPA, Hibernate |
| PostgreSQL | Kotlin (jdbc) | Kotlin: JDBC |
| PostgreSQL | Node.js / TypeScript (pg) | Node.js / TypeScript: pg |
| PostgreSQL | Node.js / TypeScript (prisma) | Node.js / TypeScript: Prisma |
| PostgreSQL | PHP (laravel) | PHP: Laravel (Eloquent) |
| PostgreSQL | PHP (pdo) | PHP: PDO (pgsql) |
| PostgreSQL | Python (django) | Python: Django ORM |
| PostgreSQL | Python (psycopg) | Python: psycopg |
| PostgreSQL | Python (sqlalchemy) | Python: SQLAlchemy |
| PostgreSQL | Ruby (activerecord) | Ruby: Rails Active Record |
| PostgreSQL | Ruby (pg) | Ruby: pg |
| PostgreSQL | Rust (sqlx) | Rust: sqlx |
| PostgreSQL | Rust (tokio-postgres) | Rust: tokio-postgres |
| SQL Server (TDS) | C# / .NET (sqlclient) | C# / .NET: Microsoft.Data.SqlClient (SQL Server / TDS) |
| SQL Server (TDS) | Python (pyodbc) | Python: pyodbc (SQL Server / TDS) |