@strapi/database 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dialects/dialect.d.ts +1 -1
- package/dist/dialects/dialect.d.ts.map +1 -1
- package/dist/dialects/postgresql/index.d.ts.map +1 -1
- package/dist/dialects/sqlite/index.d.ts +2 -1
- package/dist/dialects/sqlite/index.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,8 @@ class Dialect {
|
|
|
23
23
|
this.db = db;
|
|
24
24
|
this.client = client;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
27
|
+
configure(conn) {
|
|
27
28
|
}
|
|
28
29
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
30
|
async initialize(_nativeConnection) {
|
|
@@ -888,8 +889,8 @@ class SqliteDialect extends Dialect {
|
|
|
888
889
|
super(db, "sqlite");
|
|
889
890
|
this.schemaInspector = new SqliteSchemaInspector(db);
|
|
890
891
|
}
|
|
891
|
-
configure() {
|
|
892
|
-
const connection = this.db.config.connection.connection;
|
|
892
|
+
configure(conn) {
|
|
893
|
+
const connection = conn || this.db.config.connection.connection;
|
|
893
894
|
if (typeof connection !== "string") {
|
|
894
895
|
connection.filename = path.resolve(connection.filename);
|
|
895
896
|
}
|
|
@@ -4190,7 +4191,7 @@ const applyWhere = (qb, where) => {
|
|
|
4190
4191
|
});
|
|
4191
4192
|
};
|
|
4192
4193
|
const fieldLowerFn = (qb) => {
|
|
4193
|
-
if (qb.client.
|
|
4194
|
+
if (qb.client.dialect === "postgresql") {
|
|
4194
4195
|
return "LOWER(CAST(?? AS VARCHAR))";
|
|
4195
4196
|
}
|
|
4196
4197
|
return "LOWER(??)";
|
|
@@ -6759,19 +6760,42 @@ class Database {
|
|
|
6759
6760
|
...config.settings ?? {}
|
|
6760
6761
|
}
|
|
6761
6762
|
};
|
|
6763
|
+
this.logger = config.logger ?? console;
|
|
6762
6764
|
this.dialect = getDialect(this);
|
|
6763
|
-
this.
|
|
6765
|
+
let knexConfig = this.config.connection;
|
|
6766
|
+
if (typeof this.config.connection.connection !== "function") {
|
|
6767
|
+
this.dialect.configure();
|
|
6768
|
+
} else {
|
|
6769
|
+
this.logger.warn(
|
|
6770
|
+
"Knex connection functions are currently experimental. Attempting to access the connection object before database initialization will result in errors."
|
|
6771
|
+
);
|
|
6772
|
+
knexConfig = {
|
|
6773
|
+
...this.config.connection,
|
|
6774
|
+
connection: async () => {
|
|
6775
|
+
const conn = await this.config.connection.connection();
|
|
6776
|
+
this.dialect.configure(conn);
|
|
6777
|
+
return conn;
|
|
6778
|
+
}
|
|
6779
|
+
};
|
|
6780
|
+
}
|
|
6764
6781
|
this.metadata = createMetadata([]);
|
|
6765
|
-
this.connection = createConnection(
|
|
6782
|
+
this.connection = createConnection(knexConfig, {
|
|
6766
6783
|
pool: { afterCreate: afterCreate(this) }
|
|
6767
6784
|
});
|
|
6768
6785
|
this.schema = createSchemaProvider(this);
|
|
6769
6786
|
this.migrations = createMigrationsProvider(this);
|
|
6770
6787
|
this.lifecycles = createLifecyclesProvider(this);
|
|
6771
6788
|
this.entityManager = createEntityManager(this);
|
|
6772
|
-
this.logger = config.logger ?? console;
|
|
6773
6789
|
}
|
|
6774
6790
|
async init({ models }) {
|
|
6791
|
+
if (typeof this.config.connection.connection === "function") {
|
|
6792
|
+
this.logger.debug("Forcing Knex to make real connection to db");
|
|
6793
|
+
if (this.config.connection.client === "sqlite") {
|
|
6794
|
+
await this.connection.raw("SELECT 1");
|
|
6795
|
+
} else {
|
|
6796
|
+
await this.connection.client.acquireConnection();
|
|
6797
|
+
}
|
|
6798
|
+
}
|
|
6775
6799
|
this.metadata.loadModels(models);
|
|
6776
6800
|
await validateDatabase(this);
|
|
6777
6801
|
return this;
|