CRUD Operations
AN5 ORM provides a clean, type-safe API for all CRUD operations tailored for Golang.
Client Setup
import (
"context"
"os"
"an5client"
)
ctx := context.Background()
db, err := an5client.NewAn5DbContext(ctx, os.Getenv("DATABASE_URL"))
1. Create
Create a Single Record
user, err := db.User.Create(ctx, &an5client.UserCreateInput{
Email: "john@example.com",
Name: "John Doe",
})
Create Many Records
count, err := db.User.CreateMany(ctx, []*an5client.UserCreateInput{
{Email: "alice@example.com", Name: "Alice"},
{Email: "bob@example.com", Name: "Bob"},
})
2. Read
Find by Primary Key or Unique Field
user, err := db.User.FindFirst(ctx, &an5client.UserFindFirstArgs{
Where: &an5client.UserWhereInput{
Email: &an5client.StringFilter{Equals: "john@example.com"},
},
})
Find Many Records with Filter & Sort
users, err := db.User.FindMany(ctx, &an5client.UserFindManyArgs{
Where: &an5client.UserWhereInput{
IsActive: &an5client.BoolFilter{Equals: true},
Email: &an5client.StringFilter{Contains: "@example.com"},
},
Take: 10,
})
3. Update
Update Single Record
err := db.User.Update(ctx, &an5client.UserUpdateArgs{
Where: &an5client.UserWhereInput{Id: &an5client.StringFilter{Equals: user.Id}},
Data: &an5client.UserUpdateInput{Name: "Johnny Doe"},
})
4. Delete
Delete Single Record
err := db.User.Delete(ctx, &an5client.UserWhereInput{
Id: &an5client.StringFilter{Equals: user.Id},
})
Next Steps
- Advanced Queries - In-depth filtering, pagination, and aggregation
- Relations & Joins - One-to-many and many-to-many relations
- Database Providers - Provider dialect specifics
- Client Languages - Complete language runtime specifications