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
8 changes: 7 additions & 1 deletion crates/bindings-typescript/src/lib/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
} from './type_builders';
import type { Values } from './type_util';
import type { Bool as SatsBool } from './algebraic_type_variants';
import { Uuid } from './uuid';

/**
* Helper to get the set of table names.
Expand Down Expand Up @@ -623,6 +624,7 @@ type LiteralValue =
| bigint
| boolean
| Identity
| Uuid
| Timestamp
| ConnectionId;

Expand Down Expand Up @@ -851,7 +853,11 @@ function literalValueToSql(value: unknown): string {
if (value === null || value === undefined) {
return 'NULL';
}
if (value instanceof Identity || value instanceof ConnectionId) {
if (
value instanceof Identity ||
value instanceof ConnectionId ||
value instanceof Uuid
) {
// We use this hex string syntax.
return `0x${value.toHexString()}`;
}
Expand Down
9 changes: 7 additions & 2 deletions crates/bindings-typescript/src/lib/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Timestamp } from './timestamp';
import { AlgebraicType } from './algebraic_type.ts';
import { u128ToHexString } from './util';

export type UuidAlgebraicType = {
tag: 'Product';
Expand Down Expand Up @@ -226,10 +227,14 @@ export class Uuid {
return new Uuid(v);
}

/** Convert to hex string without a 0x prefix. */
toHexString(): string {
return u128ToHexString(this.asBigInt());
}

/** Convert to string (hyphenated form). */
toString(): string {
const bytes = Uuid.bigIntToBytes(this.__uuid__);
const hex = [...bytes].map(b => b.toString(16).padStart(2, '0')).join('');
const hex = this.toHexString();

// Format as 8-4-4-4-12
return (
Expand Down
Loading