Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d79a6db
Implement generic Table for basic CRUD operations
VojtechVitek Oct 13, 2025
c42ba49
Remove automatic 'deleted_at NULL' condition
VojtechVitek Oct 13, 2025
89f19c2
Implement .LockForUpdate() using PostgreSQL's FOR UPDATE SKIP LOCKED …
VojtechVitek Oct 13, 2025
a5d9aed
Fix generic ID
VojtechVitek Oct 13, 2025
f12a47b
Fix naming of generic types
VojtechVitek Oct 13, 2025
3569547
Add tests for simple CRUD, complex transactions and LockForUpdate()
VojtechVitek Oct 13, 2025
1fc30a9
Fix TestRecordsWithJSONStruct test, since schema changed
VojtechVitek Oct 14, 2025
bf7f7be
Fix LockForUpdate test
VojtechVitek Oct 14, 2025
feb70f3
Don't rely on wg.Go(), a feature from Go 1.25
VojtechVitek Oct 14, 2025
b218fb5
LockForUpdate that can pass transaction to update fn
VojtechVitek Oct 17, 2025
61898a1
Refactor LockForUpdate() to reuse tx if possible
VojtechVitek Oct 17, 2025
a1f7de5
Simplify data models further
VojtechVitek Oct 18, 2025
2546562
Improve tests for async processing
VojtechVitek Oct 18, 2025
f9917e9
Tests: Implement in-memory worker pattern via simple WaitGroup
VojtechVitek Oct 18, 2025
73ba584
A better "dequeue" abstraction defined on reviews table
VojtechVitek Oct 18, 2025
6c9b200
Rename GetByIDs() to ListByIDs()
VojtechVitek Oct 20, 2025
77cb157
Fix updated_at field, thanks @shunkakinoki
VojtechVitek Oct 21, 2025
82b1e7b
PR feedback: Improve error annotations
VojtechVitek Oct 21, 2025
8bd8f1f
Fix tests
VojtechVitek Oct 21, 2025
f28591e
Save multiple (#33)
david-littlefarmer Oct 24, 2025
320b0f3
Add iterator method for accounts and update tests
klaidliadon Dec 10, 2025
b2ce7a7
Rename types for clarity
klaidliadon Mar 5, 2026
95252fc
add back truncateAllTables
klaidliadon Mar 5, 2026
a3fdad7
Add IDColumn to table context and enhance WithTx tests
klaidliadon Mar 6, 2026
cf0cd56
Add pagination support to Table with ListPaged and WithPaginator methods
klaidliadon Mar 9, 2026
f74541e
feat: add Insert and Update methods in Table
klaidliadon Mar 17, 2026
2fa3605
feat: add RestoreByID and export timestamp interfaces
klaidliadon Mar 23, 2026
24ad27f
fix: LockForUpdates missing return, saveAll hardcoded ID column, Iter…
klaidliadon Apr 3, 2026
c7fd6ea
fix(tests): race conditions in TestLockForUpdates and wrong ListByIDs…
klaidliadon Apr 3, 2026
d753ee8
fix: ListPaged nil page panic
klaidliadon Apr 3, 2026
70cdd93
fix: LockForUpdates validate/timestamp, zero-value Paginator, ListPag…
klaidliadon Apr 3, 2026
ecbed78
fix: PrepareRaw empty ORDER BY and unbound limit/offset params
klaidliadon Apr 3, 2026
63e0dbc
feat: Update, DeleteByID, HardDeleteByID return (bool, error)
klaidliadon Apr 3, 2026
0cbca29
NOTICE: Experimental. Table and its methods are subject to change.
VojtechVitek Apr 3, 2026
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
33 changes: 21 additions & 12 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,21 @@ func NewPage(size, page uint32, sort ...Sort) *Page {

func (p *Page) SetDefaults(o *PaginatorSettings) {
if o == nil {
o = &PaginatorSettings{
DefaultSize: DefaultPageSize,
MaxSize: MaxPageSize,
}
o = &PaginatorSettings{}
}
defaultSize := o.DefaultSize
if defaultSize == 0 {
defaultSize = DefaultPageSize
}
maxSize := o.MaxSize
if maxSize == 0 {
maxSize = MaxPageSize
}
if p.Size == 0 {
p.Size = o.DefaultSize
p.Size = defaultSize
}
if p.Size > o.MaxSize {
p.Size = o.MaxSize
if p.Size > maxSize {
p.Size = maxSize
}
if p.Page == 0 {
p.Page = 1
Expand Down Expand Up @@ -254,18 +259,22 @@ func (p Paginator[T]) PrepareRaw(q string, args []any, page *Page) ([]T, string,

limit, offset := page.Limit(), page.Offset()

q = q + " ORDER BY " + strings.Join(p.getOrder(page), ", ")
if order := p.getOrder(page); len(order) > 0 {
q = q + " ORDER BY " + strings.Join(order, ", ")
}
q = q + " LIMIT @limit OFFSET @offset"

for i, arg := range args {
injected := false
for _, arg := range args {
if existing, ok := arg.(pgx.NamedArgs); ok {
existing["limit"] = limit + 1
existing["offset"] = offset
injected = true
break
}
if i == len(args)-1 {
args = append(args, pgx.NamedArgs{"limit": limit + 1, "offset": offset})
}
}
if !injected {
args = append(args, pgx.NamedArgs{"limit": limit + 1, "offset": offset})
}

return make([]T, 0, limit+1), q, args
Expand Down
Loading
Loading