ReturningOptions interface
Widens returning so it can name the columns to fetch back, not just ask whether to fetch any.
Signature:
export interface ReturningOptions
Remarks
Sequelize types returning as a boolean: every column, or none. Postgres can return a subset, and a service usually wants exactly the fields its caller asked for — so this package accepts a list of column names and rewrites the RETURNING * in the generated statement to name just those.
Two things follow. Less data crosses both hops: the database returns fewer columns, and the instance remembers the list, so serializing it emits only those properties. And because the option is widened rather than replaced, true and false keep working exactly as before. An empty array is treated as false, since a statement returning no columns is not what anyone means by it.
The cost is a cast at the call site, and the mimicked option types in this module are what to cast to — they exist for this and nothing else. Whenever TypeScript objects to a returning array, import the type it names from @imqueue/pg-sequelize rather than from sequelize. Use restoreSerialization() to forget the list again.
Example
const scope = new Scope({ name: 'test', description: 'Test', schema: {} });
await scope.save({ returning: ['id', 'name'] } as SaveOptions);
console.log(JSON.stringify(scope)); // {"id":2,"name":"test"}
const [count, scopes] = await Scope.update({ name: 'TEST' }, {
where: { id: 2 },
returning: ['id', 'name'],
} as UpdateOptions);
console.log(JSON.stringify(scopes[0])); // {"id":2,"name":"TEST"}
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
boolean | string[] |
(Optional) |