Introduction to upper/db
upper/db
provides a common inteface for developers to work with different SQL
and NoSQL database engines. Its main goal is to provide Go developers with the
right tools that enable them to focus on writing business logic with a
reasonable compromise between productivity, development speed and computing
resources.
Through the use of well-known database drivers, upper/db
communicates with
the most popular database engines (PostgreSQL,
MySQL, CockroachDB, Microsoft
SQL Server, SQLite,
QL and MongoDB).
Packages
db
The db
package provides an agnostic Go API focused on working with
collections of items. This API is modelled after basic set theory concepts that
are applicable to relational and document-based database engines alike.
This API provides you with enough tools for most of the tasks you perform with a database, such as:
- Basic CRUD (Create, Read, Update and Delete).
- Search and delimitation of result sets.
- Mapping between Go structs (or slices of structs) and query results.
- Limit-offset pagination (page numbers).
- Cursor-based pagination (previous and next).
- Transactions.
There will be times when an agnostic API won't be enough, for those tasks
upper/db
also provides a SQL builder interface, which provides a more direct
access to the database with the additional advantage of using a SQL-like Go API
or raw SQL sentences.
An optional ORM-like interface
db
provides an (optional) ORM-like layer for upper/db
that allows
developers to represent data structures and relationships between them in a
more opinionated way.
Getting started
- Key concepts
- Connect to a database
- Mapping database records to Go structs
- Using the agnostic
db
API - Using the SQL builder API
- Transactions
- Logger