import { Type } from './Type.js';
/** Maps a database BLOB/BYTEA column to a JS `Uint8Array`. */
export class Uint8ArrayType extends Type {
  convertToDatabaseValue(value) {
    if (!value) {
      return value;
    }
    return Buffer.from(value);
  }
  convertToJSValue(value) {
    /* v8 ignore next */
    if (!value) {
      return value;
    }
    if (value instanceof Buffer) {
      return new Uint8Array(value);
    }
    if (value.buffer instanceof Buffer) {
      return new Uint8Array(value.buffer);
    }
    return new Uint8Array(Buffer.from(value));
  }
  compareAsType() {
    return 'Buffer';
  }
  getColumnType(prop, platform) {
    return platform.getBlobDeclarationSQL();
  }
}
