xdal

module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT

README

XDAL

A lightweight, interface-driven database abstraction layer for Go.

Write database-agnostic SQL queries across MySQL, PostgreSQL, SQLite, and SQL Server with a fluent query builder, automatic placeholder translation, identifier quoting, and injectable structured logging.

Install

go get github.com/martinsuchenak/xdal

Quick Example

import (
    "github.com/martinsuchenak/xdal/pkg/mysql"
)

db := mysql.NewMySQLDB(sqlDB, nil)
qb := mysql.NewQueryBuilder()

query, args, err := qb.Select("id", "name").
    From("users").
    Where("active = ?", true).
    OrWhere("role = ?", "admin").
    OrderBy("name").
    Limit(10).
    Build()
if err != nil {
    log.Fatal(err)
}

rows, _ := db.Query(ctx, query, args...)

What It Does

  • Fluent query builder — SELECT, INSERT, UPDATE, DELETE with JOINs, GROUP BY, HAVING, LIMIT/OFFSET, DISTINCT, OR, IN-clause expansion, batch INSERT, and RETURNING
  • Automatic dialect translation — placeholders (? / $1 / @p1), LIMIT/OFFSET vs FETCH NEXT, identifier quoting (backticks / double quotes / brackets)
  • Structured logging — inject any logger matching the Logger interface, or run silently
  • Transaction wrapper — BeginTx returns a *Tx with full logging
  • Extensible — implement the Dialect interface to add new databases without touching shared code

Supported Databases

Database Package Placeholders Quoting
MySQL pkg/mysql ? `backticks`
PostgreSQL pkg/postgres $1, $2, ... "double quotes"
SQLite pkg/sqlite ? "double quotes"
SQL Server pkg/mssql @p1, @p2, ... [brackets]

Documentation

  • Usage Guide — detailed API reference for the query builder, logging, transactions, and dialect system
  • Examples — comprehensive code examples for every feature
  • Contributing — development setup, running tests, and adding new database drivers

License

MIT

Directories

Path Synopsis
pkg
mssql
Package mssql provides a SQL Server driver wrapper for the xdal database abstraction layer.
Package mssql provides a SQL Server driver wrapper for the xdal database abstraction layer.
mysql
Package mysql provides a MySQL driver wrapper for the xdal database abstraction layer.
Package mysql provides a MySQL driver wrapper for the xdal database abstraction layer.
postgres
Package postgres provides a PostgreSQL driver wrapper for the xdal database abstraction layer.
Package postgres provides a PostgreSQL driver wrapper for the xdal database abstraction layer.
sqlite
Package sqlite provides a SQLite driver wrapper for the xdal database abstraction layer.
Package sqlite provides a SQLite driver wrapper for the xdal database abstraction layer.
tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL