mirror of
https://github.com/directus/directus.git
synced 2026-01-25 19:58:23 -05:00
Use cross-platform insert
This commit is contained in:
@@ -82,12 +82,17 @@ export default class ItemsService implements AbstractService {
|
||||
// string / uuid primary
|
||||
let primaryKey = payloadWithoutAlias[primaryKeyField];
|
||||
|
||||
const result = await trx
|
||||
.insert(payloadWithoutAlias, primaryKeyField)
|
||||
.into(this.collection);
|
||||
await trx.insert(payloadWithoutAlias).into(this.collection);
|
||||
|
||||
// Auto-incremented id
|
||||
if (!primaryKey) primaryKey = result[0];
|
||||
if (!primaryKey) {
|
||||
const result = await trx
|
||||
.select(primaryKeyField)
|
||||
.from(this.collection)
|
||||
.orderBy(primaryKeyField, 'desc')
|
||||
.first();
|
||||
primaryKey = result[primaryKeyField];
|
||||
}
|
||||
|
||||
primaryKeys.push(primaryKey);
|
||||
}
|
||||
@@ -112,8 +117,15 @@ export default class ItemsService implements AbstractService {
|
||||
const activityPrimaryKeys: PrimaryKey[] = [];
|
||||
|
||||
for (const activityRecord of activityRecords) {
|
||||
const result = await trx.insert(activityRecord, 'id').into('directus_activity');
|
||||
activityPrimaryKeys.push(result[0]);
|
||||
await trx.insert(activityRecord).into('directus_activity');
|
||||
let primaryKey;
|
||||
const result = await trx
|
||||
.select('id')
|
||||
.from('directus_activity')
|
||||
.orderBy(primaryKeyField, 'desc')
|
||||
.first();
|
||||
primaryKey = result[primaryKeyField];
|
||||
activityPrimaryKeys.push(primaryKey);
|
||||
}
|
||||
|
||||
const revisionRecords = activityPrimaryKeys.map((key, index) => ({
|
||||
@@ -248,10 +260,15 @@ export default class ItemsService implements AbstractService {
|
||||
const activityPrimaryKeys: PrimaryKey[] = [];
|
||||
|
||||
for (const activityRecord of activityRecords) {
|
||||
await trx.insert(activityRecord).into('directus_activity');
|
||||
let primaryKey;
|
||||
const result = await trx
|
||||
.insert(activityRecord, 'id')
|
||||
.into('directus_activity');
|
||||
activityPrimaryKeys.push(result[0]);
|
||||
.select('id')
|
||||
.from('directus_activity')
|
||||
.orderBy(primaryKeyField, 'desc')
|
||||
.first();
|
||||
primaryKey = result[primaryKeyField];
|
||||
activityPrimaryKeys.push(primaryKey);
|
||||
}
|
||||
|
||||
const itemsService = new ItemsService(this.collection, { knex: trx });
|
||||
|
||||
Reference in New Issue
Block a user