Skip to content

Commit d8de4ab

Browse files
Allow to use Uuid as literal value in ts Query Builder (clockworklabs#5075)
# Description of Changes Was forgotten while migrating to the QueryBuilder i suppose. Closes clockworklabs#5073 Maybe @clockwork-tien could lend a hand again in reviewing? ^^ # API and ABI breaking changes None <!-- If this is an API or ABI breaking change, please apply the corresponding GitHub label. --> # Expected complexity level and risk 1 <!-- How complicated do you think these changes are? Grade on a scale from 1 to 5, where 1 is a trivial change, and 5 is a deep-reaching and complex change. This complexity rating applies not only to the complexity apparent in the diff, but also to its interactions with existing and future code. If you answered more than a 2, explain what is complex about the PR, and what other components it interacts with in potentially concerning ways. --> # Testing Works in my project :> <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [x] Type Error goes away when using .eq(uuid) --------- Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
1 parent e357f5a commit d8de4ab

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

crates/bindings-typescript/src/lib/query.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
} from './type_builders';
1313
import type { Values } from './type_util';
1414
import type { Bool as SatsBool } from './algebraic_type_variants';
15+
import { Uuid } from './uuid';
1516

1617
/**
1718
* Helper to get the set of table names.
@@ -623,6 +624,7 @@ type LiteralValue =
623624
| bigint
624625
| boolean
625626
| Identity
627+
| Uuid
626628
| Timestamp
627629
| ConnectionId;
628630

@@ -851,7 +853,11 @@ function literalValueToSql(value: unknown): string {
851853
if (value === null || value === undefined) {
852854
return 'NULL';
853855
}
854-
if (value instanceof Identity || value instanceof ConnectionId) {
856+
if (
857+
value instanceof Identity ||
858+
value instanceof ConnectionId ||
859+
value instanceof Uuid
860+
) {
855861
// We use this hex string syntax.
856862
return `0x${value.toHexString()}`;
857863
}

crates/bindings-typescript/src/lib/uuid.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Timestamp } from './timestamp';
22
import { AlgebraicType } from './algebraic_type.ts';
3+
import { u128ToHexString } from './util';
34

45
export type UuidAlgebraicType = {
56
tag: 'Product';
@@ -226,10 +227,14 @@ export class Uuid {
226227
return new Uuid(v);
227228
}
228229

230+
/** Convert to hex string without a 0x prefix. */
231+
toHexString(): string {
232+
return u128ToHexString(this.asBigInt());
233+
}
234+
229235
/** Convert to string (hyphenated form). */
230236
toString(): string {
231-
const bytes = Uuid.bigIntToBytes(this.__uuid__);
232-
const hex = [...bytes].map(b => b.toString(16).padStart(2, '0')).join('');
237+
const hex = this.toHexString();
233238

234239
// Format as 8-4-4-4-12
235240
return (

0 commit comments

Comments
 (0)