Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve circular dependency when using vite #10273

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/data-source/DataSource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Driver } from "../driver/Driver"
import { registerQueryBuilders } from "../query-builder"
import { Repository } from "../repository/Repository"
import { EntitySubscriberInterface } from "../subscriber/EntitySubscriberInterface"
import { EntityTarget } from "../common/EntityTarget"
Expand Down Expand Up @@ -40,7 +41,6 @@ import { RelationIdLoader } from "../query-builder/RelationIdLoader"
import { DriverUtils } from "../driver/DriverUtils"
import { InstanceChecker } from "../util/InstanceChecker"
import { ObjectLiteral } from "../common/ObjectLiteral"
import { registerQueryBuilders } from "../query-builder"

registerQueryBuilders()

Expand Down Expand Up @@ -139,6 +139,7 @@ export class DataSource {
// -------------------------------------------------------------------------

constructor(options: DataSourceOptions) {
registerQueryBuilders()
this.name = options.name || "default"
this.options = options
this.logger = new LoggerFactory().create(
Expand Down
4 changes: 2 additions & 2 deletions src/driver/capacitor/CapacitorDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ export class CapacitorDriver extends AbstractSqliteDriver {

// we need to enable foreign keys in sqlite to make sure all foreign key related features
// working properly. this also makes onDelete to work with sqlite.
await connection.query(`PRAGMA foreign_keys = ON`)
await connection.run(`PRAGMA foreign_keys = ON`)

if (
this.options.journalMode &&
["DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF"].indexOf(
this.options.journalMode,
) !== -1
) {
await connection.query(
await connection.run(
`PRAGMA journal_mode = ${this.options.journalMode}`,
)
}
Expand Down
9 changes: 7 additions & 2 deletions src/driver/capacitor/CapacitorQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export class CapacitorQueryRunner extends AbstractSqliteQueryRunner {

this.driver.connection.logger.logQuery(query, parameters, this)

const command = query.substr(0, query.indexOf(" "))
const command = query.substring(
0,
query.indexOf(" ") !== -1 ? query.indexOf(" ") : undefined,
)

try {
let raw: any
Expand All @@ -78,7 +81,9 @@ export class CapacitorQueryRunner extends AbstractSqliteQueryRunner {
].indexOf(command) !== -1
) {
raw = await databaseConnection.execute(query, false)
} else if (["INSERT", "UPDATE", "DELETE"].indexOf(command) !== -1) {
} else if (
["INSERT", "UPDATE", "DELETE", "PRAGMA"].indexOf(command) !== -1
) {
raw = await databaseConnection.run(query, parameters, false)
} else {
raw = await databaseConnection.query(query, parameters || [])
Expand Down
2 changes: 2 additions & 0 deletions src/platform/BrowserPlatformTools.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Buffer } from "buffer";
* For node.js environment this class is not getting packaged.
* Don't use methods of this class in the code, use PlatformTools methods instead.
*/
import { Buffer } from "buffer";

export class PlatformTools {

/**
Expand Down
8 changes: 4 additions & 4 deletions src/query-builder/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export abstract class QueryBuilder<Entity extends ObjectLiteral> {
}
}

static registerQueryBuilderClass(name: string, factory: any) {
QueryBuilder.queryBuilderRegistry[name] = factory
}

// -------------------------------------------------------------------------
// Abstract Methods
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -1672,8 +1676,4 @@ export abstract class QueryBuilder<Entity extends ObjectLiteral> {
protected hasCommonTableExpressions(): boolean {
return this.expressionMap.commonTableExpressions.length > 0
}

static registerQueryBuilderClass(name: string, factory: any) {
QueryBuilder.queryBuilderRegistry[name] = factory
}
}