Skip to content
Data

Data

  • Connect to a database: Open your app’s database from configuration and use it from handlers, jobs and background tasks.
  • Define models and save data: Map structs to tables, and create, update and delete rows with timestamps, soft deletes and hooks.
  • Migrations: Create and change your database tables with versioned migrations that are compiled into your app and run with one command.
  • Query data: Find rows with typed conditions, sort and paginate them, aggregate, and update or delete in bulk.
  • Relations and eager loading: Declare how models relate (a post belongs to an author, an author has many posts, posts have many tags), load related rows in one query per relation, and filter rows by what they relate to.
  • Transactions: Make several writes succeed or fail together, and run follow-up work only after they are saved.
  • Raw SQL: Write SQL yourself and scan the results into structs, when the query builder is in the way.
  • Seed the database: Fill a database with sample data for development, or with the reference data every environment needs.
  • Generate typed columns: Let anetos gen declare a typed column for every field of your models, and a handle for every relation, so queries say PostCols.Title.Like("%go%") and With(PostRels.Author), and the compiler checks the column name, the value’s type and the relation’s model.