Search
ctrl+/
Ask AI
ctrl+.
Light
Dark
System
Sign in

Data types

When producing results, the client automatically decodes Gel types to the corresponding JavaScript types. When you pass scalar values to the client as arguments, the client automatically encodes them to the corresponding Gel types.

The table below shows the correspondence between Gel and JavaScript data types.

Gel Type

JavaScript Type

multi set

Array

array<anytype>

Array

anytuple

Array

anyenum

string

Object

object

bool

boolean

bytes

Uint8Array

str

string

float32, float64, int16, int32, int64

number

bigint

BigInt

decimal

n/a

json

unknown

uuid

string

datetime

Date

cal::local_date

LocalDate()

cal::local_time

LocalTime()

cal::local_datetime

LocalDateTime()

duration

Duration()

cal::relative_duration

RelativeDuration()

cal::date_duration

DateDuration()

range<anytype>

Range()

cfg::memory

ConfigMemory()

Inexact single-precision float values may have a different representation when decoded into a JavaScript number. This is inherent to the implementation of limited-precision floating point types. If you need the decimal representation to match, cast the expression to float64 in your query.

Due to precision limitations the decimal type cannot be decoded to a JavaScript number. Use an explicit cast to float64 if the precision degradation is acceptable or a cast to str for an exact decimal representation.

Gel array maps onto the JavaScript Array.

Copy
await client.querySingle<number[]>("select [1, 2, 3];");
// number[]: [1, 2, 3]

Object represents an object instance returned from a query. The value of an object property or a link can be accessed through a corresponding object key:

Copy
await client.query<{
  title: string;
  characters: {
    name: string;
    "@character_name": string;
  }[];
}>(`
  select Movie {
    title,
    characters: {
      name,
      @character_name
    }
  };
`);

A regular Gel tuple becomes an Array in JavaScript. A Gel namedtuple becomes an object with properties corresponding to the tuple elements.

Copy
await client.queryRequiredSingle<[number, string]>(`select (1, "hello");`);
// [number, string]: [1, 'hello']

await client.queryRequiredSingle<{
  foo: number;
  bar: string;
}>(`select (foo := 1, bar := "hello");`);
// { foo: number; bar: string }: { foo: 1; bar: 'hello' }

class

LocalDate
LocalDate(year: number, month: number, day: number)

A JavaScript representation of a Gel local_date value. Implements a subset of the TC39 Temporal Proposal PlainDate type.

Assumes the calendar is always ISO 8601.

attribute

LocalDate.year
LocalDate.year: number

The year value of the local date.

attribute

LocalDate.month
LocalDate.month: number

The numerical month value of the local date.

Unlike the JS Date object, months in LocalDate start at 1. ie. Jan = 1, Feb = 2, etc.

attribute

LocalDate.day
LocalDate.day: number

The day of the month value of the local date (starting with 1).

attribute

LocalDate.dayOfWeek
LocalDate.dayOfWeek: number

The weekday number of the local date. Returns a value between 1 and 7 inclusive, where 1 = Monday and 7 = Sunday.

attribute

LocalDate.dayOfYear
LocalDate.dayOfYear: number

The ordinal day of the year of the local date. Returns a value between 1 and 365 (or 366 in a leap year).

attribute

LocalDate.weekOfYear
LocalDate.weekOfYear: number

The ISO week number of the local date. Returns a value between 1 and 53, where ISO week 1 is defined as the week containing the first Thursday of the year.

attribute

LocalDate.daysInWeek
LocalDate.daysInWeek: number

The number of days in the week of the local date. Always returns 7.

attribute

LocalDate.daysInMonth
LocalDate.daysInMonth: number

The number of days in the month of the local date. Returns a value between 28 and 31 inclusive.

attribute

LocalDate.daysInYear
LocalDate.daysInYear: number

The number of days in the year of the local date. Returns either 365 or 366 if the year is a leap year.

attribute

LocalDate.monthsInYear
LocalDate.monthsInYear: number

The number of months in the year of the local date. Always returns 12.

attribute

LocalDate.inLeapYear
LocalDate.inLeapYear: boolean

Return whether the year of the local date is a leap year.

method

LocalDate.toString()
LocalDate.toString(): string

Get the string representation of the LocalDate in the YYYY-MM-DD format.

method

LocalDate.toJSON()
LocalDate.toJSON(): number

Same as toString().

method

LocalDate.valueOf()
LocalDate.valueOf(): never

Always throws an Error. LocalDate objects are not comparable.

class

LocalTime
LocalTime(hour: number = 0, minute: number = 0, second: number = 0, millisecond: number = 0, microsecond: number = 0, nanosecond: number = 0)

A JavaScript representation of a Gel local_time value. Implements a subset of the TC39 Temporal Proposal PlainTime type.

The Gel local_time type only has microsecond precision, any nanoseconds specified in the LocalTime will be ignored when encoding to a Gel local_time.

attribute

LocalTime.hour
LocalTime.hour: number

The hours component of the local time in 0-23 range.

attribute

LocalTime.minute
LocalTime.minute: number

The minutes component of the local time in 0-59 range.

attribute

LocalTime.second
LocalTime.second: number

The seconds component of the local time in 0-59 range.

attribute

LocalTime.millisecond
LocalTime.millisecond: number

The millisecond component of the local time in 0-999 range.

attribute

LocalTime.microsecond
LocalTime.microsecond: number

The microsecond component of the local time in 0-999 range.

attribute

LocalTime.nanosecond
LocalTime.nanosecond: number

The nanosecond component of the local time in 0-999 range.

method

LocalTime.toString()
LocalTime.toString(): string

Get the string representation of the local_time in the HH:MM:SS 24-hour format.

method

LocalTime.toJSON()
LocalTime.toJSON(): string

Same as toString().

method

LocalTime.valueOf()
LocalTime.valueOf(): never

Always throws an Error. LocalTime objects are not comparable.

class

LocalDateTime
LocalDateTime(year: number, month: number, day: number, hour: number = 0, minute: number = 0, second: number = 0, millisecond: number = 0, microsecond: number = 0, nanosecond: number = 0) extends LocalDate, LocalTime

A JavaScript representation of a Gel local_datetime value. Implements a subset of the TC39 Temporal Proposal PlainDateTime type.

Inherits all properties from the LocalDate() and LocalTime() types.

method

LocalDateTime.toString()
LocalDateTime.toString(): string

Get the string representation of the local_datetime in the YYYY-MM-DDTHH:MM:SS 24-hour format.

method

LocalDateTime.toJSON()
LocalDateTime.toJSON(): string

Same as toString().

method

LocalDateTime.valueOf()
LocalDateTime.valueOf(): never

Always throws an Error. LocalDateTime objects are not comparable.

class

Duration
Duration(years: number = 0, months: number = 0, weeks: number = 0, days: number = 0, hours: number = 0, minutes: number = 0, seconds: number = 0, milliseconds: number = 0, microseconds: number = 0, nanoseconds: number = 0)

A JavaScript representation of a Gel duration value. This class attempts to conform to the TC39 Temporal Proposal Duration type as closely as possible.

No arguments may be infinite and all must have the same sign. Any non-integer arguments will be rounded towards zero.

The Temporal Duration type can contain both absolute duration components, such as hours, minutes, seconds, etc. and relative duration components, such as years, months, weeks, and days, where their absolute duration changes depending on the exact date they are relative to (eg. different months have a different number of days).

The Gel duration type only supports absolute durations, so any Duration with non-zero years, months, weeks, or days will throw an error when trying to encode them.

The Gel duration type only has microsecond precision, any nanoseconds specified in the Duration will be ignored when encoding to a Gel duration.

Temporal Duration objects can be unbalanced, (ie. have a greater value in any property than it would naturally have, eg. have a seconds property greater than 59), but Gel duration objects are always balanced.

Therefore in a round-trip of a Duration object to Gel and back, the returned object, while being an equivalent duration, may not have exactly the same property values as the sent object.

attribute

Duration.years
Duration.years: number

The number of years in the duration.

attribute

Duration.months
Duration.months: number

The number of months in the duration.

attribute

Duration.weeks
Duration.weeks: number

The number of weeks in the duration.

attribute

Duration.days
Duration.days: number

The number of days in the duration.

attribute

Duration.hours
Duration.hours: number

The number of hours in the duration.

attribute

Duration.minutes
Duration.minutes: number

The number of minutes in the duration.

attribute

Duration.seconds
Duration.seconds: number

The number of seconds in the duration.

attribute

Duration.milliseconds
Duration.milliseconds: number

The number of milliseconds in the duration.

attribute

Duration.microseconds
Duration.microseconds: number

The number of microseconds in the duration.

attribute

Duration.nanoseconds
Duration.nanoseconds: number

The number of nanoseconds in the duration.

attribute

Duration.sign
Duration.sign: number

Returns -1, 0, or 1 depending on whether the duration is negative, zero or positive.

attribute

Duration.blank
Duration.blank: boolean

Returns true if the duration is zero.

method

Duration.toString()
Duration.toString(): string

Get the string representation of the duration in ISO 8601 duration format.

method

Duration.toJSON()
Duration.toJSON(): number

Same as toString().

method

Duration.valueOf()
Duration.valueOf(): never

Always throws an Error. Duration objects are not comparable.

class

RelativeDuration
RelativeDuration(years: number = 0, months: number = 0, weeks: number = 0, days: number = 0, hours: number = 0, minutes: number = 0, seconds: number = 0, milliseconds: number = 0, microseconds: number = 0)

A JavaScript representation of a Gel cal::relative_duration value. This type represents a non-definite span of time such as "2 years 3 days". This cannot be represented as a duration because a year has no absolute duration; for instance, leap years are longer than non-leap years.

This class attempts to conform to the TC39 Temporal Proposal Duration type as closely as possible.

Internally, a cal::relative_duration value is represented as an integer number of months, days, and seconds. During encoding, other units will be normalized to these three. Sub-second units like microseconds will be ignored.

attribute

RelativeDuration.years
RelativeDuration.years: number

The number of years in the relative duration.

attribute

RelativeDuration.months
RelativeDuration.months: number

The number of months in the relative duration.

attribute

RelativeDuration.weeks
RelativeDuration.weeks: number

The number of weeks in the relative duration.

attribute

RelativeDuration.days
RelativeDuration.days: number

The number of days in the relative duration.

attribute

RelativeDuration.hours
RelativeDuration.hours: number

The number of hours in the relative duration.

attribute

RelativeDuration.minutes
RelativeDuration.minutes: number

The number of minutes in the relative duration.

attribute

RelativeDuration.seconds
RelativeDuration.seconds: number

The number of seconds in the relative duration.

attribute

RelativeDuration.milliseconds
RelativeDuration.milliseconds: number

The number of milliseconds in the relative duration.

attribute

RelativeDuration.microseconds
RelativeDuration.microseconds: number

The number of microseconds in the relative duration.

method

RelativeDuration.toString()
RelativeDuration.toString(): string

Get the string representation of the duration in ISO 8601 duration format.

method

RelativeDuration.toJSON()
RelativeDuration.toJSON(): string

Same as toString().

method

RelativeDuration.valueOf()
RelativeDuration.valueOf(): never

Always throws an Error. RelativeDuration objects are not comparable.

class

DateDuration
DateDuration(years: number = 0, months: number = 0, weeks: number = 0, days: number = 0)

A JavaScript representation of a Gel cal::date_duration value. This type represents a non-definite span of time consisting of an integer number of months and days.

This type is primarily intended to simplify logic involving cal::local_date values.

Copy
db> 
select <cal::date_duration>'5 days';
{<cal::date_duration>'P5D'}
Copy
db> 
select <cal::local_date>'2022-06-25' + <cal::date_duration>'5 days';
{<cal::local_date>'2022-06-30'}
Copy
db> 
select <cal::local_date>'2022-06-30' - <cal::local_date>'2022-06-25';
{<cal::date_duration>'P5D'}

Internally, a cal::relative_duration value is represented as an integer number of months and days. During encoding, other units will be normalized to these two.

attribute

DateDuration.years
DateDuration.years: number

The number of years in the relative duration.

attribute

DateDuration.months
DateDuration.months: number

The number of months in the relative duration.

attribute

DateDuration.weeks
DateDuration.weeks: number

The number of weeks in the relative duration.

attribute

DateDuration.days
DateDuration.days: number

The number of days in the relative duration.

method

DateDuration.toString()
DateDuration.toString(): string

Get the string representation of the duration in ISO 8601 duration format.

method

DateDuration.toJSON()
DateDuration.toJSON(): string

Same as toString().

method

DateDuration.valueOf()
DateDuration.valueOf(): never

Always throws an Error. DateDuration objects are not comparable.

class

ConfigMemory
ConfigMemory(bytes: BigInt)

A JavaScript representation of a Gel cfg::memory value.

attribute

ConfigMemory.bytes
ConfigMemory.bytes: number

The memory value in bytes (B).

The Gel cfg::memory represents a number of bytes stored as an int64. Since JS the number type is a float64, values above ~8191TiB will lose precision when represented as a JS number. To keep full precision use the bytesBigInt property.

attribute

ConfigMemory.kibibytes
ConfigMemory.kibibytes: number

The memory value in kibibytes (KiB).

attribute

ConfigMemory.mebibytes
ConfigMemory.mebibytes: number

The memory value in mebibytes (MiB).

attribute

ConfigMemory.gibibytes
ConfigMemory.gibibytes: number

The memory value in gibibytes (GiB).

attribute

ConfigMemory.tebibytes
ConfigMemory.tebibytes: number

The memory value in tebibytes (TiB).

attribute

ConfigMemory.pebibytes
ConfigMemory.pebibytes: number

The memory value in pebibytes (PiB).

method

ConfigMemory.toString()
ConfigMemory.toString(): string

Get the string representation of the memory value. Format is the same as returned by string casting a cfg::memory value in Gel.

class

Range
Range(lower: T | null, upper: T | null, incLower: boolean = true, incUpper: boolean = false)

A JavaScript representation of a Gel std::range value. This is a generic TypeScript class with the following type signature.

Copy
class Range<
    T extends number | Date | LocalDate | LocalDateTime | Duration
>{
    // ...
}

attribute

Range.lower
Range.lower: T

The lower bound of the range value.

attribute

Range.upper
Range.upper: T

The upper bound of the range value.

attribute

Range.incLower
Range.incLower: boolean

Whether the lower bound is inclusive.

attribute

Range.incUpper
Range.incUpper: boolean

Whether the upper bound is inclusive.

attribute

Range.empty
Range.empty: boolean

Whether the range is empty.

method

Range.toJSON(): { lower: T | null; upper: T | null; inc_lower: boolean; inc_upper: boolean; empty?()
Range.toJSON(): { lower: T | null; upper: T | null; inc_lower: boolean; inc_upper: boolean; empty?(): undefined; }

Returns a JSON-encodable representation of the range.

method

Range.empty()
Range.empty(): Range

A static method to declare an empty range (no bounds).

Copy
Range.empty();