mirror of
https://github.com/docmost/docmost.git
synced 2026-08-29 18:14:58 +08:00
refactor(base): rename baseId to pageId in BaseRowRepo
This commit is contained in:
@@ -32,7 +32,7 @@ type WorkspaceOpts = { workspaceId: string } & RepoOpts;
|
|||||||
// this constant.
|
// this constant.
|
||||||
const BASE_ROW_COLUMNS = [
|
const BASE_ROW_COLUMNS = [
|
||||||
'id',
|
'id',
|
||||||
'baseId',
|
'pageId',
|
||||||
'cells',
|
'cells',
|
||||||
'position',
|
'position',
|
||||||
'creatorId',
|
'creatorId',
|
||||||
@@ -77,7 +77,7 @@ export class BaseRowRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async list(opts: {
|
async list(opts: {
|
||||||
baseId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
filter?: FilterNode;
|
filter?: FilterNode;
|
||||||
sorts?: SortSpec[];
|
sorts?: SortSpec[];
|
||||||
@@ -91,7 +91,7 @@ export class BaseRowRepo {
|
|||||||
const base = db
|
const base = db
|
||||||
.selectFrom('baseRows')
|
.selectFrom('baseRows')
|
||||||
.select(BASE_ROW_COLUMNS)
|
.select(BASE_ROW_COLUMNS)
|
||||||
.where('baseId', '=', opts.baseId)
|
.where('pageId', '=', opts.pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null);
|
.where('deletedAt', 'is', null);
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ export class BaseRowRepo {
|
|||||||
* approximate; planner accuracy depends on fresh stats (ANALYZE).
|
* approximate; planner accuracy depends on fresh stats (ANALYZE).
|
||||||
*/
|
*/
|
||||||
async countEstimate(opts: {
|
async countEstimate(opts: {
|
||||||
baseId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
filter?: FilterNode;
|
filter?: FilterNode;
|
||||||
search?: SearchSpec;
|
search?: SearchSpec;
|
||||||
@@ -149,7 +149,7 @@ export class BaseRowRepo {
|
|||||||
let qb = db
|
let qb = db
|
||||||
.selectFrom('baseRows')
|
.selectFrom('baseRows')
|
||||||
.select(sql<number>`1`.as('x'))
|
.select(sql<number>`1`.as('x'))
|
||||||
.where('baseId', '=', opts.baseId)
|
.where('pageId', '=', opts.pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null);
|
.where('deletedAt', 'is', null);
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ export class BaseRowRepo {
|
|||||||
* matches more than `cap` — callers render "cap+" in the UI instead.
|
* matches more than `cap` — callers render "cap+" in the UI instead.
|
||||||
*/
|
*/
|
||||||
async countExact(opts: {
|
async countExact(opts: {
|
||||||
baseId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
filter?: FilterNode;
|
filter?: FilterNode;
|
||||||
search?: SearchSpec;
|
search?: SearchSpec;
|
||||||
@@ -206,7 +206,7 @@ export class BaseRowRepo {
|
|||||||
let inner = db
|
let inner = db
|
||||||
.selectFrom('baseRows')
|
.selectFrom('baseRows')
|
||||||
.select(sql<number>`1`.as('x'))
|
.select(sql<number>`1`.as('x'))
|
||||||
.where('baseId', '=', opts.baseId)
|
.where('pageId', '=', opts.pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null);
|
.where('deletedAt', 'is', null);
|
||||||
|
|
||||||
@@ -234,14 +234,14 @@ export class BaseRowRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getLastPosition(
|
async getLastPosition(
|
||||||
baseId: string,
|
pageId: string,
|
||||||
opts: WorkspaceOpts,
|
opts: WorkspaceOpts,
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
const db = dbOrTx(this.db, opts.trx);
|
const db = dbOrTx(this.db, opts.trx);
|
||||||
const result = await db
|
const result = await db
|
||||||
.selectFrom('baseRows')
|
.selectFrom('baseRows')
|
||||||
.select('position')
|
.select('position')
|
||||||
.where('baseId', '=', baseId)
|
.where('pageId', '=', pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.orderBy(sql`position COLLATE "C"`, 'desc')
|
.orderBy(sql`position COLLATE "C"`, 'desc')
|
||||||
@@ -272,7 +272,7 @@ export class BaseRowRepo {
|
|||||||
rowId: string,
|
rowId: string,
|
||||||
patch: Record<string, unknown>,
|
patch: Record<string, unknown>,
|
||||||
opts: {
|
opts: {
|
||||||
baseId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
actorId?: string;
|
actorId?: string;
|
||||||
trx?: KyselyTransaction;
|
trx?: KyselyTransaction;
|
||||||
@@ -291,7 +291,7 @@ export class BaseRowRepo {
|
|||||||
lastUpdatedById: opts.actorId ?? null,
|
lastUpdatedById: opts.actorId ?? null,
|
||||||
})
|
})
|
||||||
.where('id', '=', rowId)
|
.where('id', '=', rowId)
|
||||||
.where('baseId', '=', opts.baseId)
|
.where('pageId', '=', opts.pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.returning(BASE_ROW_COLUMNS)
|
.returning(BASE_ROW_COLUMNS)
|
||||||
@@ -302,7 +302,7 @@ export class BaseRowRepo {
|
|||||||
rowId: string,
|
rowId: string,
|
||||||
position: string,
|
position: string,
|
||||||
opts: {
|
opts: {
|
||||||
baseId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
trx?: KyselyTransaction;
|
trx?: KyselyTransaction;
|
||||||
},
|
},
|
||||||
@@ -312,7 +312,7 @@ export class BaseRowRepo {
|
|||||||
.updateTable('baseRows')
|
.updateTable('baseRows')
|
||||||
.set({ position, updatedAt: new Date() })
|
.set({ position, updatedAt: new Date() })
|
||||||
.where('id', '=', rowId)
|
.where('id', '=', rowId)
|
||||||
.where('baseId', '=', opts.baseId)
|
.where('pageId', '=', opts.pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.execute();
|
.execute();
|
||||||
@@ -321,7 +321,7 @@ export class BaseRowRepo {
|
|||||||
async softDelete(
|
async softDelete(
|
||||||
rowId: string,
|
rowId: string,
|
||||||
opts: {
|
opts: {
|
||||||
baseId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
trx?: KyselyTransaction;
|
trx?: KyselyTransaction;
|
||||||
},
|
},
|
||||||
@@ -331,7 +331,7 @@ export class BaseRowRepo {
|
|||||||
.updateTable('baseRows')
|
.updateTable('baseRows')
|
||||||
.set({ deletedAt: new Date() })
|
.set({ deletedAt: new Date() })
|
||||||
.where('id', '=', rowId)
|
.where('id', '=', rowId)
|
||||||
.where('baseId', '=', opts.baseId)
|
.where('pageId', '=', opts.pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.execute();
|
.execute();
|
||||||
@@ -340,7 +340,7 @@ export class BaseRowRepo {
|
|||||||
async softDeleteMany(
|
async softDeleteMany(
|
||||||
rowIds: string[],
|
rowIds: string[],
|
||||||
opts: {
|
opts: {
|
||||||
baseId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
trx?: KyselyTransaction;
|
trx?: KyselyTransaction;
|
||||||
},
|
},
|
||||||
@@ -351,14 +351,14 @@ export class BaseRowRepo {
|
|||||||
.updateTable('baseRows')
|
.updateTable('baseRows')
|
||||||
.set({ deletedAt: new Date() })
|
.set({ deletedAt: new Date() })
|
||||||
.where('id', 'in', rowIds)
|
.where('id', 'in', rowIds)
|
||||||
.where('baseId', '=', opts.baseId)
|
.where('pageId', '=', opts.pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeCellKey(
|
async removeCellKey(
|
||||||
baseId: string,
|
pageId: string,
|
||||||
propertyId: string,
|
propertyId: string,
|
||||||
opts: WorkspaceOpts,
|
opts: WorkspaceOpts,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@@ -369,7 +369,7 @@ export class BaseRowRepo {
|
|||||||
cells: sql`cells - ${propertyId}::text`,
|
cells: sql`cells - ${propertyId}::text`,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where('baseId', '=', baseId)
|
.where('pageId', '=', pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
@@ -384,7 +384,7 @@ export class BaseRowRepo {
|
|||||||
* we don't drag 100k empty rows through Node just to rewrite a dozen.
|
* we don't drag 100k empty rows through Node just to rewrite a dozen.
|
||||||
*/
|
*/
|
||||||
async *streamByBaseId(
|
async *streamByBaseId(
|
||||||
baseId: string,
|
pageId: string,
|
||||||
opts: {
|
opts: {
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
chunkSize?: number;
|
chunkSize?: number;
|
||||||
@@ -401,7 +401,7 @@ export class BaseRowRepo {
|
|||||||
let qb = db
|
let qb = db
|
||||||
.selectFrom('baseRows')
|
.selectFrom('baseRows')
|
||||||
.select(BASE_ROW_COLUMNS)
|
.select(BASE_ROW_COLUMNS)
|
||||||
.where('baseId', '=', baseId)
|
.where('pageId', '=', pageId)
|
||||||
.where('workspaceId', '=', opts.workspaceId)
|
.where('workspaceId', '=', opts.workspaceId)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.orderBy(sql`position COLLATE "C"`, 'asc')
|
.orderBy(sql`position COLLATE "C"`, 'asc')
|
||||||
@@ -443,7 +443,7 @@ export class BaseRowRepo {
|
|||||||
async batchUpdateCells(
|
async batchUpdateCells(
|
||||||
updates: Array<{ id: string; patch: Record<string, unknown> }>,
|
updates: Array<{ id: string; patch: Record<string, unknown> }>,
|
||||||
opts: {
|
opts: {
|
||||||
baseId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
actorId?: string;
|
actorId?: string;
|
||||||
trx?: KyselyTransaction;
|
trx?: KyselyTransaction;
|
||||||
@@ -462,7 +462,7 @@ export class BaseRowRepo {
|
|||||||
last_updated_by_id = coalesce(${opts.actorId ?? null}, r.last_updated_by_id)
|
last_updated_by_id = coalesce(${opts.actorId ?? null}, r.last_updated_by_id)
|
||||||
FROM unnest(${ids}::uuid[], ${patches}::text[]) AS u(row_id, patch)
|
FROM unnest(${ids}::uuid[], ${patches}::text[]) AS u(row_id, patch)
|
||||||
WHERE r.id = u.row_id
|
WHERE r.id = u.row_id
|
||||||
AND r.base_id = ${opts.baseId}
|
AND r.page_id = ${opts.pageId}
|
||||||
AND r.workspace_id = ${opts.workspaceId}
|
AND r.workspace_id = ${opts.workspaceId}
|
||||||
AND r.deleted_at IS NULL
|
AND r.deleted_at IS NULL
|
||||||
`.execute(db);
|
`.execute(db);
|
||||||
|
|||||||
Reference in New Issue
Block a user