Skip to main content

SerializeFunction

The type of the optional serialize field on SerializerExtension. Relevant only to authors of a dialect/adapter package writing a custom node renderer — not to everyday query building.

type SerializeFunction = (
ctx: SerializeContext,
type: SerializationType | string,
obj: any,
defFn: DefaultSerializeFunction,
) => string | undefined;

Parameters

ParameterTypeDescription
ctxSerializeContextThe active serialization context for the whole .generate() call.
typeSerializationType | stringThe kind of node being rendered — see SerializationType.
objanyThe node's own serialized-data shape (varies per type).
defFnDefaultSerializeFunctionCall this to fall back to the builder's default rendering for the node, e.g. return defFn(ctx, obj).

Return a string to override the rendering for this node, or undefined to let the next registered extension (or the default renderer) handle it.

import { SerializerRegistry, SerializationType } from '@sqb/builder';

SerializerRegistry.register({
dialect: 'my-dialect',
serialize(ctx, type, obj, defFn) {
if (type === SerializationType.SELECT_QUERY_JOIN) {
return undefined; // fall through
}
return defFn(ctx, obj);
},
});

See also