1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Make DB name non-optional.

This commit is contained in:
Sam Rose 2023-11-08 14:37:19 +00:00
parent 7672993eae
commit 47292b8ab4
No known key found for this signature in database
5 changed files with 15 additions and 19 deletions

View file

@ -276,6 +276,9 @@ export function getAuditLogsDB(): Database {
*/ */
export function getAppDB(opts?: any): Database { export function getAppDB(opts?: any): Database {
const appId = getAppId() const appId = getAppId()
if (!appId) {
throw new Error("Unable to retrieve app DB - no app ID.")
}
return getDB(appId, opts) return getDB(appId, opts)
} }

View file

@ -48,10 +48,7 @@ export class DatabaseImpl implements Database {
private readonly couchInfo = getCouchInfo() private readonly couchInfo = getCouchInfo()
constructor(dbName?: string, opts?: DatabaseOpts, connection?: string) { constructor(dbName: string, opts?: DatabaseOpts, connection?: string) {
if (dbName == null) {
throw new Error("Database name cannot be undefined.")
}
this.name = dbName this.name = dbName
this.pouchOpts = opts || {} this.pouchOpts = opts || {}
if (connection) { if (connection) {

View file

@ -1,10 +1,7 @@
import env from "../environment"
import { directCouchQuery, DatabaseImpl } from "./couch" import { directCouchQuery, DatabaseImpl } from "./couch"
import { CouchFindOptions, Database } from "@budibase/types" import { CouchFindOptions, Database } from "@budibase/types"
const dbList = new Set() export function getDB(dbName: string, opts?: any): Database {
export function getDB(dbName?: string, opts?: any): Database {
return new DatabaseImpl(dbName, opts) return new DatabaseImpl(dbName, opts)
} }
@ -22,13 +19,6 @@ export async function doWithDB<T>(
return await cb(db) return await cb(db)
} }
export function allDbs() {
if (!env.isTest()) {
throw new Error("Cannot be used outside test environment.")
}
return [...dbList]
}
export async function directCouchAllDbs(queryString?: string) { export async function directCouchAllDbs(queryString?: string) {
let couchPath = "/_all_dbs" let couchPath = "/_all_dbs"
if (queryString) { if (queryString) {

View file

@ -337,7 +337,7 @@ export async function destroy(ctx: UserCtx) {
if (datasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE) { if (datasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE) {
await destroyInternalTablesBySourceId(datasourceId) await destroyInternalTablesBySourceId(datasourceId)
} else { } else {
const queries = await db.allDocs(getQueryParams(datasourceId, null)) const queries = await db.allDocs(getQueryParams(datasourceId))
await db.bulkDocs( await db.bulkDocs(
queries.rows.map((row: any) => ({ queries.rows.map((row: any) => ({
_id: row.id, _id: row.id,

View file

@ -6,6 +6,7 @@ import {
RelationshipFieldMetadata, RelationshipFieldMetadata,
VirtualDocumentType, VirtualDocumentType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
DatabaseQueryOpts,
} from "@budibase/types" } from "@budibase/types"
import { FieldTypes } from "../constants" import { FieldTypes } from "../constants"
export { DocumentType, VirtualDocumentType } from "@budibase/types" export { DocumentType, VirtualDocumentType } from "@budibase/types"
@ -229,7 +230,10 @@ export function getAutomationMetadataParams(otherProps: any = {}) {
/** /**
* Gets parameters for retrieving a query, this is a utility function for the getDocParams function. * Gets parameters for retrieving a query, this is a utility function for the getDocParams function.
*/ */
export function getQueryParams(datasourceId?: Optional, otherProps: any = {}) { export function getQueryParams(
datasourceId?: Optional,
otherProps: Partial<DatabaseQueryOpts> = {}
) {
if (datasourceId == null) { if (datasourceId == null) {
return getDocParams(DocumentType.QUERY, null, otherProps) return getDocParams(DocumentType.QUERY, null, otherProps)
} }
@ -256,7 +260,7 @@ export function generateMetadataID(type: string, entityId: string) {
export function getMetadataParams( export function getMetadataParams(
type: string, type: string,
entityId?: Optional, entityId?: Optional,
otherProps: any = {} otherProps: Partial<DatabaseQueryOpts> = {}
) { ) {
let docId = `${type}${SEPARATOR}` let docId = `${type}${SEPARATOR}`
if (entityId != null) { if (entityId != null) {
@ -269,7 +273,9 @@ export function generateMemoryViewID(viewName: string) {
return `${DocumentType.MEM_VIEW}${SEPARATOR}${viewName}` return `${DocumentType.MEM_VIEW}${SEPARATOR}${viewName}`
} }
export function getMemoryViewParams(otherProps: any = {}) { export function getMemoryViewParams(
otherProps: Partial<DatabaseQueryOpts> = {}
) {
return getDocParams(DocumentType.MEM_VIEW, null, otherProps) return getDocParams(DocumentType.MEM_VIEW, null, otherProps)
} }