This commit is contained in:
adrinr 2023-02-27 17:25:26 +01:00
parent 30fde61d4d
commit abe06a127a
1 changed files with 9 additions and 9 deletions

View File

@ -13,7 +13,7 @@ import { DataSourceOperation, FieldTypes } from "../constants"
import { GoogleSpreadsheet } from "google-spreadsheet"
import env from "../environment"
import { tenancy, db as dbCore, constants } from "@budibase/backend-core"
const fetch = require("node-fetch")
import fetch from "node-fetch"
interface GoogleSheetsConfig {
spreadsheetId: string
@ -112,7 +112,7 @@ const SCHEMA: Integration = {
class GoogleSheetsIntegration implements DatasourcePlus {
private readonly config: GoogleSheetsConfig
private client: any
private client: GoogleSpreadsheet
public tables: Record<string, Table> = {}
public schemaErrors: Record<string, string> = {}
@ -211,7 +211,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
async buildSchema(datasourceId: string) {
await this.connect()
const sheets = await this.client.sheetsByIndex
const sheets = this.client.sheetsByIndex
const tables: Record<string, Table> = {}
for (let sheet of sheets) {
// must fetch rows to determine schema
@ -294,7 +294,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
async updateTable(table?: any) {
try {
await this.connect()
const sheet = await this.client.sheetsByTitle[table.name]
const sheet = this.client.sheetsByTitle[table.name]
await sheet.loadHeaderRow()
if (table._rename) {
@ -329,7 +329,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
async deleteTable(sheet: any) {
try {
await this.connect()
const sheetToDelete = await this.client.sheetsByTitle[sheet]
const sheetToDelete = this.client.sheetsByTitle[sheet]
return await sheetToDelete.delete()
} catch (err) {
console.error("Error deleting table in google sheets", err)
@ -340,7 +340,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
async create(query: { sheet: string; row: any }) {
try {
await this.connect()
const sheet = await this.client.sheetsByTitle[query.sheet]
const sheet = this.client.sheetsByTitle[query.sheet]
const rowToInsert =
typeof query.row === "string" ? JSON.parse(query.row) : query.row
const row = await sheet.addRow(rowToInsert)
@ -356,7 +356,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
async read(query: { sheet: string }) {
try {
await this.connect()
const sheet = await this.client.sheetsByTitle[query.sheet]
const sheet = this.client.sheetsByTitle[query.sheet]
const rows = await sheet.getRows()
const headerValues = sheet.headerValues
const response = []
@ -375,7 +375,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
async update(query: { sheet: string; rowIndex: number; row: any }) {
try {
await this.connect()
const sheet = await this.client.sheetsByTitle[query.sheet]
const sheet = this.client.sheetsByTitle[query.sheet]
const rows = await sheet.getRows()
const row = rows[query.rowIndex]
if (row) {
@ -399,7 +399,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
async delete(query: { sheet: string; rowIndex: number }) {
await this.connect()
const sheet = await this.client.sheetsByTitle[query.sheet]
const sheet = this.client.sheetsByTitle[query.sheet]
const rows = await sheet.getRows()
const row = rows[query.rowIndex]
if (row) {