Advanced Queries

@an5/adapters provides powerful query capabilities for complex data retrieval across SQL dialects (MSSQL, PostgreSQL, MySQL, SQLite) and Google Sheets.

Sqlite note: SQLite uses LIMIT/OFFSET pagination and ? placeholders in Python raw SQL. The Go example uses the sqlite3 driver name; register that driver before opening a connection.

Client query capabilities

The examples above use @an5/adapters for TypeScript. The generated clients cover the same ground for the other languages, but not evenly — each one is generated from the same schema and the query surface differs:

  TypeScript Python .NET Go Rust Java Kotlin Swift
Read rows findMany find_many FindMany FindMany find_many findMany findMany findMany
Filter where object where dict SQL predicate typed structs typed structs An5Query.where query block Query(filter:)
Sort orderBy order_by in the SQL you write *SortOrder SortOrder An5Query.orderBy orderBy(...) Query.orderBy
Paginate skip / take skip / take in the SQL you write Skip / Take skip / take skip / take skip / take skip / take
Select columns select select — Select select select select select
Load relations include include — — — include include include
Aggregate aggregate aggregate Count only — through table() aggregate aggregate aggregate
Group by groupBy group_by — — through table() groupBy groupBy groupBy
Raw SQL $queryRawUnsafe query_raw QueryRaw QueryRaw adapter().query_raw queryRaw query query

The examples below use the fields of the generated example schema — User with id, email, name, createdAt, and Order with userId, total — so the queries line up across languages.

Go

connStr := an5.GetDefaultConnectionString()
conn, err := sql.Open("sqlite3", connStr)  // register the selected database/sql driver first
if err != nil {
	log.Fatal(err)
}
defer conn.Close()

db := an5.NewAn5DbContextWithConnStr(conn, connStr)
ctx := context.Background()

since := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
take, skip := 10, 0

users, err := db.User.FindMany(ctx, &an5.UserFindManyArgs{
	Where: &an5.UserWhereInput{
		Email:     &an5.StringFilter{Contains: an5.StringPtr("@example.com")},
		CreatedAt: &an5.DateTimeFilter{Gte: &since},
	},
	OrderBy: &an5.UserOrderByInput{
		CreatedAt: an5.SortOrderPtr(an5.SortOrderDesc),
	},
	Take:   &take,
	Skip:   &skip,
	Select: []string{"id", "email", "created_at"},
})

Every call takes a context.Context and returns ([]T, error). Take and Skip are pointers, and both have to be set for the page to be applied.

Counting and raw SQL are available; aggregate and groupBy are not:

n, err := db.Order.Count(ctx, &an5.OrderCountArgs{
	Where: &an5.OrderWhereInput{
		Total: &an5.IntFilter{Gte: an5.IntPtr(10)},
	},
})

rows, err := db.Order.QueryRaw(ctx,
	"SELECT userId, SUM(total) AS revenue FROM orders GROUP BY userId")

Two things to know about the Go client:

  • It writes columns in snake_case (created_at), whatever the schema declares.
  • NotIn is declared on the filter types but never turned into SQL, so setting it silently does nothing. In works.

Next Steps