values

Bun

Symbol

Statement.values

values(...params: ParamsType): string | number | bigint | boolean | Uint8Array<ArrayBufferLike>[][]

Execute the prepared statement and return the results as an array of arrays.

In Bun v0.6.7 and earlier, this method returned null if there were no results instead of []. This was changed in v0.6.8 to align more with what people expect.

@param params

optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.

const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");

stmt.values("baz");
// => [['baz']]

stmt.values();
// => [['baz']]

stmt.values("foo");
// => [['foo']]

stmt.values("not-found");
// => []

The following types can be used when binding parameters:

JavaScript typeSQLite type
stringTEXT
numberINTEGER or DECIMAL
booleanINTEGER (1 or 0)
Uint8ArrayBLOB
BufferBLOB
bigintINTEGER
nullNULL

Referenced types

class Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.

  • readonly [Symbol.toStringTag]: 'Uint8Array'
  • readonly buffer: TArrayBuffer

    The ArrayBuffer instance referenced by the array.

  • readonly byteLength: number

    The length in bytes of the array.

  • readonly byteOffset: number

    The offset in bytes of the array.

  • readonly BYTES_PER_ELEMENT: number

    The size in bytes of each element in the array.

  • readonly length: number

    The length of the array.

  • [Symbol.iterator](): ArrayIterator<number>
  • at(index: number): undefined | number

    Returns the item located at the specified index.

    @param index

    The zero-based index of the desired code unit. A negative index will count back from the last item.

  • copyWithin(target: number, start: number, end?: number): this

    Returns the this object after copying a section of the array identified by start and end to the same array starting at position target

    @param target

    If target is negative, it is treated as length+target where length is the length of the array.

    @param start

    If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.

    @param end

    If not specified, length of the this object is used as its default value.

  • entries(): ArrayIterator<[number, number]>

    Returns an array of key, value pairs for every entry in the array

  • every(predicate: (value: number, index: number, array: this) => unknown, thisArg?: any): boolean

    Determines whether all the members of an array satisfy the specified test.

    @param predicate

    A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

    @param thisArg

    An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • fill(value: number, start?: number, end?: number): this

    Changes all array elements from start to end index to a static value and returns the modified array

    @param value

    value to fill array section with

    @param start

    index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.

    @param end

    index to stop filling the array at. If end is negative, it is treated as length+end.

  • filter(predicate: (value: number, index: number, array: this) => any, thisArg?: any): Uint8Array<ArrayBuffer>

    Returns the elements of an array that meet the condition specified in a callback function.

    @param predicate

    A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

    @param thisArg

    An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • find(predicate: (value: number, index: number, obj: this) => boolean, thisArg?: any): undefined | number

    Returns the value of the first element in the array where predicate is true, and undefined otherwise.

    @param predicate

    find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.

    @param thisArg

    If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

  • findIndex(predicate: (value: number, index: number, obj: this) => boolean, thisArg?: any): number

    Returns the index of the first element in the array where predicate is true, and -1 otherwise.

    @param predicate

    find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.

    @param thisArg

    If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

  • findLast<S extends number>(predicate: (value: number, index: number, array: this) => value is S, thisArg?: any): undefined | S

    Returns the value of the last element in the array where predicate is true, and undefined otherwise.

    @param predicate

    findLast calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLast immediately returns that element value. Otherwise, findLast returns undefined.

    @param thisArg

    If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

    findLast(predicate: (value: number, index: number, array: this) => unknown, thisArg?: any): undefined | number
  • findLastIndex(predicate: (value: number, index: number, array: this) => unknown, thisArg?: any): number

    Returns the index of the last element in the array where predicate is true, and -1 otherwise.

    @param predicate

    findLastIndex calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.

    @param thisArg

    If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

  • forEach(callbackfn: (value: number, index: number, array: this) => void, thisArg?: any): void

    Performs the specified action for each element in an array.

    @param callbackfn

    A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

    @param thisArg

    An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

  • includes(searchElement: number, fromIndex?: number): boolean

    Determines whether an array includes a certain element, returning true or false as appropriate.

    @param searchElement

    The element to search for.

    @param fromIndex

    The position in this array at which to begin searching for searchElement.

  • indexOf(searchElement: number, fromIndex?: number): number

    Returns the index of the first occurrence of a value in an array.

    @param searchElement

    The value to locate in the array.

    @param fromIndex

    The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

  • join(separator?: string): string

    Adds all the elements of an array separated by the specified separator string.

    @param separator

    A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.

  • keys(): ArrayIterator<number>

    Returns an list of keys in the array

  • lastIndexOf(searchElement: number, fromIndex?: number): number

    Returns the index of the last occurrence of a value in an array.

    @param searchElement

    The value to locate in the array.

    @param fromIndex

    The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

  • map(callbackfn: (value: number, index: number, array: this) => number, thisArg?: any): Uint8Array<ArrayBuffer>

    Calls a defined callback function on each element of an array, and returns an array that contains the results.

    @param callbackfn

    A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

    @param thisArg

    An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

  • reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: this) => number): number

    Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    @param callbackfn

    A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

    reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: this) => number, initialValue: number): number
    reduce<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: this) => U, initialValue: U): U

    Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    @param callbackfn

    A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

    @param initialValue

    If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

  • reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: this) => number): number

    Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    @param callbackfn

    A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

    reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: this) => number, initialValue: number): number
    reduceRight<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: this) => U, initialValue: U): U

    Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    @param callbackfn

    A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

    @param initialValue

    If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

  • reverse(): this

    Reverses the elements in an Array.

  • set(array: ArrayLike<number>, offset?: number): void

    Sets a value or an array of values.

    @param array

    A typed or untyped array of values to set.

    @param offset

    The index in the current array at which the values are to be written.

  • setFromBase64(base64: string, offset?: number): { read: number; written: number }

    Set the contents of the Uint8Array from a base64 encoded string

    @param base64

    The base64 encoded string to decode into the array

    @param offset

    Optional starting index to begin setting the decoded bytes (default: 0)

  • setFromHex(hex: string): { read: number; written: number }

    Set the contents of the Uint8Array from a hex encoded string

    @param hex

    The hex encoded string to decode into the array. The string must have an even number of characters, be valid hexadecimal characters and contain no whitespace.

  • slice(start?: number, end?: number): Uint8Array<ArrayBuffer>

    Returns a section of an array.

    @param start

    The beginning of the specified portion of the array.

    @param end

    The end of the specified portion of the array. This is exclusive of the element at the index 'end'.

  • some(predicate: (value: number, index: number, array: this) => unknown, thisArg?: any): boolean

    Determines whether the specified callback function returns true for any element of an array.

    @param predicate

    A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

    @param thisArg

    An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

  • sort(compareFn?: (a: number, b: number) => number): this

    Sorts an array.

    @param compareFn

    Function used to determine the order of the elements. It is expected to return a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise. If omitted, the elements are sorted in ascending order.

    [11,2,22,1].sort((a, b) => a - b)
    
  • subarray(begin?: number, end?: number): Uint8Array<TArrayBuffer>

    Gets a new Uint8Array view of the ArrayBuffer store for this array, referencing the elements at begin, inclusive, up to end, exclusive.

    @param begin

    The index of the beginning of the array.

    @param end

    The index of the end of the array.

  • toBase64(options?: { alphabet: 'base64' | 'base64url'; omitPadding: boolean }): string

    Convert the Uint8Array to a base64 encoded string

    @returns

    The base64 encoded string representation of the Uint8Array

  • toHex(): string

    Convert the Uint8Array to a hex encoded string

    @returns

    The hex encoded string representation of the Uint8Array

  • toLocaleString(): string

    Converts a number to a string by using the current locale.

    toLocaleString(locales: string | string[], options?: NumberFormatOptions): string
  • Copies the array and returns the copy with the elements in reverse order.

  • toSorted(compareFn?: (a: number, b: number) => number): Uint8Array<ArrayBuffer>

    Copies and sorts the array.

    @param compareFn

    Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending order.

    const myNums = Uint8Array.from([11, 2, 22, 1]);
    myNums.toSorted((a, b) => a - b) // Uint8Array(4) [1, 2, 11, 22]
    
  • toString(): string

    Returns a string representation of an array.

  • valueOf(): this

    Returns the primitive value of the specified object.

  • values(): ArrayIterator<number>

    Returns an list of values in the array

  • with(index: number, value: number): Uint8Array<ArrayBuffer>

    Copies the array and inserts the given number at the provided index.

    @param index

    The index of the value to overwrite. If the index is negative, then it replaces from the end of the array.

    @param value

    The value to insert into the copied array.

    @returns

    A copy of the original array with the inserted value.