All files / src/data-types bit-type.ts

100% Statements 3/3
100% Branches 4/4
100% Functions 1/1
100% Lines 3/3

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                            289x 289x           289x      
import { AbstractDataType } from './abstract-data-type.ts';
 
/**
 * `BIT(length)` / `BIT VARYING(length)` (`DataTypes.BIT`, `DataTypes.VARBIT`); values are strings
 * of `0` and `1`.
 *
 * @internal
 */
export class BitType extends AbstractDataType {
  /**
   * @param key - `'BIT'` or `'VARBIT'`.
   * @param length - Number of bits; `BIT` defaults to 1, `VARBIT` to unlimited.
   */
  constructor(key: 'BIT' | 'VARBIT', length?: number) {
    const sqlName = key === 'BIT' ? 'BIT' : 'BIT VARYING';
    super(
      key,
      length === undefined
        ? sqlName
        : `${sqlName}(${AbstractDataType.integer(`${key} length`, length)})`,
    );
    Object.freeze(this);
  }
}