Skip to main content

Param

Represents an external bind parameter. Serializes to :name by default (a dialect extension may render a different placeholder syntax). See Raw SQL and Parameters for a full walkthrough.

Constructor

Param(name: string, dataType?: DataType, isArray?: boolean): Param
Param(args: Param.Args): Param
new Param(...): Param

Dual-callable, with two argument forms:

interface Param.Args {
name: string;
dataType?: DataType;
isArray?: boolean;
}
import { Param, DataType } from '@sqb/builder';

Param('id');
Param('id', DataType.INTEGER, false);
Param({ name: 'id', dataType: DataType.INTEGER });

Properties

KeyTypeReadonlyDescription
_typeSerializationType.EXTERNAL_PARAMETERYesDiscriminates this node during serialization.
_namestringNoParameter name.
_dataTypeDataType | undefinedNoOptional data type hint, surfaced on GenerateResult.paramOptions.
_isArrayboolean | undefinedNoOptional array-parameter hint.

Methods

Param has no chainable methods — its serialization logic resolves the parameter's value from ctx.params (populated from generate({ params }) or .values()), records it on GenerateResult.params/paramOptions, and renders :name.

import { Select, Eq, Param } from '@sqb/builder';

const result = Select().from('customers').where(Eq('id', Param('id'))).generate({
params: { id: 1 },
});

result.sql; // select * from customers where id = :id
result.params; // { id: 1 }

See also