Merge branch 'develop' of github.com:Budibase/budibase into develop
This commit is contained in:
commit
3e7bed067b
|
@ -6,12 +6,15 @@ import {
|
||||||
DatabaseOpts,
|
DatabaseOpts,
|
||||||
DatabaseQueryOpts,
|
DatabaseQueryOpts,
|
||||||
DatabasePutOpts,
|
DatabasePutOpts,
|
||||||
|
DatabaseCreateIndexOpts,
|
||||||
|
DatabaseDeleteIndexOpts,
|
||||||
Document,
|
Document,
|
||||||
isDocument,
|
isDocument,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { getCouchInfo } from "./connections"
|
import { getCouchInfo } from "./connections"
|
||||||
import { directCouchCall } from "./utils"
|
import { directCouchCall } from "./utils"
|
||||||
import { getPouchDB } from "./pouchDB"
|
import { getPouchDB } from "./pouchDB"
|
||||||
|
import { WriteStream, ReadStream } from "fs"
|
||||||
|
|
||||||
export class DatabaseImpl implements Database {
|
export class DatabaseImpl implements Database {
|
||||||
public readonly name: string
|
public readonly name: string
|
||||||
|
@ -159,34 +162,32 @@ export class DatabaseImpl implements Database {
|
||||||
return this.updateOutput(() => db.compact())
|
return this.updateOutput(() => db.compact())
|
||||||
}
|
}
|
||||||
|
|
||||||
private doWithPouchDB(func: string) {
|
|
||||||
const dbName = this.name
|
|
||||||
return async (args: any[]) => {
|
|
||||||
const pouch = getPouchDB(dbName)
|
|
||||||
// @ts-ignore
|
|
||||||
return pouch[func](...args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// All below functions are in-frequently called, just utilise PouchDB
|
// All below functions are in-frequently called, just utilise PouchDB
|
||||||
// for them as it implements them better than we can
|
// for them as it implements them better than we can
|
||||||
async dump(...args: any[]) {
|
async dump(stream: WriteStream, opts?: { filter?: any }) {
|
||||||
return this.doWithPouchDB("dump")(args)
|
const pouch = getPouchDB(this.name)
|
||||||
|
// @ts-ignore
|
||||||
|
return pouch.dump(stream, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
async load(...args: any[]) {
|
async load(stream: ReadStream) {
|
||||||
return this.doWithPouchDB("load")(args)
|
const pouch = getPouchDB(this.name)
|
||||||
|
// @ts-ignore
|
||||||
|
return pouch.load(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
async createIndex(...args: any[]) {
|
async createIndex(opts: DatabaseCreateIndexOpts) {
|
||||||
return this.doWithPouchDB("createIndex")(args)
|
const pouch = getPouchDB(this.name)
|
||||||
|
return pouch.createIndex(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteIndex(...args: any[]) {
|
async deleteIndex(opts: DatabaseDeleteIndexOpts) {
|
||||||
return this.doWithPouchDB("createIndex")(args)
|
const pouch = getPouchDB(this.name)
|
||||||
|
return pouch.deleteIndex(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getIndexes(...args: any[]) {
|
async getIndexes() {
|
||||||
return this.doWithPouchDB("createIndex")(args)
|
const pouch = getPouchDB(this.name)
|
||||||
|
return pouch.getIndexes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,21 @@ export type DatabasePutOpts = {
|
||||||
force?: boolean
|
force?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DatabaseCreateIndexOpts = {
|
||||||
|
index: {
|
||||||
|
fields: string[]
|
||||||
|
name?: string | undefined
|
||||||
|
ddoc?: string | undefined
|
||||||
|
type?: string | undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DatabaseDeleteIndexOpts = {
|
||||||
|
name: string
|
||||||
|
ddoc: string
|
||||||
|
type?: string | undefined
|
||||||
|
}
|
||||||
|
|
||||||
export type DatabaseQueryOpts = {
|
export type DatabaseQueryOpts = {
|
||||||
include_docs?: boolean
|
include_docs?: boolean
|
||||||
startkey?: string
|
startkey?: string
|
||||||
|
|
Loading…
Reference in New Issue