Skip to content

Commit

Permalink
Add support for timestamp and timestamptz on the client
Browse files Browse the repository at this point in the history
  • Loading branch information
alco committed Aug 15, 2023
1 parent ae33c38 commit bbdd75a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions clients/typescript/src/satellite/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,8 @@ function deserializeColumnData(
switch (columnType) {
case 'CHAR':
case 'TEXT':
case 'TIMESTAMP':
case 'TIMESTAMPTZ':
case 'UUID':
case 'VARCHAR':
return typeDecoder.text(column)
Expand Down
10 changes: 7 additions & 3 deletions clients/typescript/src/util/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ setGlobalUUID(

export const typeDecoder = {
number: bytesToNumber,
text: (bytes: Uint8Array) => new TextDecoder().decode(bytes),
text: bytesToString,
}

export const typeEncoder = {
Expand Down Expand Up @@ -46,14 +46,18 @@ export function numberToBytes(i: number) {
)
}

export function bytesToNumber(bs: Uint8Array) {
export function bytesToNumber(bytes: Uint8Array) {
let n = 0
for (const byte of bs.values()) {
for (const byte of bytes.values()) {
n = (n << 8) | byte
}
return n
}

export function bytesToString(bytes: Uint8Array) {
return new TextDecoder().decode(bytes)
}

export function uuid() {
return (globalThis as any).uuid()
}
Expand Down

0 comments on commit bbdd75a

Please sign in to comment.