Skip to content

Commit 34372e0

Browse files
committed
Fix duplicate types
1 parent 48a0108 commit 34372e0

3 files changed

Lines changed: 46 additions & 107 deletions

File tree

lib/data-type.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,34 @@ export type ColumnOption = 'Null' | 'NotNull' | {
372372
}
373373

374374
/**
375-
* ```
376-
* <constraint_characteristics> = [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] [ ENFORCED | NOT ENFORCED ]
377-
* ```
375+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.DeferrableInitial.html
376+
*/
377+
export type DeferrableInitial = 'Immediate' | 'Deferred';
378+
379+
/**
380+
* `<constraint_characteristics> = [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] [ ENFORCED | NOT ENFORCED ]`
381+
*
378382
* Used in UNIQUE and foreign key constraints. The individual settings may occur in any order.
379383
*
380384
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.ConstraintCharacteristics.html
381385
*/
382-
export type ConstraintCharacteristics = any; // TODO: types
386+
export interface ConstraintCharacteristics {
387+
/**
388+
* `[ DEFERRABLE | NOT DEFERRABLE ]`
389+
*/
390+
deferrable?: boolean,
391+
392+
/**
393+
* `[ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]`
394+
*/
395+
initially?: DeferrableInitial,
396+
397+
/**
398+
* `[ ENFORCED | NOT ENFORCED ]`
399+
*/
400+
enforced?: boolean,
401+
}
402+
383403

384404
/**
385405
* ```
@@ -408,11 +428,11 @@ export type GeneratedAs =
408428
| 'ExpStored';
409429

410430
/**
411-
* ```
431+
* ```sql
412432
* [ INCREMENT [ BY ] increment ]
413433
[ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
414434
[ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
415-
```
435+
```
416436
*
417437
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.SequenceOptions.html
418438
*/

lib/function.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ export type WindowType = {
2727
NamedWindow?: Ident;
2828
}
2929

30+
/**
31+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.NamedWindowDefinition.html
32+
*/
33+
export type NamedWindowDefinition = [Ident, NamedWindowExpr];
34+
35+
/**
36+
* An expression used in a named window declaration.
37+
*
38+
* `WINDOW mywindow AS [named_window_expr]`
39+
*
40+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.NamedWindowExpr.html
41+
*/
42+
export type NamedWindowExpr = {
43+
NamedWindow?: Ident;
44+
WindowSpec?: WindowSpec;
45+
};
46+
3047
/**
3148
* A window specification (i.e. `OVER ([window_name] PARTITION BY .. ORDER BY .. etc.)`)
3249
*

lib/statement.ts

Lines changed: 3 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ColumnDef, ColumnOption, CommentDef, DataType, GeneratedAs, NullsDistinctOption, SqlOption } from "./data-type";
1+
import { ColumnDef, ColumnOption, CommentDef, ConstraintCharacteristics, DataType, GeneratedAs, NullsDistinctOption, ReferentialAction, SequenceOptions, SqlOption } from "./data-type";
22
import type { Expr, ExprWithAlias, OneOrManyWithParens } from "./expr";
3-
import { FunctionArg, SQLFunction } from "./function";
3+
import { FunctionArg, NamedWindowDefinition, SQLFunction } from "./function";
44
import type { Ident, ObjectName, ObjectType } from "./ident";
55
import type { AttachedToken, Value, ValueWithSpan } from "./token";
66

@@ -515,23 +515,7 @@ export type AlterColumnOperation =
515515
},
516516
}
517517

518-
/**
519-
* ```sql
520-
* [ INCREMENT [ BY ] increment ]
521-
[ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
522-
[ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
523-
```
524-
*
525-
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.SequenceOptions.html
526-
*/
527-
export type SequenceOptions = {
528-
IncrementBy?: [Expr, boolean],
529-
MinValue?: Expr,
530-
MaxValue?: Expr,
531-
StartWith?: [Expr, boolean],
532-
Cache?: Expr,
533-
Cycle?: boolean,
534-
}
518+
535519

536520
/**
537521
* SQL `CREATE TABLE` statement.
@@ -751,49 +735,6 @@ export type FileFormat =
751735
| 'RCFILE'
752736
| 'JSONFILE';
753737

754-
/**
755-
* `<constraint_characteristics> = [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] [ ENFORCED | NOT ENFORCED ]`
756-
*
757-
* Used in UNIQUE and foreign key constraints. The individual settings may occur in any order.
758-
*
759-
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.ConstraintCharacteristics.html
760-
*/
761-
export interface ConstraintCharacteristics {
762-
/**
763-
* `[ DEFERRABLE | NOT DEFERRABLE ]`
764-
*/
765-
deferrable?: boolean,
766-
767-
/**
768-
* `[ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]`
769-
*/
770-
initially?: DeferrableInitial,
771-
772-
/**
773-
* `[ ENFORCED | NOT ENFORCED ]`
774-
*/
775-
enforced?: boolean,
776-
}
777-
778-
/**
779-
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.DeferrableInitial.html
780-
*/
781-
export type DeferrableInitial = 'Immediate' | 'Deferred';
782-
783-
/**
784-
* `<referential_action> = { RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT }`
785-
*
786-
* Used in foreign key constraints in ON UPDATE and ON DELETE options.
787-
*
788-
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.ReferentialAction.html
789-
*/
790-
export type ReferentialAction =
791-
| 'Restrict'
792-
| 'Cascade'
793-
| 'SetNull'
794-
| 'NoAction'
795-
| 'SetDefault';
796-
797738
/**
798739
* Representation whether a definition can can contains the KEY or INDEX keywords with the same meaning.
799740
*
@@ -1900,45 +1841,6 @@ export type GroupByWithModifier = 'Rollup' | 'Cube' | 'Totals' | {
19001841
GroupingSets: Expr;
19011842
}
19021843

1903-
/**
1904-
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.NamedWindowDefinition.html
1905-
*/
1906-
export type NamedWindowDefinition = [Ident, NamedWindowExpr];
1907-
1908-
/**
1909-
* An expression used in a named window declaration.
1910-
*
1911-
* `WINDOW mywindow AS [named_window_expr]`
1912-
*
1913-
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.NamedWindowExpr.html
1914-
*/
1915-
export type NamedWindowExpr = {
1916-
NamedWindow?: Ident;
1917-
WindowSpec?: WindowSpec;
1918-
};
1919-
1920-
/**
1921-
* A window specification (i.e. `OVER ([window_name] PARTITION BY .. ORDER BY .. etc.)`)
1922-
*
1923-
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.WindowSpec.html
1924-
*/
1925-
export interface WindowSpec {
1926-
window_name?: Ident,
1927-
partition_by: Expr[],
1928-
order_by: OrderByExpr[],
1929-
window_frame?: WindowFrame,
1930-
}
1931-
1932-
/**
1933-
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.WindowFrame.html
1934-
*/
1935-
export interface WindowFrame {
1936-
// TODO: Define proper types
1937-
units: unknown;
1938-
start_bound: unknown;
1939-
end_bound?: unknown;
1940-
}
1941-
19421844
/**
19431845
* What did this select look like?
19441846
*

0 commit comments

Comments
 (0)