Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
# Migration Guide: v0.3.0 to v1.0
# Migration Guide: v0.3.0 to v2.0

This guide helps you migrate from go-paging v0.3.0 to the new v1.0 modular architecture.
This guide helps you migrate from go-paging v0.3.0 to paging-go v2.0.

## Overview

v2.0 combines two major improvements:

1. **Modular architecture** - Separate packages for offset, cursor, and quota-fill pagination
2. **Repository rename** - Aligned with organizational naming standards: `go-paging` → `paging-go/v2`
3. **API consistency** - Type rename: `OrderBy` → `Sort`
4. **Schema pattern** - Ensures encoder/sort order consistency for cursor and quota-fill

## Breaking Changes Summary

| Change | Old (v0.3.0) | New (v2.0) |
|--------|-------------|-----------|
| **Module path** | `github.com/nrfta/go-paging` | `github.com/nrfta/paging-go/v2` |
| **Constructor** | `paging.NewOffsetPaginator()` | `offset.New()` |
| **Type** | `paging.OffsetPaginator` | `offset.Paginator` |
| **Sort type** | `paging.OrderBy` | `paging.Sort` |
| **Cursor encoding** | `paging.EncodeOffsetCursor()` | `offset.EncodeCursor()` |

## Quick Summary

**What you need to change:**

1. Add import: `"github.com/nrfta/go-paging/offset"`
2. Change: `paging.NewOffsetPaginator(...)` → `offset.New(...)`
3. Change: `paging.OffsetPaginator` → `offset.Paginator`
4. **New (Recommended):** Use `offset.BuildConnection()` to eliminate boilerplate
1. Update imports: `"github.com/nrfta/go-paging"` → `"github.com/nrfta/paging-go/v2/offset"`
2. Change constructor: `paging.NewOffsetPaginator(...)` → `offset.New(...)`
3. Change type: `paging.OffsetPaginator` → `offset.Paginator`
4. Rename sort type: `paging.OrderBy` → `paging.Sort`
5. **New (Recommended):** Use `offset.BuildConnection()` to eliminate 60-80% of boilerplate

**What stays the same:**

Expand Down Expand Up @@ -54,8 +74,8 @@ Add the offset package import:

```go
import (
"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/offset" // Add this
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/offset" // Add this
)
```

Expand Down Expand Up @@ -185,7 +205,7 @@ import (
"context"
"database/sql"

"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"
"github.com/my-user/my-app/models"
)

Expand Down Expand Up @@ -237,8 +257,8 @@ import (
"context"
"database/sql"

"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/offset"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/offset"
"github.com/my-user/my-app/models"
)

Expand Down Expand Up @@ -343,7 +363,7 @@ if page != nil && page.After != nil {
fetchParams := paging.FetchParams{
Limit: limit + 1, // Manual N+1
Cursor: cursorPos,
OrderBy: []paging.OrderBy{
OrderBy: []paging.Sort{
{Column: "created_at", Desc: true},
{Column: "id", Desc: true},
},
Expand All @@ -355,11 +375,11 @@ users, _ := fetcher.Fetch(ctx, fetchParams)

```go
// ✅ N+1 handled automatically!
orderBy := []paging.OrderBy{
sorts := []paging.Sort{
{Column: "created_at", Desc: true},
{Column: "id", Desc: true},
}
fetchParams := cursor.BuildFetchParams(page, encoder, orderBy)
fetchParams := cursor.BuildFetchParams(page, encoder, sorts)
users, _ := fetcher.Fetch(ctx, fetchParams)
```

Expand Down Expand Up @@ -409,7 +429,7 @@ type UserEdge {
```yaml
models:
UserConnection:
model: github.com/nrfta/go-paging.Connection[github.com/my-user/my-app/domain.User]
model: github.com/nrfta/paging-go/v2.Connection[github.com/my-user/my-app/domain.User]
```

## Advanced: SQLBoiler Adapter (for library authors)
Expand Down Expand Up @@ -445,11 +465,13 @@ The new modular architecture provides:

## Migration Checklist

- [ ] Update imports to include `"github.com/nrfta/go-paging/offset"`
- [ ] Update module import: `"github.com/nrfta/go-paging"` → `"github.com/nrfta/paging-go/v2"`
- [ ] Update subpackage imports: `"github.com/nrfta/go-paging/offset"` → `"github.com/nrfta/paging-go/v2/offset"`
- [ ] Replace `paging.NewOffsetPaginator()` with `offset.New()`
- [ ] Update type references from `paging.OffsetPaginator` to `offset.Paginator`
- [ ] Update type references: `paging.OffsetPaginator` → `offset.Paginator`
- [ ] Rename sort type: `paging.OrderBy` → `paging.Sort`
- [ ] Replace manual edge/node building with `offset.BuildConnection()`
- [ ] Update cursor function calls (if used): `paging.EncodeOffsetCursor` → `offset.EncodeCursor`
- [ ] Update cursor functions (if used): `paging.EncodeOffsetCursor` → `offset.EncodeCursor`
- [ ] Run tests to verify everything works
- [ ] Enjoy 60-80% less boilerplate code! 🎉

Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# go-paging ![](https://github.com/nrfta/go-paging/workflows/CI/badge.svg)
# paging-go ![](https://github.com/nrfta/paging-go/workflows/CI/badge.svg)

Type-safe Relay pagination for [SQLBoiler](https://github.com/aarondl/sqlboiler) and [gqlgen](https://github.com/99designs/gqlgen/).

Expand All @@ -7,15 +7,15 @@ Supports three pagination strategies: offset (traditional LIMIT/OFFSET), cursor
## Install

```sh
go get -u "github.com/nrfta/go-paging"
go get -u "github.com/nrfta/paging-go/v2"
```

## Migration from v0.3.0

Breaking changes in v1.0 moved from monolithic API to modular package structure. See [MIGRATION.md](./MIGRATION.md) for details.

Quick summary:
1. Add strategy import: `"github.com/nrfta/go-paging/offset"`
1. Add strategy import: `"github.com/nrfta/paging-go/v2/offset"`
2. Change constructor: `paging.NewOffsetPaginator()` → `offset.New()`
3. Use builder: `offset.BuildConnection()` eliminates 60-80% of boilerplate

Expand All @@ -29,17 +29,17 @@ Add [this schema](./schema.graphql) and configure gqlgen:
# gqlgen.yml
models:
PageArgs:
model: github.com/nrfta/go-paging.PageArgs
model: github.com/nrfta/paging-go/v2.PageArgs
PageInfo:
model: github.com/nrfta/go-paging.PageInfo
model: github.com/nrfta/paging-go/v2.PageInfo
```

### PageInfo Resolver

```go
package resolvers

import "github.com/nrfta/go-paging"
import "github.com/nrfta/paging-go/v2"

func (r *RootResolver) PageInfo() PageInfoResolver {
return paging.NewPageInfoResolver()
Expand All @@ -55,8 +55,8 @@ package resolvers

import (
"context"
"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/offset"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/offset"
"github.com/my-user/my-app/models"
)

Expand Down Expand Up @@ -135,8 +135,8 @@ High-performance keyset pagination using composite indexes. Provides O(1) perfor

```go
import (
"github.com/nrfta/go-paging/cursor"
"github.com/nrfta/go-paging/sqlboiler"
"github.com/nrfta/paging-go/v2/cursor"
"github.com/nrfta/paging-go/v2/sqlboiler"
)

func (r *queryResolver) Users(ctx context.Context, page *paging.PageArgs) (*paging.Connection[*User], error) {
Expand Down Expand Up @@ -337,9 +337,9 @@ This creates poor UX: uneven layouts, unpredictable "Load More" behavior, multip

```go
import (
"github.com/nrfta/go-paging/cursor"
"github.com/nrfta/go-paging/quotafill"
"github.com/nrfta/go-paging/sqlboiler"
"github.com/nrfta/paging-go/v2/cursor"
"github.com/nrfta/paging-go/v2/quotafill"
"github.com/nrfta/paging-go/v2/sqlboiler"
)

func (r *queryResolver) Organizations(ctx context.Context, page *paging.PageArgs) (*paging.Connection[*Organization], error) {
Expand Down
4 changes: 2 additions & 2 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/offset"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/offset"
)

// Mock database models
Expand Down
2 changes: 1 addition & 1 deletion cursor/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (
"encoding/base64"
"encoding/json"

"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"
)

// CompositeCursorEncoder encodes multiple column values into an opaque cursor string.
Expand Down
2 changes: 1 addition & 1 deletion cursor/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/nrfta/go-paging/cursor"
"github.com/nrfta/paging-go/v2/cursor"
)

// testUser is a simple test struct for cursor encoding
Expand Down
2 changes: 1 addition & 1 deletion cursor/paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cursor
import (
"fmt"

"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"
)

const defaultLimitVal = 50
Expand Down
4 changes: 2 additions & 2 deletions cursor/paginator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"errors"
"time"

"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/cursor"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/cursor"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion cursor/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"errors"
"fmt"

"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"
)

// Direction represents the sort direction for a field.
Expand Down
4 changes: 2 additions & 2 deletions cursor/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cursor_test
import (
"time"

"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/cursor"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/cursor"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/nrfta/go-paging
module github.com/nrfta/paging-go/v2

go 1.24.9

Expand Down
2 changes: 1 addition & 1 deletion offset/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/nrfta/go-paging/offset"
"github.com/nrfta/paging-go/v2/offset"
)

var _ = Describe("Cursor Encoding/Decoding", func() {
Expand Down
2 changes: 1 addition & 1 deletion offset/paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package offset
import (
"strings"

"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"

"github.com/aarondl/sqlboiler/v4/queries/qm"
)
Expand Down
4 changes: 2 additions & 2 deletions offset/paginator_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package offset_test

import (
"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/offset"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/offset"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion page_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"
)

var _ = Describe("PageArgs", func() {
Expand Down
6 changes: 3 additions & 3 deletions quotafill/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"testing"

"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/cursor"
"github.com/nrfta/go-paging/quotafill"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/cursor"
"github.com/nrfta/paging-go/v2/quotafill"
)

func TestCursorGeneration(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions quotafill/quotafill.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"time"

"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/cursor"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/cursor"
)

// Default configuration values
Expand Down
6 changes: 3 additions & 3 deletions quotafill/quotafill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"testing"
"time"

"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/cursor"
"github.com/nrfta/go-paging/quotafill"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/cursor"
"github.com/nrfta/paging-go/v2/quotafill"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
2 changes: 1 addition & 1 deletion sqlboiler/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/aarondl/sqlboiler/v4/queries"
"github.com/aarondl/sqlboiler/v4/queries/qm"
"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"
)

// CursorToQueryMods converts FetchParams into SQLBoiler query mods for cursor-based pagination.
Expand Down
4 changes: 2 additions & 2 deletions sqlboiler/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package sqlboiler_test
import (
"time"

"github.com/nrfta/go-paging"
"github.com/nrfta/go-paging/sqlboiler"
"github.com/nrfta/paging-go/v2"
"github.com/nrfta/paging-go/v2/sqlboiler"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down
2 changes: 1 addition & 1 deletion sqlboiler/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"context"

"github.com/aarondl/sqlboiler/v4/queries/qm"
"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"
)

// QueryFunc executes a SQLBoiler query and returns results.
Expand Down
2 changes: 1 addition & 1 deletion sqlboiler/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"

"github.com/aarondl/sqlboiler/v4/queries/qm"
"github.com/nrfta/go-paging"
"github.com/nrfta/paging-go/v2"
)

// OffsetToQueryMods converts FetchParams into SQLBoiler query mods for offset pagination.
Expand Down
Loading
Loading