merging with relationship backend work

This commit is contained in:
Martin McKeaveney 2021-06-29 12:05:26 +01:00
commit 60425d9810
19 changed files with 1472 additions and 44 deletions

View File

@ -9,7 +9,8 @@
"url": "https://github.com/Budibase/budibase.git" "url": "https://github.com/Budibase/budibase.git"
}, },
"scripts": { "scripts": {
"build": "rm -rf dist/ && tsc && mv dist/src/* dist/ && rmdir dist/src/", "build": "rm -rf dist/ && tsc && mv dist/src/* dist/ && rmdir dist/src/ && yarn postbuild",
"postbuild": "copyfiles -u 1 src/**/*.svelte dist/ && copyfiles -u 1 src/**/*.hbs dist/ && copyfiles -u 1 src/**/*.json dist/",
"test": "jest --coverage --maxWorkers=2", "test": "jest --coverage --maxWorkers=2",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"build:docker": "docker build . -t app-service", "build:docker": "docker build . -t app-service",
@ -122,6 +123,7 @@
"@types/node": "^15.12.4", "@types/node": "^15.12.4",
"@typescript-eslint/parser": "^4.28.0", "@typescript-eslint/parser": "^4.28.0",
"babel-jest": "^27.0.2", "babel-jest": "^27.0.2",
"copyfiles": "^2.4.1",
"docker-compose": "^0.23.6", "docker-compose": "^0.23.6",
"eslint": "^6.8.0", "eslint": "^6.8.0",
"express": "^4.17.1", "express": "^4.17.1",

View File

@ -15,3 +15,26 @@ CREATE TABLE Tasks (
FOREIGN KEY(PersonID) FOREIGN KEY(PersonID)
REFERENCES Persons(PersonID) REFERENCES Persons(PersonID)
); );
CREATE TABLE Products (
ProductID INT NOT NULL PRIMARY KEY,
ProductName varchar(255)
);
CREATE TABLE Products_Tasks (
ProductID INT NOT NULL,
TaskID INT NOT NULL,
CONSTRAINT fkProducts
FOREIGN KEY(ProductID)
REFERENCES Products(ProductID),
CONSTRAINT fkTasks
FOREIGN KEY(TaskID)
REFERENCES Tasks(TaskID),
PRIMARY KEY (ProductID, TaskID)
);
INSERT INTO Persons (PersonID, FirstName, LastName, Address, City) VALUES (1, 'Mike', 'Hughes', '123 Fake Street', 'Belfast');
INSERT INTO Tasks (TaskID, PersonID, TaskName) VALUES (1, 1, 'assembling');
INSERT INTO Products (ProductID, ProductName) VALUES (1, 'Computers');
INSERT INTO Products (ProductID, ProductName) VALUES (2, 'Laptops');
INSERT INTO Products (ProductID, ProductName) VALUES (3, 'Chairs');
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (1, 1);
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (2, 1);
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (3, 1);

View File

@ -0,0 +1,3 @@
#!/bin/bash
docker-compose down
docker volume prune -f

View File

@ -0,0 +1,78 @@
interface Base {
_id?: string
_rev?: string
}
export interface TableSchema {
[key: string]: {
// TODO: replace with field types enum when done
type: string
fieldName?: string
name: string
constraints?: {
type?: string
email?: boolean
inclusion?: string[]
length?: {
minimum?: string | number
maximum?: string | number
}
presence?: boolean
}
}
}
export interface Table extends Base {
type?: string
views?: {}
name?: string
primary?: string[]
schema: TableSchema
primaryDisplay?: string
sourceId?: string
}
export interface Row extends Base {
type?: string
tableId: string
[key: string]: any
}
interface JsonSchemaField {
properties: {
[key: string]: {
type: string
title: string
customType?: string
}
}
required?: string[]
}
export interface AutomationStep {
description: string
event?: string
icon: string
id: string
inputs: {
[key: string]: any
}
name: string
schema: {
inputs: JsonSchemaField
outputs: JsonSchemaField
}
stepId: string
tagline: string
type: string
}
export interface Automation extends Base {
name: string
type: string
appId?: string
definition: {
steps: AutomationStep[]
trigger?: AutomationStep
}
}

View File

@ -75,11 +75,7 @@ export interface SearchFilters {
} }
export interface RelationshipsJson { export interface RelationshipsJson {
through?: { through?: string
from: string
to: string
tableName: string
}
from: string from: string
to: string to: string
tableName: string tableName: string

View File

@ -2,7 +2,7 @@ import {
Integration, Integration,
DatasourceFieldTypes, DatasourceFieldTypes,
QueryTypes, QueryTypes,
} from "./base/definitions" } from "../definitions/datasource"
module AirtableModule { module AirtableModule {
const Airtable = require("airtable") const Airtable = require("airtable")

View File

@ -2,7 +2,7 @@ import {
Integration, Integration,
DatasourceFieldTypes, DatasourceFieldTypes,
QueryTypes, QueryTypes,
} from "./base/definitions" } from "../definitions/datasource"
module ArangoModule { module ArangoModule {
const { Database, aql } = require("arangojs") const { Database, aql } = require("arangojs")

View File

@ -7,7 +7,7 @@ import {
SortDirection, SortDirection,
Operation, Operation,
RelationshipsJson, RelationshipsJson,
} from "./definitions" } from "../../definitions/datasource"
type KnexQuery = Knex.QueryBuilder | Knex type KnexQuery = Knex.QueryBuilder | Knex

View File

@ -2,7 +2,7 @@ import {
Integration, Integration,
DatasourceFieldTypes, DatasourceFieldTypes,
QueryTypes, QueryTypes,
} from "./base/definitions" } from "../definitions/datasource"
module CouchDBModule { module CouchDBModule {
const PouchDB = require("pouchdb") const PouchDB = require("pouchdb")

View File

@ -2,7 +2,7 @@ import {
Integration, Integration,
DatasourceFieldTypes, DatasourceFieldTypes,
QueryTypes, QueryTypes,
} from "./base/definitions" } from "../definitions/datasource"
module DynamoModule { module DynamoModule {
const AWS = require("aws-sdk") const AWS = require("aws-sdk")

View File

@ -2,7 +2,7 @@ import {
Integration, Integration,
DatasourceFieldTypes, DatasourceFieldTypes,
QueryTypes, QueryTypes,
} from "./base/definitions" } from "../definitions/datasource"
module ElasticsearchModule { module ElasticsearchModule {
const { Client } = require("@elastic/elasticsearch") const { Client } = require("@elastic/elasticsearch")

View File

@ -4,7 +4,7 @@ import {
QueryTypes, QueryTypes,
QueryJson, QueryJson,
SqlQuery, SqlQuery,
} from "./base/definitions" } from "../definitions/datasource"
import { getSqlQuery } from "./utils" import { getSqlQuery } from "./utils"
module MSSQLModule { module MSSQLModule {

View File

@ -2,7 +2,7 @@ import {
Integration, Integration,
DatasourceFieldTypes, DatasourceFieldTypes,
QueryTypes, QueryTypes,
} from "./base/definitions" } from "../definitions/datasource"
module MongoDBModule { module MongoDBModule {
const { MongoClient } = require("mongodb") const { MongoClient } = require("mongodb")

View File

@ -5,7 +5,8 @@ import {
Operation, Operation,
QueryJson, QueryJson,
SqlQuery, SqlQuery,
} from "./base/definitions" } from "../definitions/datasource"
import { Table, TableSchema } from "../definitions/common"
import { getSqlQuery } from "./utils" import { getSqlQuery } from "./utils"
module MySQLModule { module MySQLModule {
@ -139,7 +140,7 @@ module MySQLModule {
} }
async buildSchema(datasourceId: string) { async buildSchema(datasourceId: string) {
const tables: any = {} const tables: { [key: string]: Table } = {}
const database = this.config.database const database = this.config.database
this.client.connect() this.client.connect()
@ -154,7 +155,7 @@ module MySQLModule {
) )
for (let tableName of tableNames) { for (let tableName of tableNames) {
const primaryKeys = [] const primaryKeys = []
const schema: any = {} const schema: TableSchema = {}
const descResp = await internalQuery( const descResp = await internalQuery(
this.client, this.client,
{ sql: `DESCRIBE ${tableName};` }, { sql: `DESCRIBE ${tableName};` },
@ -166,7 +167,7 @@ module MySQLModule {
primaryKeys.push(columnName) primaryKeys.push(columnName)
} }
const constraints = { const constraints = {
required: column.Null !== "YES", presence: column.Null !== "YES",
} }
schema[columnName] = { schema[columnName] = {
name: columnName, name: columnName,
@ -212,7 +213,7 @@ module MySQLModule {
} }
async getReturningRow(json: QueryJson) { async getReturningRow(json: QueryJson) {
if (!json.extra.idFilter) { if (!json.extra || !json.extra.idFilter) {
return {} return {}
} }
const input = this._query({ const input = this._query({

View File

@ -4,8 +4,8 @@ import {
QueryTypes, QueryTypes,
QueryJson, QueryJson,
SqlQuery, SqlQuery,
} from "./base/definitions" } from "../definitions/datasource"
import { Table } from "../constants/definitions" import { Table } from "../definitions/common"
import { getSqlQuery } from "./utils" import { getSqlQuery } from "./utils"
module PostgresModule { module PostgresModule {

View File

@ -2,7 +2,7 @@ import {
Integration, Integration,
DatasourceFieldTypes, DatasourceFieldTypes,
QueryTypes, QueryTypes,
} from "./base/definitions" } from "../definitions/datasource"
module RestModule { module RestModule {
const fetch = require("node-fetch") const fetch = require("node-fetch")

View File

@ -1,4 +1,4 @@
import { Integration, QueryTypes } from "./base/definitions" import { Integration, QueryTypes } from "../definitions/datasource"
module S3Module { module S3Module {
const AWS = require("aws-sdk") const AWS = require("aws-sdk")

View File

@ -1,4 +1,4 @@
import { SqlQuery } from "./base/definitions" import { SqlQuery } from "../definitions/datasource"
const { DocumentTypes, SEPARATOR } = require("../db/utils") const { DocumentTypes, SEPARATOR } = require("../db/utils")
const { FieldTypes } = require("../constants") const { FieldTypes } = require("../constants")

File diff suppressed because it is too large Load Diff