githubEdit

query

Represents a BoxLang Query object that stores tabular data.

This class implements multiple interfaces:

  • IType: for BoxLang type system integration

  • IReferenceable: for dynamic property/method access

  • Collection: for Java collection operations

  • Serializable: for persistence support

The Query object stores data as a list of row arrays, with column metadata maintained separately. It provides thread-safe operations for manipulating the data and supports JDBC ResultSet integration.

Key features:

  • Dynamic column addition/removal

  • Row manipulation (add, delete, swap)

  • Conversion to/from other data structures

  • Query metadata support

  • Collection interface implementation

  • Optimized data storage with lazy initialization

Query Methods

chevron-rightaddColumn(columnName=[string], datatype=[any], array=[array])hashtag

Adds a column to a query and populates its rows with the contents of a one-dimensional array.

Arguments:

Argument
Type
Required
Default

columnName

string

true

null

datatype

any

false

object

array

array

false

[]

chevron-rightaddRow(rowData=[any])hashtag

Return new query

Arguments:

Argument
Type
Required
Default

rowData

any

false

null

chevron-rightappend(query2=[query])hashtag

This function clears the query

Arguments:

Argument
Type
Required
Default

query2

query

true

null

chevron-rightbxDump(label=[string], top=[numeric], expand=[boolean], abort=[boolean], output=[string], format=[string], showUDFs=[boolean])hashtag

Outputs the contents of a variable (simple or complex) of any type for debugging purposes to a specific output location.

, The available ,,output,, locations are: - ,,buffer,,: The output is written to the buffer, which is the default location. If running on a web server, the output is written to the browser. - ,,console,,: The output is printed to the System console. - ,,Absolute File Path,, The output is written to a file with the specified absolute file path. ,

,

The output format can be either HTML or plain text.

The default format is HTML if the output location is the buffer or a web server or a file, otherwise it is plain text for the console.

Arguments:

Argument
Type
Required
Default

label

string

false

null

top

numeric

false

null

expand

boolean

false

true

abort

boolean

false

false

output

string

false

null

format

string

false

null

showUDFs

boolean

false

true

chevron-rightclear()hashtag

This function clears the query

chevron-rightcolumnArray()hashtag

This function returns the column array of a query.

chevron-rightcolumnCount()hashtag

This function returns the number of columns in a query

chevron-rightcolumnData(columnName=[string])hashtag

Returns the data in a query column.

Arguments:

Argument
Type
Required
Default

columnName

string

true

null

chevron-rightcolumnExists(column=[string])hashtag

This function returns true if the column exists in the query

Arguments:

Argument
Type
Required
Default

column

string

true

null

chevron-rightcolumnList()hashtag

This function returns the delimited column list of a query.

chevron-rightcurrentRow()hashtag

Returns the current row number

chevron-rightdeleteColumn(column=[string])hashtag

Deletes a column within a query object.

Arguments:

Argument
Type
Required
Default

column

string

true

null

chevron-rightdeleteRow(row=[integer])hashtag

This function deletes a row from the query

Arguments:

Argument
Type
Required
Default

row

integer

true

null

chevron-rightduplicate(deep=[boolean])hashtag

Duplicates an object - either shallow or deep

Arguments:

Argument
Type
Required
Default

deep

boolean

false

true

chevron-righteach(callback=[function:Consumer], parallel=[boolean], maxThreads=[any], ordered=[boolean], virtual=[boolean])hashtag

Iterates over query rows and passes each row per iteration to a callback function.

This function is used to perform an action for each row in the query. It does not return a value, but rather allows you to perform side effects such as printing or modifying data. ,

, ,

,Parallel Execution,

, If the ,,parallel,, argument is set to true, and no ,,max_threads,, are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If ,,max_threads,, is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to iterate, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

Arguments:

Argument
Type
Required
Default

callback

function:Consumer

true

null

parallel

boolean

false

false

maxThreads

any

false

null

ordered

boolean

false

false

virtual

boolean

false

false

chevron-rightevery(closure=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])hashtag

Used to iterate over a Query and test whether every item meets the test callback.

The function will be passed 3 arguments: the value, the index, and the Query. You can alternatively pass a Java Predicate which will only receive the 1st arg. The function should return true if the item meets the test, and false otherwise. ,

, ,,Note:,, This operation is a short-circuit operation, meaning it will stop iterating as soon as it finds the first item that does not meet the test condition. ,

, ,

,Parallel Execution,

, If the ,,parallel,, argument is set to true, and no ,,max_threads,, are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If ,,max_threads,, is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. This allows for efficient processing of large Queries, especially when the test function is computationally expensive or the Query is large.

Arguments:

Argument
Type
Required
Default

closure

function:Predicate

true

null

parallel

boolean

false

false

maxThreads

any

false

null

virtual

boolean

false

false

chevron-rightfilter(callback=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])hashtag

Filters query rows specified in filter criteria This BIF will invoke the callback function for each row in the query, passing the row as a struct.

  • , ,

  • ,If the callback returns true, the row will be included in the new query.,

  • , ,

  • ,If the callback returns false, the row will be excluded from the new query.,

  • , ,

  • ,If the callback requires strict arguments, it will only receive the row as a struct.,

  • , ,

  • ,If the callback does not require strict arguments, it will receive the row as a struct, the row number (1-based), and the query itself.,

  • , ,

, ,

, ,

,Parallel Execution,

, If the ,,parallel,, argument is set to true, and no ,,max_threads,, are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If ,,max_threads,, is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to filter, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

Arguments:

Argument
Type
Required
Default

callback

function:Predicate

true

null

parallel

boolean

false

false

maxThreads

any

false

null

virtual

boolean

false

false

chevron-rightgetCell(column_name=[string], row_number=[integer])hashtag

This function maps the query to a new query.

Arguments:

Argument
Type
Required
Default

column_name

string

true

null

row_number

integer

false

null

chevron-rightgetResult()hashtag

Returns the metadata of a query.

chevron-rightgetRow(rowNumber=[integer])hashtag

Returns the cells of a query row as a structure

Arguments:

Argument
Type
Required
Default

rowNumber

integer

true

null

chevron-rightinsertAt(value=[query], position=[numeric])hashtag

Inserts a query data into another query at a specific position

Arguments:

Argument
Type
Required
Default

value

query

true

null

position

numeric

true

null

chevron-rightisEmpty()hashtag

Determine whether a given value is empty.

We check for emptiness of anything that can be casted to: Array, Struct, Query, or String.

chevron-rightkeyExists(key=[string])hashtag

This function returns true if the key exists in the query

Arguments:

Argument
Type
Required
Default

key

string

true

null

chevron-rightlen()hashtag

Returns the absolute value of a number

chevron-rightmap(callback=[function:Function], parallel=[boolean], maxThreads=[any], virtual=[boolean])hashtag

This BIF will iterate over each row in the query and invoke the callback function for each item so you can do any operation on the row and return a new value that will be set at the same index in a new query.

The callback function will be passed the row as a struct, the current row number (1-based), and the query itself. ,

  • , ,

  • ,If the callback requires strict arguments, it will only receive the row as a struct.,

  • , ,

  • ,If the callback does not require strict arguments, it will receive the row as a struct, the row number (1-based), and the query itself.,

  • , ,

, ,

, ,

,Parallel Execution,

, If the ,,parallel,, argument is set to true, and no ,,max_threads,, are sent, the map will be executed in parallel using a ForkJoinPool with parallel streams. If ,,max_threads,, is specified, it will create a new ForkJoinPool with the specified number of threads to run the map in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to map, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

Arguments:

Argument
Type
Required
Default

callback

function:Function

true

null

parallel

boolean

false

false

maxThreads

any

false

null

virtual

boolean

false

false

chevron-rightnone(callback=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])hashtag

Used to iterate over a Query and test whether NONE item meets the test callback.

This is the opposite of ,{@link QuerySome},. ,

, The function will be passed 3 arguments: the value, the index, and the Query. You can alternatively pass a Java Predicate which will only receive the 1st arg. The function should return true if the item meets the test, and false otherwise. ,

, ,,Note:,, This operation is a short-circuit operation, meaning it will stop iterating as soon as it finds the first item that does not meet the test condition. ,

, ,

,Parallel Execution,

, If the ,,parallel,, argument is set to true, and no ,,max_threads,, are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If ,,max_threads,, is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. This allows for efficient processing of large Queries, especially when the test function is computationally expensive or the Query is large.

Arguments:

Argument
Type
Required
Default

callback

function:Predicate

true

null

parallel

boolean

false

false

maxThreads

any

false

null

virtual

boolean

false

false

chevron-rightprepend(query2=[query])hashtag

Adds a query to the beginning of another query

Arguments:

Argument
Type
Required
Default

query2

query

true

null

chevron-rightrecordCount()hashtag

This function returns the number of records in a query

chevron-rightreduce(callback=[function:BiFunction], initialValue=[any])hashtag

This function reduces the query to a single value.

Arguments:

Argument
Type
Required
Default

callback

function:BiFunction

true

null

initialValue

any

true

null

chevron-rightreverse()hashtag

This function reverses the query data

chevron-rightrowData(rowNumber=[integer])hashtag

Returns the cells of a query row as a structure

Arguments:

Argument
Type
Required
Default

rowNumber

integer

true

null

chevron-rightrowSwap(source=[numeric], destination=[numeric])hashtag

In a query object, swap the record in the sourceRow with the record from the destinationRow.

Arguments:

Argument
Type
Required
Default

source

numeric

true

null

destination

numeric

true

null

chevron-rightsetCell(column=[string], value=[any], row=[integer])hashtag

Sets a cell to a value.

Arguments:

Argument
Type
Required
Default

column

string

true

null

value

any

true

null

row

integer

false

null

chevron-rightsetRow(rowNumber=[integer], rowData=[any])hashtag

Adds or updates a row in a query based on the provided row data and position.

Arguments:

Argument
Type
Required
Default

rowNumber

integer

false

0

rowData

any

true

null

chevron-rightslice(offset=[integer], length=[integer])hashtag

Returns a subset of rows from an existing query

Arguments:

Argument
Type
Required
Default

offset

integer

true

null

length

integer

false

0

chevron-rightsome(callback=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])hashtag

Used to iterate over a query and test whether ANY items meet the test callback.

The function will be passed 3 arguments: the row, the currentRow, and the query. You can alternatively pass a Java Predicate which will only receive the 1st arg. The function should return true if the item meets the test, and false otherwise. ,

, ,,Note:,, This operation is a short-circuit operation, meaning it will stop iterating as soon as it finds the first item that meets the test condition. ,

, ,

,Parallel Execution,

, If the ,,parallel,, argument is set to true, and no ,,max_threads,, are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If ,,max_threads,, is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to iterate, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance. ,

Arguments:

Argument
Type
Required
Default

callback

function:Predicate

true

null

parallel

boolean

false

false

maxThreads

any

false

null

virtual

boolean

false

false

chevron-rightsort(sortFunc=[function:Comparator])hashtag

Sorts array elements.

Arguments:

Argument
Type
Required
Default

sortFunc

function:Comparator

true

null

chevron-righttoArrayOfStructs()hashtag

Convert this query to an array of structs.

chevron-righttoJSON(queryFormat=[string], useSecureJSONPrefix=[string], useCustomSerializer=[boolean], pretty=[boolean])hashtag

Converts a BoxLang variable into a JSON (JavaScript Object Notation) string according to the specified options.

,Query Format Options,

, The ,,queryFormat,, argument determines how queries are serialized: ,

  • , ,

  • ,,row,, or ,,false,,: Serializes the query as a top-level struct with two keys: ,,columns,, (an array of column names) and ,,data,, (an array of arrays representing each row's data).,

  • , ,

  • ,,column,, or ,,true,,: Serializes the query as a top-level struct with three keys: ,,rowCount,, (the number of rows), ,,columns,, (an array of column names), and ,,data,, (a struct where each key is a column name and the value is an array of values for that column).,

  • , ,

  • ,,struct,,: Serializes the query as an array of structs, where each struct represents a row of data.,

  • , ,

,

,

,Usage,

,

,

Arguments:

Argument
Type
Required
Default

queryFormat

string

false

row

useSecureJSONPrefix

string

false

false

useCustomSerializer

boolean

false

null

pretty

boolean

false

false

chevron-righttoModifiable()hashtag

Convert an array, struct or query to its Modifiable counterpart.

chevron-righttoUnmodifiable()hashtag

Convert an array, struct or query to its Unmodifiable counterpart.

Examples

Last updated

Was this helpful?