Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 143x 143x 143x 143x 143x 143x | import { AbstractDataType, type DataType, type DataTypeInput } from './abstract-data-type.ts';
/**
* Attribute that is not stored in the database (`DataTypes.VIRTUAL`).
*
* @internal
*/
export class VirtualType extends AbstractDataType {
/** The attribute is not stored in the database. */
readonly isVirtual = true;
/** Attributes the computed value depends on; a query that selects the virtual attribute selects these instead. */
readonly dependencies: readonly string[];
/** Type of the computed value (v6 `returnType`); `undefined` without one. */
readonly returnType: DataType | undefined;
/** Attributes the value is computed from (v6 `fields`). */
readonly fields: readonly string[];
/**
* @param returnType - Type of the computed value.
* @param fields - Attributes the value is computed from.
*/
constructor(returnType?: DataTypeInput, fields: readonly string[] = []) {
super(
'VIRTUAL',
returnType === undefined ? 'VIRTUAL' : AbstractDataType.from(returnType).sqlType,
);
this.dependencies = fields;
this.fields = fields;
this.returnType = returnType === undefined ? undefined : AbstractDataType.from(returnType);
Object.freeze(this);
}
}
|