import { ColumnDefinition , makeColumnDefinition } from './column' ; const variableLength = ( string , ... n ) => { const pruned = n . filter ( ( i ) => i != undefined ) ; return pruned . length > 0 ? `${ string }(${ pruned . join ( `, ` ) })` : string ; } ; const makeDataType = makeColumnDefinition ; export type GetNotNull < Left , Right > = Right extends true ? Left extends true ? true : false : false ; export type GetMostSignificantDataType < Left , Right > = Left & Right extends Float8 ? Float8 : Left extends Float4 ? Right extends Float4 ? Float4 : Left & Right extends Float4 ? Float8 : Left & Right extends Numeric ? Numeric : Left & Right extends Int8 ? Int8 : Int4 : Left & Right extends Float4 ? Float8 : Left & Right extends Numeric ? Numeric : Left & Right extends Int8 ? Int8 : Int4 ; export type Int4 = 'Int4' ; export type Int8 = 'Int8' ; export type Float4 = 'Float4' ; export type Float8 = 'Float8' ; export type Numeric = 'Numeric' ; export type AnyNumber = Int4 | Int8 | Float4 | Float8 | Numeric ; export type Text = 'Text' ; export type Date = 'Date' ; export type DateTime = 'DateTime' ; export type Time = 'Time' ; export type Any = AnyNumber | Text | Date | DateTime ; export type Uuid < T > = InternalUuid < T > ; export class InternalUuid < T > { private _uuidBrand ! : [ 'uuid' , T ] ; } export type ToPostgresDataType < T extends string > = T extends DateTime ? 'timestamptz' : Lowercase < T > ; export function dataType < T > ( dataType ) { return makeDataType < T > ( dataType ) ; } export function int8 ( ) ; export function int8 < T > ( ) ; export function int8 ( ) { return makeDataType ( `int8` ) ; } export function bigint ( ) ; export function bigint < T > ( ) ; export function bigint ( ) { return makeDataType ( `bigint` ) ; } export function bigserial ( ) ; export function bigserial < T > ( ) ; export function bigserial ( ) { return makeDataType ( `bigserial` ) ; } export function serial8 ( ) ; export function serial8 < T > ( ) ; export function serial8 ( ) { return makeDataType ( `serial8` ) ; } export function serial ( ) ; export function serial < T > ( ) ; export function serial ( ) { return makeDataType ( `serial` ) ; } export function serial4 ( ) ; export function serial4 < T > ( ) ; export function serial4 ( ) { return makeDataType ( `serial4` ) ; } export function smallserial ( ) ; export function smallserial < T > ( ) ; export function smallserial ( ) { return makeDataType ( `smallserial` ) ; } export function serial2 ( ) ; export function serial2 < T > ( ) ; export function serial2 ( ) { return makeDataType ( `serial2` ) ; } export function bit ( n ? ) ; export function bit < T > ( n ? ) ; export function bit ( n ? ) { return makeDataType ( variableLength ( `bit` , n ) ) ; } export function bitVarying ( n ? ) ; export function bitVarying < T > ( n ? ) ; export function bitVarying ( n ? ) { return makeDataType ( variableLength ( `bit varying` , n ) ) ; } export function varbit ( n ? ) ; export function varbit < T > ( n ? ) ; export function varbit ( n ? ) { return makeDataType ( variableLength ( `varbit` , n ) ) ; } export function boolean ( ) ; export function boolean < T > ( ) ; export function boolean ( ) { return makeDataType ( `boolean` ) ; } export function bool ( ) ; export function bool < T > ( ) ; export function bool ( ) { return makeDataType ( `bool` ) ; } export function box ( ) ; export function box < T > ( ) ; export function box ( ) { return makeDataType ( `box` ) ; } export function bytea ( ) ; export function bytea < T > ( ) ; export function bytea ( ) { return makeDataType ( `bytea` ) ; } export function character ( n ? ) ; export function character < T > ( n ? ) ; export function character ( n ? ) { return makeDataType ( variableLength ( `character` , n ) ) ; } export function char ( n ? ) ; export function char < T > ( n ? ) ; export function char ( n ? ) { return makeDataType ( variableLength ( `char` , n ) ) ; } export function characterVarying ( n ? ) ; export function characterVarying < T > ( n ? ) ; export function characterVarying ( n ? ) { return makeDataType ( variableLength ( `character varying` , n ) ) ; } export function varchar ( n ? ) ; export function varchar < T > ( n ? ) ; export function varchar ( n ? ) { return makeDataType ( variableLength ( `varchar` , n ) ) ; } export function circle ( ) ; export function circle < T > ( ) ; export function circle ( ) { return makeDataType ( `circle` ) ; } export function cidr ( ) ; export function cidr < T > ( ) ; export function cidr ( ) { return makeDataType ( `cidr` ) ; } export function caseInsensitiveText ( ) ; export function caseInsensitiveText < T > ( ) ; export function caseInsensitiveText ( ) { return makeDataType ( `citext` ) ; } export function citext ( ) ; export function citext < T > ( ) ; export function citext ( ) { return makeDataType ( `citext` ) ; } export function date ( ) ; export function date < T > ( ) ; export function date ( ) { return makeDataType ( `date` ) ; } export function doublePrecision ( ) ; export function doublePrecision < T > ( ) ; export function doublePrecision ( ) { return makeDataType ( `double precision` ) ; } export function float8 ( ) ; export function float8 < T > ( ) ; export function float8 ( ) { return makeDataType ( `float8` ) ; } export function inet ( ) ; export function inet < T > ( ) ; export function inet ( ) { return makeDataType ( `inet` ) ; } export function decimal ( ) ; export function decimal ( p ) ; export function decimal ( p , s ) ; export function decimal < T > ( ) ; export function decimal < T > ( p ) ; export function decimal < T > ( p , s ) ; export function decimal ( ... n ) { return makeDataType ( variableLength ( `decimal` , ... n ) ) ; } export function integer ( ) ; export function integer < T > ( ) ; export function integer ( ) { return makeDataType ( `integer` ) ; } export function int ( ) ; export function int < T > ( ) ; export function int ( ) { return makeDataType ( `int` ) ; } export function int4 ( ) ; export function int4 < T > ( ) ; export function int4 ( ) { return makeDataType ( `int4` ) ; } export function interval ( ) ; export function interval < T > ( ) ; export function interval ( ) { return makeDataType ( `interval` ) ; } export function json ( ) ; export function json < T > ( ) ; export function json ( ) { return makeDataType ( `json` ) ; } export function jsonb ( ) ; export function jsonb < T > ( ) ; export function jsonb ( ) { return makeDataType ( `jsonb` ) ; } export function line ( ) ; export function line < T > ( ) ; export function line ( ) { return makeDataType ( `line` ) ; } export function lseg ( ) ; export function lseg < T > ( ) ; export function lseg ( ) { return makeDataType ( `lseg` ) ; } export function macaddr ( ) ; export function macaddr < T > ( ) ; export function macaddr ( ) { return makeDataType ( `macaddr` ) ; } export function macaddr8 ( ) ; export function macaddr8 < T > ( ) ; export function macaddr8 ( ) { return makeDataType ( `macaddr8` ) ; } export function money ( ) ; export function money < T > ( ) ; export function money ( ) { return makeDataType ( `money` ) ; } export function numeric ( ) ; export function numeric ( p ) ; export function numeric ( p , s ) ; export function numeric < T > ( ) ; export function numeric < T > ( p ) ; export function numeric < T > ( p , s ) ; export function numeric ( ... n ) { return makeDataType ( variableLength ( `numeric` , ... n ) ) ; } export function point ( ) ; export function point < T > ( ) ; export function point ( ) { return makeDataType ( `point` ) ; } export function path ( ) ; export function path < T > ( ) ; export function path ( ) { return makeDataType ( `path` ) ; } export function pgLsn ( ) ; export function pgLsn < T > ( ) ; export function pgLsn ( ) { return makeDataType ( `pg_lsn` ) ; } export function polygon ( ) ; export function polygon < T > ( ) ; export function polygon ( ) { return makeDataType ( `polygon` ) ; } export function real ( ) ; export function real < T > ( ) ; export function real ( ) { return makeDataType ( `real` ) ; } export function float4 ( ) ; export function float4 < T > ( ) ; export function float4 ( ) { return makeDataType ( `float4` ) ; } export function smallint ( ) ; export function smallint < T > ( ) ; export function smallint ( ) { return makeDataType ( `smallint` ) ; } export function int2 ( ) ; export function int2 < T > ( ) ; export function int2 ( ) { return makeDataType ( `int2` ) ; } export function text ( ) ; export function text < T > ( ) ; export function text ( ) { return makeDataType ( `text` ) ; } export function time ( ) ; export function time < T > ( ) ; export function time ( ) { return makeDataType ( `time` ) ; } export function timeWithoutTimeZone ( ) ; export function timeWithoutTimeZone < T > ( ) ; export function timeWithoutTimeZone ( ) { return makeDataType ( `time without time zone` ) ; } export function timeWithTimeZone ( ) ; export function timeWithTimeZone < T > ( ) ; export function timeWithTimeZone ( ) { return makeDataType ( `time with time zone` ) ; } export function timestamp ( ) ; export function timestamp < T > ( ) ; export function timestamp ( ) { return makeDataType ( `timestamp` ) ; } export function timestamptz ( ) ; export function timestamptz < T > ( ) ; export function timestamptz ( ) { return makeDataType ( `timestamptz` ) ; } export function timestampWithoutTimeZone ( ) ; export function timestampWithoutTimeZone < T > ( ) ; export function timestampWithoutTimeZone ( ) { return makeDataType ( `timestamp without time zone` ) ; } export function timestampWithTimeZone ( ) ; export function timestampWithTimeZone < T > ( ) ; export function timestampWithTimeZone ( ) { return makeDataType ( `timestamp with time zone` ) ; } export function tsquery ( ) ; export function tsquery < T > ( ) ; export function tsquery ( ) { return makeDataType ( `tsquery` ) ; } export function tsvector ( ) ; export function tsvector < T > ( ) ; export function tsvector ( ) { return makeDataType ( `tsvector` ) ; } export function txidSnapshot ( ) ; export function txidSnapshot < T > ( ) ; export function txidSnapshot ( ) { return makeDataType ( `txid_snapshot` ) ; } export function uuid ( ) ; export function uuid < T > ( ) ; export function uuid ( ) { return makeDataType ( `uuid` ) ; } export function xml ( ) ; export function xml < T > ( ) ; export function xml ( ) { return makeDataType ( `xml` ) ; } export function enumType < EnumValue > ( name , values ) { return makeDataType < EnumValue > ( name , values as any ) ; } export function array < T > ( dataType ) { return internalArray < T [ ] > ( dataType , 1 ) ; } export function array2d < T > ( dataType ) { return internalArray < T [ ] [ ] > ( dataType , 2 ) ; } function internalArray < T > ( dataType , dimensions ) { const definition = dataType . getDefinition ( ) ; return makeDataType < T > ( definition . dataType + '[]' . repeat ( dimensions ) ) ; }