diff --git a/packages/server/src/db/utils.ts b/packages/server/src/db/utils.ts index 1712563085..a487c562b6 100644 --- a/packages/server/src/db/utils.ts +++ b/packages/server/src/db/utils.ts @@ -1,5 +1,5 @@ import newid from "./newid" -import { db as dbCore } from "@budibase/backend-core" +import { context, db as dbCore } from "@budibase/backend-core" import { DocumentType, FieldSchema, @@ -7,6 +7,7 @@ import { VirtualDocumentType, INTERNAL_TABLE_SOURCE_ID, DatabaseQueryOpts, + LinkDocument, } from "@budibase/types" import { FieldTypes } from "../constants" @@ -127,10 +128,24 @@ export function generateLinkID( /** * Gets parameters for retrieving link docs, this is a utility function for the getDocParams function. */ -export function getLinkParams(otherProps: any = {}) { +function getLinkParams(otherProps: Partial = {}) { return getDocParams(DocumentType.LINK, null, otherProps) } +/** + * Gets all the link docs document from the current app db. + */ +export async function allLinkDocs() { + const db = context.getAppDB() + + const response = await db.allDocs( + getLinkParams({ + include_docs: true, + }) + ) + return response.rows.map(row => row.doc!) +} + /** * Generates a new layout ID. * @returns The new layout ID which the layout doc can be stored under.