-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
968 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { freeze } from '../util/object-utils.js' | ||
import { OperationNode } from './operation-node.js' | ||
import { TableNode } from './table-node.js' | ||
import { IdentifierNode } from './identifier-node.js' | ||
import { QueryNode } from './query-node.js' | ||
import { TriggerEventNode } from './trigger-event-node.js' | ||
import { TriggerOrderNode } from './trigger-order-node.js' | ||
import { FunctionNode } from './function-node.js' | ||
|
||
export type TriggerTime = 'after' | 'before' | 'instead of' | ||
|
||
export type CreateTriggerNodeParams = Omit< | ||
CreateTriggerNode, | ||
'kind' | 'name' | 'queries' | ||
> | ||
|
||
export interface CreateTriggerNode extends OperationNode { | ||
readonly kind: 'CreateTriggerNode' | ||
readonly name: IdentifierNode | ||
readonly queries?: ReadonlyArray<QueryNode> | ||
readonly function?: FunctionNode | ||
readonly time?: TriggerTime | ||
readonly events?: ReadonlyArray<TriggerEventNode> | ||
readonly table?: TableNode | ||
readonly orReplace?: boolean | ||
readonly ifNotExists?: boolean | ||
readonly when?: OperationNode | ||
readonly temporary?: boolean | ||
readonly forEach?: 'row' | 'statement' | ||
readonly order?: TriggerOrderNode | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const CreateTriggerNode = freeze({ | ||
is(node: OperationNode): node is CreateTriggerNode { | ||
return node.kind === 'CreateTriggerNode' | ||
}, | ||
|
||
create(name: IdentifierNode): CreateTriggerNode { | ||
return freeze({ | ||
kind: 'CreateTriggerNode', | ||
name, | ||
}) | ||
}, | ||
|
||
cloneWithQuery( | ||
createTrigger: CreateTriggerNode, | ||
query: QueryNode | ||
): CreateTriggerNode { | ||
return freeze({ | ||
...createTrigger, | ||
queries: freeze([...(createTrigger.queries || []), query]), | ||
}) | ||
}, | ||
|
||
cloneWithEvent( | ||
createTrigger: CreateTriggerNode, | ||
event: TriggerEventNode | ||
): CreateTriggerNode { | ||
return freeze({ | ||
...createTrigger, | ||
events: freeze([...(createTrigger.events || []), event]), | ||
}) | ||
}, | ||
|
||
cloneWith( | ||
createTrigger: CreateTriggerNode, | ||
params: CreateTriggerNodeParams | ||
): CreateTriggerNode { | ||
return freeze({ | ||
...createTrigger, | ||
...params, | ||
}) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { freeze } from '../util/object-utils.js' | ||
import { OperationNode } from './operation-node.js' | ||
import { SchemableIdentifierNode } from './schemable-identifier-node.js' | ||
|
||
export type DropTriggerNodeParams = Omit< | ||
Partial<DropTriggerNode>, | ||
'kind' | 'name' | ||
> | ||
export interface DropTriggerNode extends OperationNode { | ||
readonly kind: 'DropTriggerNode' | ||
readonly name: SchemableIdentifierNode | ||
readonly ifExists?: boolean | ||
readonly cascade?: boolean | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const DropTriggerNode = freeze({ | ||
is(node: OperationNode): node is DropTriggerNode { | ||
return node.kind === 'DropTriggerNode' | ||
}, | ||
|
||
create(name: SchemableIdentifierNode): DropTriggerNode { | ||
return freeze({ | ||
kind: 'DropTriggerNode', | ||
name, | ||
}) | ||
}, | ||
|
||
cloneWith( | ||
dropTrigger: DropTriggerNode, | ||
params: DropTriggerNodeParams | ||
): DropTriggerNode { | ||
return freeze({ | ||
...dropTrigger, | ||
...params, | ||
}) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { freeze } from '../util/object-utils.js' | ||
import { OperationNode } from './operation-node.js' | ||
|
||
export type TriggerEvent = 'delete' | 'update' | 'insert' | 'truncate' | ||
|
||
export type TriggerEventNodeParams = Omit<TriggerEventNode, 'kind'> | ||
|
||
export interface TriggerEventNode extends OperationNode { | ||
readonly kind: 'TriggerEventNode' | ||
readonly event: TriggerEvent | ||
readonly columns?: ReadonlyArray<OperationNode> | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const TriggerEventNode = freeze({ | ||
is(node: OperationNode): node is TriggerEventNode { | ||
return node.kind === 'TriggerEventNode' | ||
}, | ||
|
||
create( | ||
event: TriggerEvent, | ||
columns?: ReadonlyArray<OperationNode> | ||
): TriggerEventNode { | ||
return freeze({ | ||
kind: 'TriggerEventNode', | ||
event, | ||
columns, | ||
}) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { freeze } from '../util/object-utils.js' | ||
import { IdentifierNode } from './identifier-node.js' | ||
import { OperationNode } from './operation-node.js' | ||
|
||
export type TriggerOrder = 'follows' | 'precedes' | ||
|
||
export type TriggerOrderNodeParams = Omit<TriggerOrderNode, 'kind'> | ||
|
||
export interface TriggerOrderNode extends OperationNode { | ||
readonly kind: 'TriggerOrderNode' | ||
readonly order: TriggerOrder | ||
readonly otherTriggerName: IdentifierNode | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const TriggerOrderNode = freeze({ | ||
is(node: OperationNode): node is TriggerOrderNode { | ||
return node.kind === 'TriggerOrderNode' | ||
}, | ||
|
||
create( | ||
order: TriggerOrder, | ||
otherTriggerName: IdentifierNode | ||
): TriggerOrderNode { | ||
return freeze({ | ||
kind: 'TriggerOrderNode', | ||
order, | ||
otherTriggerName, | ||
}) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.