Skip to content

Commit 6080f06

Browse files
Copilothotlong
andcommitted
Address code review feedback with comments and optimizations
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 1cddee4 commit 6080f06

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

packages/plugins/plugin-auth/src/objectql-adapter.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,24 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
101101
}
102102

103103
return {
104-
create: async <T extends Record<string, any>>({ model, data }: { model: string; data: T; select?: string[] }): Promise<T> => {
104+
create: async <T extends Record<string, any>>({ model, data, select: _select }: { model: string; data: T; select?: string[] }): Promise<T> => {
105105
const objectName = toObjectName(model);
106106
const objectData = convertDataToObjectQL(data);
107107

108+
// Note: select parameter is currently not supported by ObjectQL's insert operation
109+
// The full record is always returned after insertion
108110
const result = await dataEngine.insert(objectName, objectData);
109111
return convertDataFromObjectQL(result) as T;
110112
},
111113

112-
findOne: async <T>({ model, where, select }: { model: string; where: CleanedWhere[]; select?: string[]; join?: any }): Promise<T | null> => {
114+
findOne: async <T>({ model, where, select, join: _join }: { model: string; where: CleanedWhere[]; select?: string[]; join?: any }): Promise<T | null> => {
113115
const objectName = toObjectName(model);
114116
const filter = convertWhere(where);
115117

118+
// Note: join parameter is not currently supported by ObjectQL's findOne operation
119+
// Joins/populate functionality is planned for future ObjectQL releases
120+
// For now, related data must be fetched separately
121+
116122
const result = await dataEngine.findOne(objectName, {
117123
filter,
118124
select: select?.map(toFieldName),
@@ -121,10 +127,13 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
121127
return result ? convertDataFromObjectQL(result) as T : null;
122128
},
123129

124-
findMany: async <T>({ model, where, limit, offset, sortBy }: { model: string; where?: CleanedWhere[]; limit: number; offset?: number; sortBy?: { field: string; direction: 'asc' | 'desc' }; join?: any }): Promise<T[]> => {
130+
findMany: async <T>({ model, where, limit, offset, sortBy, join: _join }: { model: string; where?: CleanedWhere[]; limit: number; offset?: number; sortBy?: { field: string; direction: 'asc' | 'desc' }; join?: any }): Promise<T[]> => {
125131
const objectName = toObjectName(model);
126132
const filter = where ? convertWhere(where) : {};
127133

134+
// Note: join parameter is not currently supported by ObjectQL's find operation
135+
// Joins/populate functionality is planned for future ObjectQL releases
136+
128137
const sort = sortBy ? [{
129138
field: toFieldName(sortBy.field),
130139
order: sortBy.direction as 'asc' | 'desc',
@@ -171,6 +180,10 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
171180
const filter = convertWhere(where);
172181
const updateData = convertDataToObjectQL(update);
173182

183+
// Note: Sequential updates are used here because ObjectQL's IDataEngine interface
184+
// requires an ID for updates. A future optimization could use a bulk update
185+
// operation if ObjectQL adds support for filter-based updates without IDs.
186+
174187
// Find all matching records
175188
const records = await dataEngine.find(objectName, { filter });
176189

@@ -189,7 +202,9 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
189202
const objectName = toObjectName(model);
190203
const filter = convertWhere(where);
191204

192-
// Find the record first to get its ID
205+
// Note: We need to find the record first to get its ID because ObjectQL's
206+
// delete operation requires an ID. Direct filter-based delete would be more
207+
// efficient if supported by ObjectQL in the future.
193208
const record = await dataEngine.findOne(objectName, { filter });
194209
if (!record) {
195210
return;
@@ -202,6 +217,10 @@ export function createObjectQLAdapter(dataEngine: IDataEngine) {
202217
const objectName = toObjectName(model);
203218
const filter = convertWhere(where);
204219

220+
// Note: Sequential deletes are used here because ObjectQL's delete operation
221+
// requires an ID in the filter. A future optimization could use a single
222+
// delete call with the original filter if ObjectQL supports it.
223+
205224
// Find all matching records
206225
const records = await dataEngine.find(objectName, { filter });
207226

0 commit comments

Comments
 (0)