queries

module
v0.0.0-...-af08da9 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: GPL-2.0

README

Go Django Queries Documentation

Welcome to the documentation for the go-django-queries package.

While Go-Django tries to do as little as possible with the database, sometimes helper functions make working with models easier.

This library brings Django-style ORM queries to Go-Django, allowing you to:

  • Define models with relationships
  • Compose queries with filters, ordering, limits
  • Use select expressions and annotations

Do note that the queries package is not compatible with the default *sql.DB struct, but rather implements it's own Database interface. Databases must always be opened using drivers.Open(ctx, driverName, dsn).


📁 Documentation Structure


🔧 Quick Example

// Query forward foreign key relation
var todos, err := queries.GetQuerySet(&Todo{}).
    Select("*", "User.*").
    Filter("Done", false).
    OrderBy("-ID").
    All()

// Query reverse foreign key relation
var todos, err := queries.GetQuerySet(&User{}).
    Select("*", "TodoSet.*").
    Filter("TodoSet.Done", false).
    OrderBy("-ID").
    All()

Continue with Getting Started

✅ Supported Features

We try to support as many features as possible, but some stuff is either not supported, implemented or tested yet.

TODO:

  • Implement eficient prefetching of multiple- relations
Tested Databases

But more tests / databases will be added over time.

Caveats
  • MySQL and MariaDB requires both multiStatements and interpolateParams to be true. This is because the driver cannot go-sql-driver/mysql otherwise return multiple result id's in a single query. Without this it is impossible to bulk update or bulk insert.

  • The mariadb driver is a custom driver that supports returning all columns upon creation of an object. It is a wrapper around the go-sql-driver/mysql driver. It can be used by passing mariadb as the driver name to drivers.Open(...), example:

    db, err := drivers.Open("mariadb", "user:password@tcp(localhost:3306)/dbname?multiStatements=true&interpolateParams=true")
    if err != nil {
        log.Fatal(err)
    }
    
The following features are currently supported
  • Selecting fields
  • Selecting forward and reverse relations
  • Filtering
  • Lookups
  • Ordering
  • Limiting
  • Expressions
  • Annotations
  • Aggregates
  • Virtual fields

Directories

Path Synopsis
src
migrator/sql/mysql
Package mysql provides a MySQL implementation of the migrator.SchemaEditor interface.
Package mysql provides a MySQL implementation of the migrator.SchemaEditor interface.

Jump to

Keyboard shortcuts

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