import { BaseNode, Keyword } from "./Base"; import { StringLiteral } from "./Literal"; import { Expr, Identifier, ListExpr, ParenExpr, EntityName } from "./Expr"; import { SortDirectionAsc, SortDirectionDesc, WhereClause } from "./Select"; import { BigqueryOptions } from "./dialects/Bigquery"; import { Default } from "./Insert"; import { UsingAccessMethodClause } from "./CreateTable"; import { PostgresqlOperator, PostgresqlOperatorExpr, PostgresqlOptions, PostgresqlWithOptions } from "./dialects/Postgresql"; import { SequenceOptionList } from "./Sequence"; import { IndexIncludeClause, IndexSpecification } from "./Index"; export type AllConstraintNodes = Constraint | ConstraintNull | ConstraintNotNull | ConstraintDefault | ConstraintAutoIncrement | ConstraintUnique | ConstraintPrimaryKey | ExistingIndex | ReferencesSpecification | ConstraintComment | ConstraintCheck | ConstraintIndex | ConstraintGenerated | IdentityColumn | ConstraintCollate | ConstraintVisible | ConstraintColumnFormat | ConstraintStorage | ConstraintEngineAttribute | ConstraintCompression | ConstraintForeignKey | ConstraintName | ConstraintModifier | ConstraintExclude | ExclusionParam | ReferentialAction | ReferentialMatch | OnConflictClause | IndexTablespaceClause; export interface Constraint extends BaseNode { type: "constraint"; name?: ConstraintName; constraint: T; modifiers: ConstraintModifier[]; } export interface ConstraintName extends BaseNode { type: "constraint_name"; constraintKw: Keyword<"CONSTRAINT">; name?: Identifier; } export interface ConstraintModifier extends BaseNode { type: "constraint_modifier"; kw: Keyword<"DEFERRABLE"> | [Keyword<"NOT">, Keyword<"DEFERRABLE">] | [Keyword<"INITIALLY">, Keyword<"IMMEDIATE" | "DEFERRED">] | Keyword<"ENFORCED"> | [Keyword<"NOT">, Keyword<"ENFORCED">] | [Keyword<"NO">, Keyword<"INHERIT">] | [Keyword<"NOT">, Keyword<"VALID">]; } export type TableConstraint = ConstraintPrimaryKey | ConstraintForeignKey | ConstraintUnique | ConstraintCheck | ConstraintIndex | ConstraintExclude; export type ColumnConstraint = ConstraintNull | ConstraintNotNull | ConstraintDefault | ConstraintAutoIncrement | ConstraintUnique | ConstraintPrimaryKey | ReferencesSpecification | ConstraintComment | ConstraintCheck | ConstraintIndex | ConstraintGenerated | ConstraintCollate | ConstraintVisible | ConstraintColumnFormat | ConstraintStorage | ConstraintEngineAttribute | ConstraintCompression | BigqueryOptions | PostgresqlOptions; export type DomainConstraint = ConstraintCollate | ConstraintDefault | ConstraintNull | ConstraintNotNull | ConstraintCheck; export interface ConstraintPrimaryKey extends BaseNode { type: "constraint_primary_key"; primaryKeyKw: [Keyword<"PRIMARY">, Keyword<"KEY">] | Keyword<"KEY">; direction?: SortDirectionAsc | SortDirectionDesc; columns?: ParenExpr> | ExistingIndex; clauses: (IndexParameterClause | OnConflictClause)[]; } export interface ExistingIndex extends BaseNode { type: "existing_index"; usingIndexKw: [Keyword<"USING">, Keyword<"INDEX">]; index: Identifier; } export interface ConstraintForeignKey extends BaseNode { type: "constraint_foreign_key"; foreignKeyKw: [Keyword<"FOREIGN">, Keyword<"KEY">]; indexName?: Identifier; columns: ParenExpr>; references: ReferencesSpecification; } export interface ReferencesSpecification extends BaseNode { type: "references_specification"; referencesKw: Keyword<"REFERENCES">; table: EntityName; columns?: ParenExpr>; options: (ReferentialAction | ReferentialMatch)[]; } export interface ReferentialAction extends BaseNode { type: "referential_action"; onKw: Keyword<"ON">; eventKw: Keyword<"DELETE" | "UPDATE">; actionKw: Keyword<"RESTRICT" | "CASCADE"> | [Keyword<"SET">, Keyword<"NULL" | "DEFAULT">] | [Keyword<"NO">, Keyword<"ACTION">]; columns?: ParenExpr>; } export interface ReferentialMatch extends BaseNode { type: "referential_match"; matchKw: Keyword<"MATCH">; typeKw: Keyword<"FULL" | "PARTIAL" | "SIMPLE">; } export interface ConstraintUnique extends BaseNode { type: "constraint_unique"; uniqueKw: Keyword<"UNIQUE"> | [Keyword<"UNIQUE">, Keyword<"KEY" | "INDEX">]; nullsKw?: [Keyword<"NULLS">, Keyword<"DISTINCT">] | [Keyword<"NULLS">, Keyword<"NOT">, Keyword<"DISTINCT">]; columns?: ParenExpr> | ExistingIndex; clauses: (IndexParameterClause | OnConflictClause)[]; } export interface ConstraintCheck extends BaseNode { type: "constraint_check"; checkKw: Keyword<"CHECK">; expr: ParenExpr; clauses: OnConflictClause[]; } export interface ConstraintIndex extends BaseNode { type: "constraint_index"; indexTypeKw?: Keyword<"FULLTEXT" | "SPATIAL">; indexKw: Keyword<"INDEX" | "KEY">; columns?: ParenExpr>; } export interface ConstraintNull extends BaseNode { type: "constraint_null"; nullKw: Keyword<"NULL">; } export interface ConstraintNotNull extends BaseNode { type: "constraint_not_null"; notNullKw: [Keyword<"NOT">, Keyword<"NULL">]; clauses: OnConflictClause[]; } export interface ConstraintDefault extends BaseNode { type: "constraint_default"; defaultKw: Keyword<"DEFAULT">; expr: Expr; } export interface ConstraintAutoIncrement extends BaseNode { type: "constraint_auto_increment"; autoIncrementKw: Keyword<"AUTO_INCREMENT" | "AUTOINCREMENT">; } export interface ConstraintComment extends BaseNode { type: "constraint_comment"; commentKw: Keyword<"COMMENT">; value: StringLiteral; } export interface ConstraintGenerated extends BaseNode { type: "constraint_generated"; generatedKw?: [Keyword<"GENERATED">, Keyword<"ALWAYS">] | [Keyword<"GENERATED">, Keyword<"BY">, Keyword<"DEFAULT">]; asKw: Keyword<"AS">; expr: ParenExpr | IdentityColumn; storageKw?: Keyword<"STORED" | "VIRTUAL">; sequenceOptions?: ParenExpr; } export interface IdentityColumn extends BaseNode { type: "identity_column"; identityKw: Keyword<"IDENTITY">; } export interface ConstraintCollate extends BaseNode { type: "constraint_collate"; collateKw: Keyword<"COLLATE">; collation: Identifier | StringLiteral; } export interface ConstraintVisible extends BaseNode { type: "constraint_visible"; visibleKw: Keyword<"VISIBLE" | "INVISIBLE">; } export interface ConstraintColumnFormat extends BaseNode { type: "constraint_column_format"; columnFormatKw: Keyword<"COLUMN_FORMAT">; formatKw: Keyword<"FIXED" | "DYNAMIC" | "DEFAULT">; } export interface ConstraintStorage extends BaseNode { type: "constraint_storage"; storageKw: Keyword<"STORAGE">; typeKw: Keyword<"DISK" | "MEMORY" | "PLAIN" | "EXTERNAL" | "EXTENDED" | "MAIN" | "DEFAULT">; } export interface ConstraintEngineAttribute extends BaseNode { type: "constraint_engine_attribute"; engineAttributeKw: Keyword<"ENGINE_ATTRIBUTE" | "SECONDARY_ENGINE_ATTRIBUTE">; hasEq: boolean; value: StringLiteral; } export interface ConstraintCompression extends BaseNode { type: "constraint_compression"; compressionKw: Keyword<"COMPRESSION">; method: Identifier | Default; } export interface ConstraintExclude extends BaseNode { type: "constraint_exclude"; excludeKw: Keyword<"EXCLUDE">; using?: UsingAccessMethodClause; params: ParenExpr>; clauses: (IndexParameterClause | WhereClause)[]; } export interface ExclusionParam extends BaseNode { type: "exclusion_param"; index: IndexSpecification; withKw: Keyword<"WITH">; operator: PostgresqlOperatorExpr | PostgresqlOperator; } export interface OnConflictClause extends BaseNode { type: "on_conflict_clause"; onConflictKw: [Keyword<"ON">, Keyword<"CONFLICT">]; resolutionKw: Keyword<"ROLLBACK" | "ABORT" | "FAIL" | "IGNORE" | "REPLACE">; } type IndexParameterClause = IndexIncludeClause | PostgresqlWithOptions | IndexTablespaceClause; export interface IndexTablespaceClause extends BaseNode { type: "index_tablespace_clause"; usingIndexTablespaceKw: [ Keyword<"USING">, Keyword<"INDEX">, Keyword<"TABLESPACE"> ]; name: Identifier; } export {};