blob.d.cts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import type { ColumnBuilderBaseConfig } from "../../column-builder.cjs";
  2. import type { ColumnBaseConfig } from "../../column.cjs";
  3. import { entityKind } from "../../entity.cjs";
  4. import { type Equal } from "../../utils.cjs";
  5. import { SQLiteColumn, SQLiteColumnBuilder } from "./common.cjs";
  6. type BlobMode = 'buffer' | 'json' | 'bigint';
  7. export type SQLiteBigIntBuilderInitial<TName extends string> = SQLiteBigIntBuilder<{
  8. name: TName;
  9. dataType: 'bigint';
  10. columnType: 'SQLiteBigInt';
  11. data: bigint;
  12. driverParam: Buffer;
  13. enumValues: undefined;
  14. }>;
  15. export declare class SQLiteBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'SQLiteBigInt'>> extends SQLiteColumnBuilder<T> {
  16. static readonly [entityKind]: string;
  17. constructor(name: T['name']);
  18. }
  19. export declare class SQLiteBigInt<T extends ColumnBaseConfig<'bigint', 'SQLiteBigInt'>> extends SQLiteColumn<T> {
  20. static readonly [entityKind]: string;
  21. getSQLType(): string;
  22. mapFromDriverValue(value: Buffer | Uint8Array | ArrayBuffer): bigint;
  23. mapToDriverValue(value: bigint): Buffer;
  24. }
  25. export type SQLiteBlobJsonBuilderInitial<TName extends string> = SQLiteBlobJsonBuilder<{
  26. name: TName;
  27. dataType: 'json';
  28. columnType: 'SQLiteBlobJson';
  29. data: unknown;
  30. driverParam: Buffer;
  31. enumValues: undefined;
  32. }>;
  33. export declare class SQLiteBlobJsonBuilder<T extends ColumnBuilderBaseConfig<'json', 'SQLiteBlobJson'>> extends SQLiteColumnBuilder<T> {
  34. static readonly [entityKind]: string;
  35. constructor(name: T['name']);
  36. }
  37. export declare class SQLiteBlobJson<T extends ColumnBaseConfig<'json', 'SQLiteBlobJson'>> extends SQLiteColumn<T> {
  38. static readonly [entityKind]: string;
  39. getSQLType(): string;
  40. mapFromDriverValue(value: Buffer | Uint8Array | ArrayBuffer): T['data'];
  41. mapToDriverValue(value: T['data']): Buffer;
  42. }
  43. export type SQLiteBlobBufferBuilderInitial<TName extends string> = SQLiteBlobBufferBuilder<{
  44. name: TName;
  45. dataType: 'buffer';
  46. columnType: 'SQLiteBlobBuffer';
  47. data: Buffer;
  48. driverParam: Buffer;
  49. enumValues: undefined;
  50. }>;
  51. export declare class SQLiteBlobBufferBuilder<T extends ColumnBuilderBaseConfig<'buffer', 'SQLiteBlobBuffer'>> extends SQLiteColumnBuilder<T> {
  52. static readonly [entityKind]: string;
  53. constructor(name: T['name']);
  54. }
  55. export declare class SQLiteBlobBuffer<T extends ColumnBaseConfig<'buffer', 'SQLiteBlobBuffer'>> extends SQLiteColumn<T> {
  56. static readonly [entityKind]: string;
  57. mapFromDriverValue(value: Buffer | Uint8Array | ArrayBuffer): T['data'];
  58. getSQLType(): string;
  59. }
  60. export interface BlobConfig<TMode extends BlobMode = BlobMode> {
  61. mode: TMode;
  62. }
  63. /**
  64. * It's recommended to use `text('...', { mode: 'json' })` instead of `blob` in JSON mode, because it supports JSON functions:
  65. * >All JSON functions currently throw an error if any of their arguments are BLOBs because BLOBs are reserved for a future enhancement in which BLOBs will store the binary encoding for JSON.
  66. *
  67. * https://www.sqlite.org/json1.html
  68. */
  69. export declare function blob(): SQLiteBlobJsonBuilderInitial<''>;
  70. export declare function blob<TMode extends BlobMode = BlobMode>(config?: BlobConfig<TMode>): Equal<TMode, 'bigint'> extends true ? SQLiteBigIntBuilderInitial<''> : Equal<TMode, 'buffer'> extends true ? SQLiteBlobBufferBuilderInitial<''> : SQLiteBlobJsonBuilderInitial<''>;
  71. export declare function blob<TName extends string, TMode extends BlobMode = BlobMode>(name: TName, config?: BlobConfig<TMode>): Equal<TMode, 'bigint'> extends true ? SQLiteBigIntBuilderInitial<TName> : Equal<TMode, 'buffer'> extends true ? SQLiteBlobBufferBuilderInitial<TName> : SQLiteBlobJsonBuilderInitial<TName>;
  72. export {};