A read-only database/sql driver for Microsoft Access databases (.mdb and .accdb) written in Go. No Microsoft software, ODBC drivers, or OLE DB providers required.
mdbgo provides two drivers — a pure Go implementation and a CGo-based implementation backed by mdbtools.
| Driver | Name | Backend | C compiler | Speed | Memory |
|---|---|---|---|---|---|
| Pure Go | "gomdb" |
driver/gomdb |
No | Faster | ~45 KB/op |
| CGo | "cmdb" |
driver/cmdb |
zig cc |
Fast | ~2 KB/op |
Both drivers are feature-equivalent and produce identical results — verified across 32,549 rows over 5 databases with 0 value differences.
Note: Both drivers are read-only — querying existing Access databases only, no writes.
- Standard
database/sqlinterface - Full sqlx compatibility (
StructScan,Select,Get,Namedqueries) - Reads MDB (Jet 3/4) and ACCDB files
- No dependency on Microsoft Access, ACE/Jet OLE DB, or ODBC
- SQL queries:
SELECT,WHERE,ORDER BY,LIMIT,LIST TABLES,DESCRIBE TABLE - Parameterized queries with
?placeholders - All 15 Access column types with
sql.Null*support - Full column metadata (
ColumnTypeDatabaseTypeName,ColumnTypeLength,ColumnTypeScanType) - Unicode support (CJK, Arabic, etc.)
- Binary data and OLE object reading
- DateTime handling with
time.Time - LIKE pattern matching with Chinese/Unicode text
go get github.com/Felamande/mdbgoNo C toolchain needed:
CGO_ENABLED=0 go buildRequires a C compiler. zig cc recommended:
CC="zig cc" CGO_ENABLED=1 go buildNo external C libraries needed — mdbtools is compiled in-tree.
import (
"database/sql"
_ "github.com/Felamande/mdbgo/driver/gomdb" // pure Go
// _ "github.com/Felamande/mdbgo/driver/cmdb" // or CGo
)
db, _ := sql.Open("gomdb", "path/to/database.mdb") // or "cmdb"
// Query with parameters
rows, _ := db.Query("SELECT ID, Name, Birthday FROM Users WHERE Age > ?", 18)
// sqlx struct scanning
type User struct {
ID int64 `db:"ID"`
Name string `db:"Name"`
Birthday time.Time `db:"Birthday"`
}
var users []User
sqlxDB.Select(&users, "SELECT * FROM Users")rows, _ := db.Query("LIST TABLES")rows, _ := db.Query("DESCRIBE TABLE MyTable")| Access Type | Go Type | DatabaseTypeName() |
|---|---|---|
| Boolean | bool |
"Boolean" |
| Byte | int64 |
"Byte" |
| Integer | int64 |
"Integer" |
| Long Integer | int64 |
"Long Integer" |
| Currency | float64 |
"Currency" |
| Single | float64 |
"Single" |
| Double | float64 |
"Double" |
| DateTime | time.Time |
"DateTime" |
| Text | string |
"Text" |
| Memo | string |
"Memo/Hyperlink" |
| Binary | []byte |
"Binary" |
| OLE Object | []byte |
"OLE" |
| Replication ID | string |
"Replication ID" |
| Numeric | string |
"Numeric" |
| Complex | int64 |
— |
- Read-only — no INSERT, UPDATE, DELETE, or DDL operations
- No transactions —
Begin()not supported - Client-side parameter interpolation —
?placeholders are escaped and interpolated into the SQL string - BIT/Boolean NULL — Access BIT fields cannot store NULL; NULL coerces to FALSE
- TEXT length — Unicode TEXT(n) columns report byte length (2×n)
- No
IN (...)syntax — use multipleORconditions instead - Jet SQL only — advanced ACCDB SQL features may not be supported
┌──────────────────────────────────────────────┐
│ Go application / sqlx │
├──────────────────────────────────────────────┤
│ driver/gomdb/gomdb.go driver/cmdb/cmdb.go
│ (pure Go, zero CGo) (CGo + mdbtools) │
├──────────────────────────────────────────────┤
│ internal/gomdb/ internal/cmdb/ │
│ 19 .go files C source + cgo │
└──────────────────────────────────────────────┘
Both backends parse Access database files directly — the pure Go driver is a ground-up port of mdbtools with no C dependencies, while the CGo driver wraps the original C library.
mdbgo/
├── driver/
│ ├── cmdb/ # CGo driver — registers "cmdb"
│ │ └── cmdb.go
│ └── gomdb/ # Pure Go driver — registers "gomdb"
│ └── gomdb.go
├── internal/
│ ├── cmdb/ # CGo backend (bridge + mdbtools C source)
│ └── gomdb/ # Pure Go backend (MDB parser, SQL engine)
├── testdata/ # .mdb test databases
└── temp/ # Comparison harnesses
- Go 1.26+
- CGo driver: C compiler (gcc, clang, or
zig cc) - Pure Go driver: no additional requirements
Go code: MIT License
This project embeds mdbtools under the LGPL-2.0-or-later. See internal/cmdb/mdbtools/COPYING.LIB.