func (s Service) ListUsers(ctx context.Context, offset, limit int) (total int, users []UserEntity, err error) {
	var countRow struct {
		Count int `ksql:"count"`
	}
	err = s.db.QueryOne(ctx, &countRow, "SELECT count(*) as count FROM users")
	if err != nil {
		return 0, nil, err
	}
	return countRow.Count, users, s.db.Query(ctx, &users, "SELECT * FROM users OFFSET ? LIMIT ?", offset, limit)
}
ListUsers returns a page of users
package exampleservice
import (
	"context"
	"time"
	"github.com/vingarcia/ksql"
	"github.com/vingarcia/ksql/nullable"
)
var UsersTable = ksql.NewTable("users", "id")
type UserEntity struct {
	ID          int       `ksql:"id"`
	Name        *string   `ksql:"name"`
	Age         *int      `ksql:"age"`
	Score       *int      `ksql:"score"`
	LastPayment time.Time `ksql:"last_payment"`
	Address     *Address  `ksql:"address,json"`
}
type Address struct {
	AddrLines []string `json:"addr_lines"`
	City      string   `json:"city"`
	State     string   `json:"state"`
	Country   string   `json:"country"`
}
type Service struct {
	db              ksql.Provider
	streamChunkSize int
}
func NewUserService(db ksql.Provider) Service {
	return Service{
		db:              db,
		streamChunkSize: 100,
	}
}
func (s Service) CreateUser(ctx context.Context, u UserEntity) error {
	return s.db.Insert(ctx, UsersTable, &u)
}
func (s Service) UpdateUserScore(ctx context.Context, uID int, scoreChange int) error {
	var scoreRow struct {
		Score int `ksql:"score"`
	}
	err := s.db.QueryOne(ctx, &scoreRow, "SELECT score FROM users WHERE id = ?", uID)
	if err != nil {
		return err
	}
	return s.db.Update(ctx, UsersTable, &UserEntity{
		ID:    uID,
		Score: nullable.Int(scoreRow.Score + scoreChange),
	})
}