UNPKG

5.31 kBTypeScriptView Raw
1import { Query } from "../driver/Query";
2import { SqlInMemory } from "../driver/SqlInMemory";
3import { View } from "../schema-builder/view/View";
4import { Connection } from "../connection/Connection";
5import { Table } from "../schema-builder/table/Table";
6import { EntityManager } from "../entity-manager/EntityManager";
7import { TableColumn } from "../schema-builder/table/TableColumn";
8import { Broadcaster } from "../subscriber/Broadcaster";
9export declare abstract class BaseQueryRunner {
10 /**
11 * Connection used by this query runner.
12 */
13 connection: Connection;
14 /**
15 * Entity manager working only with current query runner.
16 */
17 manager: EntityManager;
18 /**
19 * Indicates if connection for this query runner is released.
20 * Once its released, query runner cannot run queries anymore.
21 */
22 isReleased: boolean;
23 /**
24 * Indicates if transaction is in progress.
25 */
26 isTransactionActive: boolean;
27 /**
28 * Stores temporarily user data.
29 * Useful for sharing data with subscribers.
30 */
31 data: {};
32 /**
33 * All synchronized tables in the database.
34 */
35 loadedTables: Table[];
36 /**
37 * All synchronized views in the database.
38 */
39 loadedViews: View[];
40 /**
41 * Broadcaster used on this query runner to broadcast entity events.
42 */
43 broadcaster: Broadcaster;
44 /**
45 * Real database connection from a connection pool used to perform queries.
46 */
47 protected databaseConnection: any;
48 /**
49 * Indicates if special query runner mode in which sql queries won't be executed is enabled.
50 */
51 protected sqlMemoryMode: boolean;
52 /**
53 * Sql-s stored if "sql in memory" mode is enabled.
54 */
55 protected sqlInMemory: SqlInMemory;
56 /**
57 * Mode in which query runner executes.
58 * Used for replication.
59 * If replication is not setup its value is ignored.
60 */
61 protected mode: "master" | "slave";
62 /**
63 * Executes a given SQL query.
64 */
65 abstract query(query: string, parameters?: any[]): Promise<any>;
66 protected abstract loadTables(tablePaths: string[]): Promise<Table[]>;
67 protected abstract loadViews(tablePaths: string[]): Promise<View[]>;
68 /**
69 * Loads given table's data from the database.
70 */
71 getTable(tablePath: string): Promise<Table | undefined>;
72 /**
73 * Loads all tables (with given names) from the database.
74 */
75 getTables(tableNames: string[]): Promise<Table[]>;
76 /**
77 * Loads given view's data from the database.
78 */
79 getView(viewPath: string): Promise<View | undefined>;
80 /**
81 * Loads given view's data from the database.
82 */
83 getViews(viewPaths: string[]): Promise<View[]>;
84 /**
85 * Enables special query runner mode in which sql queries won't be executed,
86 * instead they will be memorized into a special variable inside query runner.
87 * You can get memorized sql using getMemorySql() method.
88 */
89 enableSqlMemory(): void;
90 /**
91 * Disables special query runner mode in which sql queries won't be executed
92 * started by calling enableSqlMemory() method.
93 *
94 * Previously memorized sql will be flushed.
95 */
96 disableSqlMemory(): void;
97 /**
98 * Flushes all memorized sqls.
99 */
100 clearSqlMemory(): void;
101 /**
102 * Gets sql stored in the memory. Parameters in the sql are already replaced.
103 */
104 getMemorySql(): SqlInMemory;
105 /**
106 * Executes up sql queries.
107 */
108 executeMemoryUpSql(): Promise<void>;
109 /**
110 * Executes down sql queries.
111 */
112 executeMemoryDownSql(): Promise<void>;
113 /**
114 * Gets view from previously loaded views, otherwise loads it from database.
115 */
116 protected getCachedView(viewName: string): Promise<View>;
117 /**
118 * Gets table from previously loaded tables, otherwise loads it from database.
119 */
120 protected getCachedTable(tableName: string): Promise<Table>;
121 /**
122 * Replaces loaded table with given changed table.
123 */
124 protected replaceCachedTable(table: Table, changedTable: Table): void;
125 protected getTypeormMetadataTableName(): string;
126 /**
127 * Checks if at least one of column properties was changed.
128 * Does not checks column type, length and autoincrement, because these properties changes separately.
129 */
130 protected isColumnChanged(oldColumn: TableColumn, newColumn: TableColumn, checkDefault?: boolean, checkComment?: boolean): boolean;
131 /**
132 * Checks if column length is by default.
133 */
134 protected isDefaultColumnLength(table: Table, column: TableColumn, length: string): boolean;
135 /**
136 * Checks if column display width is by default. Used only for MySQL.
137 */
138 protected isDefaultColumnWidth(table: Table, column: TableColumn, width: number): boolean;
139 /**
140 * Checks if column precision is by default.
141 */
142 protected isDefaultColumnPrecision(table: Table, column: TableColumn, precision: number): boolean;
143 /**
144 * Checks if column scale is by default.
145 */
146 protected isDefaultColumnScale(table: Table, column: TableColumn, scale: number): boolean;
147 /**
148 * Executes sql used special for schema build.
149 */
150 protected executeQueries(upQueries: Query | Query[], downQueries: Query | Query[]): Promise<void>;
151}