Skip to content

Commit

Permalink
Build deno [autogenerated commit]
Browse files Browse the repository at this point in the history
  • Loading branch information
oguimbal committed Oct 11, 2024
1 parent 958898b commit 8f84e85
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 74 deletions.
82 changes: 42 additions & 40 deletions .deno/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,48 +128,50 @@ export class ColRef implements _Column {
}

alter(alter: AlterColumn, t: _Transaction): this {
switch (alter.type) {
case 'drop default':
this.default = null;
break;
case 'set default':
if (alter.default.type === 'null') {
withSelection(this.table.selection, () => {
switch (alter.type) {
case 'drop default':
this.default = null;
break;
}
const df = withSelection(this.table.selection, () => buildValue(alter.default));
if (!df.isConstant) {
throw new QueryError('cannot use column references in default expression');
}
if (alter.updateExisting) {
const defVal = df.get();
this.table.remapData(t, x => x[this.expression.id!] = defVal);
}
this.default = df;
break;
case 'set not null':
this.addNotNullConstraint(t);
break;
case 'drop not null':
this.notNull = false;
break;
case 'set type':
const newType = this.table.ownerSchema.getType(alter.dataType);
const conv = this.expression.cast(newType);
const eid = this.expression.id;

this.table.remapData(t, x => x[this.expression.id!] = conv.get(x, t));

// once converted, do nasty things to change expression
this.replaceExpression(eid!, newType);
break;
case 'add generated':
new GeneratedIdentityConstraint(alter.constraintName?.name, this)
.install(t, alter);
break;
default:
throw NotSupported.never(alter, 'alter column type');
}
case 'set default':
if (alter.default.type === 'null') {
this.default = null;
break;
}
const df = buildValue(alter.default);
if (!df.isConstant) {
throw new QueryError('cannot use column references in default expression');
}
if (alter.updateExisting) {
const defVal = df.get();
this.table.remapData(t, x => x[this.expression.id!] = defVal);
}
this.default = df;
break;
case 'set not null':
this.addNotNullConstraint(t);
break;
case 'drop not null':
this.notNull = false;
break;
case 'set type':
const newType = this.table.ownerSchema.getType(alter.dataType);
const conv = this.expression.cast(newType);
const eid = this.expression.id;

this.table.remapData(t, x => x[this.expression.id!] = conv.get(x, t));

// once converted, do nasty things to change expression
this.replaceExpression(eid!, newType);
break;
case 'add generated':
new GeneratedIdentityConstraint(alter.constraintName?.name, this)
.install(t, alter);
break;
default:
throw NotSupported.never(alter, 'alter column type');
}
});
this.table.db.onSchemaChange();
this.table.selection.rebuild();
return this;
Expand Down
3 changes: 3 additions & 0 deletions .deno/datatypes/datatype-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export abstract class TypeBase<TRaw = any> implements _IType<TRaw>, _RelationBas
get name(): string {
return this.primary;
}
get primaryName(): string {
return this.primary;
}


/** Compute a custom unicty hash for a non null value */
Expand Down
53 changes: 32 additions & 21 deletions .deno/datatypes/datatypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,27 @@ class TextType extends TypeBase<string> {
super(25);
}

doPrefer(to: _IType) {
doPrefer(to: _IType, stricterType?: boolean) {
if (to instanceof TextType) {
// returns the broader type
if (!to.len) {
return to;
}
if (!this.len) {
return this;
if (stricterType) {
// returns the stricter type
if (!to.len) {
return to;
}
if (!this.len) {
return this;
}
return to.len > this.len ? to : this;
} else {
// returns the broader type
if (!to.len) {
return to;
}
if (!this.len) {
return this;
}
return to.len < this.len ? to : this;
}
return to.len > this.len ? to : this;
}
if (this.canCast(to)) {
return to;
Expand Down Expand Up @@ -744,10 +755,10 @@ export const typeSynonyms: { [key: string]: DataType | { type: DataType; ignoreC


/** Finds a common type by implicit conversion */
export function reconciliateTypes(values: IValue[], nullIfNoMatch?: false): _IType;
export function reconciliateTypes(values: IValue[], nullIfNoMatch: true): _IType | nil;
export function reconciliateTypes(values: IValue[], nullIfNoMatch?: boolean): _IType | nil
export function reconciliateTypes(values: IValue[], nullIfNoMatch?: boolean): _IType | nil {
export function reconciliateTypes(values: IValue[], nullIfNoMatch?: false, stricterType?: boolean): _IType;
export function reconciliateTypes(values: IValue[], nullIfNoMatch: true, stricterType?: boolean): _IType | nil;
export function reconciliateTypes(values: IValue[], nullIfNoMatch?: boolean, stricterType?: boolean): _IType | nil
export function reconciliateTypes(values: IValue[], nullIfNoMatch?: boolean, stricterType?: boolean): _IType | nil {
// FROM https://www.postgresql.org/docs/current/typeconv-union-case.html

const nonNull = values
Expand All @@ -761,27 +772,27 @@ export function reconciliateTypes(values: IValue[], nullIfNoMatch?: boolean): _I
// If all inputs are of the same type, and it is not unknown, resolve as that type.
const single = new Set(nonNull
.map(v => v.type.reg.typeId));
if (single.size === 1) {
return nonNull[0].type;
}
// if (single.size === 1) {
// return nonNull[0].type;
// }

return reconciliateTypesRaw(nonNull, nullIfNoMatch);
return reconciliateTypesRaw(nonNull, nullIfNoMatch, stricterType);
}



/** Finds a common type by implicit conversion */
function reconciliateTypesRaw(values: IValue[], nullIfNoMatch?: false): _IType;
function reconciliateTypesRaw(values: IValue[], nullIfNoMatch: true): _IType | nil;
function reconciliateTypesRaw(values: IValue[], nullIfNoMatch?: boolean): _IType | nil
function reconciliateTypesRaw(values: IValue[], nullIfNoMatch?: boolean): _IType | nil {
function reconciliateTypesRaw(values: IValue[], nullIfNoMatch?: false, stricterType?: boolean): _IType;
function reconciliateTypesRaw(values: IValue[], nullIfNoMatch: true, stricterType?: boolean): _IType | nil;
function reconciliateTypesRaw(values: IValue[], nullIfNoMatch?: boolean, stricterType?: boolean): _IType | nil
function reconciliateTypesRaw(values: IValue[], nullIfNoMatch?: boolean, stricterType?: boolean): _IType | nil {
// find the matching type among non constants
const foundType = values
.reduce((final, c) => {
if (c.type === Types.null) {
return final;
}
const pref = final.prefer(c.type);
const pref = final.prefer(c.type, stricterType);
if (!pref) {
throw new CastError(c.type.primary, final.primary, c.id ?? undefined);
}
Expand Down
17 changes: 13 additions & 4 deletions .deno/datatypes/t-equivalent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Types } from './datatypes.ts';

export class EquivalentType extends TypeBase<string> {

private equiv: IType;
private equiv: _IType;

constructor(private def: IEquivalentType) {
super(null);
Expand All @@ -17,7 +17,7 @@ export class EquivalentType extends TypeBase<string> {
}
this.equiv = eq;
} else {
this.equiv = def.equivalentTo;
this.equiv = def.equivalentTo as _IType;
}

if (!this.equiv) {
Expand All @@ -26,7 +26,15 @@ export class EquivalentType extends TypeBase<string> {
}

get primary(): DataType {
return this.def.name as any;
return this.equiv.primary;
}

get primaryName(): string {
return this.def.name;
}

get name(): string {
return this.def.name;
}

doCanCast(to: _IType) {
Expand All @@ -42,7 +50,8 @@ export class EquivalentType extends TypeBase<string> {
}

doCanBuildFrom(from: _IType): boolean | nil {
return from.primary === this.equiv.primary;
// return from.canCast(this.equiv);
return this.equiv.canCast(from);
}

doBuildFrom(value: Evaluator<string>, from: _IType<string>): Evaluator<string> | nil {
Expand Down
4 changes: 3 additions & 1 deletion .deno/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { dateFunctions } from './date.ts';
import { systemFunctions } from './system.ts';
import { sequenceFunctions } from './sequence-fns.ts';
import { numberFunctions } from './numbers.ts';
import { subqueryFunctions } from './subquery.ts';


export const allFunctions = [
Expand All @@ -11,4 +12,5 @@ export const allFunctions = [
, ... systemFunctions
, ... sequenceFunctions
, ... numberFunctions
]
, ... subqueryFunctions
]
14 changes: 14 additions & 0 deletions .deno/functions/subquery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FunctionDefinition } from '../interfaces.ts';
import { DataType } from '../interfaces-private.ts';

export const subqueryFunctions: FunctionDefinition[] = [
{
name: 'exists',
args: [DataType.integer],
argsVariadic: DataType.integer,
returns: DataType.bool,
allowNullArguments: true,
impure: true,
implementation: (...items: number[]) => items?.some?.(Boolean) ?? false,
},
];
6 changes: 6 additions & 0 deletions .deno/functions/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ export const systemFunctions: FunctionDefinition[] = [
returns: Types.text(),
implementation: () => 'public',
},
{
name: 'obj_description',
args: [Types.regclass, Types.text()],
returns: Types.null,
implementation: () => null
},
]
3 changes: 2 additions & 1 deletion .deno/interfaces-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ export interface _IType<TRaw = any> extends IType, _RelationBase {
readonly type: 'type';
/** Data type */
readonly primary: DataType;
readonly primaryName: string;
/** Reg type name */
readonly name: string; // | null;
readonly reg: Reg;
Expand All @@ -516,7 +517,7 @@ export interface _IType<TRaw = any> extends IType, _RelationBase {
canCast(to: _IType<TRaw>): boolean | nil;
cast<T = any>(value: IValue<TRaw>, to: _IType<T>): IValue;
convertImplicit<T = any>(value: IValue<TRaw>, to: _IType<T>): IValue;
prefer(type: _IType<any>): _IType | nil;
prefer(type: _IType<any>, stricterType?: boolean): _IType | nil;

/** Build an array type for this type */
asArray(): _IType<TRaw[]>;
Expand Down
3 changes: 3 additions & 0 deletions .deno/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ export interface ISchema {
/** Register a simple type, which is equivalent to another */
registerEquivalentType(type: IEquivalentType): IType;

/** Register a simple type, which is equivalent to another */
registerEquivalentSizableType(type: IEquivalentType): IType;

/** Get an existing type */
getType(name: DataType): IType;

Expand Down
6 changes: 6 additions & 0 deletions .deno/schema/pg-catalog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { DataType, FunctionDefinition, _IDb, _ISchema } from '../../interfaces-p
import { PgAttributeTable } from './pg-attribute-list.ts';
import { PgClassListTable } from './pg-class.ts';
import { PgConstraintTable } from './pg-constraints-list.ts';
import { PgEnumTable } from './pg-enum-list.ts';
import { PgIndexTable } from './pg-index-list.ts';
import { PgNamespaceTable } from './pg-namespace-list.ts';
import { PgSequencesTable } from './pg-sequences-list.ts';
import { PgTypeTable } from './pg-type-list.ts';
import { PgUserTable } from './pg-user-list.ts';
import { allFunctions } from '../../functions/index.ts';
import { PgRange } from './pg-range.ts';
import { sqlSubstring } from '../../parser/expression-builder.ts';
Expand Down Expand Up @@ -58,6 +61,9 @@ export function setupPgCatalog(db: _IDb) {
new PgProc(catalog).register();
new PgDatabaseTable(catalog).register();
new PgStatioUserTables(catalog).register();
new PgEnumTable(catalog).register();
new PgSequencesTable(catalog).register();
new PgUserTable(catalog).register();


// this is an ugly hack...
Expand Down
28 changes: 28 additions & 0 deletions .deno/schema/pg-catalog/pg-enum-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { _ITable, _ISelection, _IIndex, _IDb, _ISchema } from '../../interfaces-private.ts';
import { Schema } from '../../interfaces.ts';
import { Types } from '../../datatypes/index.ts';
import { ReadOnlyTable } from '../readonly-table.ts';

export class PgEnumTable extends ReadOnlyTable implements _ITable {

_schema: Schema = {
name: 'pg_enum',
fields: [
{ name: 'oid', type: Types.integer }
, { name: 'enumtypid', type: Types.integer }
, { name: 'enumsortorder', type: Types.integer }
, { name: 'enumlabel', type: Types.text() }
]
};

entropy(): number {
return 0;
}

*enumerate() {
}

hasItem(value: any): boolean {
return false;
}
}
35 changes: 35 additions & 0 deletions .deno/schema/pg-catalog/pg-sequences-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { _ITable, _ISelection, _IIndex, _IDb, _ISchema } from '../../interfaces-private.ts';
import { Schema } from '../../interfaces.ts';
import { Types } from '../../datatypes/index.ts';
import { ReadOnlyTable } from '../readonly-table.ts';

export class PgSequencesTable extends ReadOnlyTable implements _ITable {

_schema: Schema = {
name: 'pg_sequences',
fields: [
{ name: 'schemaname', type: Types.text() }
, { name: 'sequencename', type: Types.text() }
, { name: 'sequenceowner', type: Types.integer }
, { name: 'data_type', type: Types.text() }
, { name: 'start_value', type: Types.integer }
, { name: 'min_value', type: Types.integer }
, { name: 'max_value', type: Types.integer }
, { name: 'increment_by', type: Types.integer }
, { name: 'cycle', type: Types.bool }
, { name: 'cache_size', type: Types.integer }
, { name: 'last_value', type: Types.integer }
]
};

entropy(): number {
return 0;
}

*enumerate() {
}

hasItem(value: any): boolean {
return false;
}
}
Loading

0 comments on commit 8f84e85

Please sign in to comment.