Skip to content

Commit 5ca4c85

Browse files
DavudSafarliory-bot
authored andcommitted
feat: use keysetpagination planner for keto read queries
GitOrigin-RevId: e2ed9c3eecc60fd26eaedb3f8cca4f222fd1cb1e
1 parent 1819465 commit 5ca4c85

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

oryx/pagination/keysetpagination_v2/.snapshots/TestPageToken-Marshal_snapshot.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"n": "int64",
3232
"vi": 64
3333
},
34+
{
35+
"n": "int64-zero",
36+
"vi": 0
37+
},
38+
{
39+
"n": "empty-nullint64",
40+
"vi": 0
41+
},
3442
{
3543
"n": "nullint64",
3644
"vi": 64

oryx/pagination/keysetpagination_v2/page_token.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,11 @@ func (t *PageToken) UnmarshalJSON(data []byte) error {
130130
t.cols[i].Value = nil
131131
case col.ValueAny != nil:
132132
t.cols[i].Value = col.ValueAny
133-
134-
// zero-value checks needed for backward compatibility.
135-
// Old format: {"vt": "2023-01-01...", "vu": "00000...", "vi": 0} - all fields are present.
136-
// To avoid breaking existing tokens, we need to check for zero value as old logic did.
137-
// The next release can drop the 2nd part of the case conditions.
138-
case col.ValueTime != nil && !col.ValueTime.IsZero():
139-
t.cols[i].Value = *col.ValueTime
140-
case col.ValueUUID != nil && *col.ValueUUID != uuid.Nil:
133+
case col.ValueUUID != nil:
141134
t.cols[i].Value = *col.ValueUUID
142-
case col.ValueAny != nil:
143-
t.cols[i].Value = col.ValueAny
144-
case col.ValueInt64 != nil && *col.ValueInt64 != 0:
135+
case col.ValueTime != nil:
136+
t.cols[i].Value = *col.ValueTime
137+
case col.ValueInt64 != nil:
145138
t.cols[i].Value = *col.ValueInt64
146139
}
147140
}

oryx/pagination/paginationplanner/planner.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ type Column struct {
141141
name string
142142
}
143143

144+
func (c Column) Name() string {
145+
return c.name
146+
}
147+
144148
type ColumnConstraint uint8
145149

146150
const (
@@ -163,15 +167,16 @@ type Query map[Column]ColumnConstraint
163167
func NewQuery() Query { return make(Query) }
164168

165169
func (qc Query) SetEq(cols ...Column) Query {
166-
for _, col := range cols {
167-
qc[col] = colConstraintEq
168-
}
169-
return qc
170+
return qc.set(colConstraintEq, cols...)
170171
}
171172

172173
func (qc Query) SetIsNull(cols ...Column) Query {
174+
return qc.set(colConstraintIsNull, cols...)
175+
}
176+
177+
func (qc Query) set(c ColumnConstraint, cols ...Column) Query {
173178
for _, col := range cols {
174-
qc[col] = colConstraintIsNull
179+
qc[col] = c
175180
}
176181
return qc
177182
}

0 commit comments

Comments
 (0)