Browse Source

Merge branch 'feature/opinionated-sql' of github.com:Budibase/budibase into feature/opinionated-sql

pull/1732/head
mike12345567 5 years ago
parent
commit
ac85f117f6
  1. 5
      packages/builder/cypress/support/commands.js
  2. 2
      packages/builder/src/components/backend/DataTable/DataTable.svelte
  3. 2
      packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte
  4. 3
      packages/builder/src/components/deploy/DeploymentHistory.svelte
  5. 2
      packages/builder/src/pages/builder/app/[application]/data/table/_layout.svelte
  6. 4
      packages/builder/src/stores/backend/datasources.js
  7. 6
      packages/builder/src/stores/backend/tests/datasources.spec.js
  8. 7
      packages/builder/src/stores/backend/tests/queries.spec.js
  9. 8
      packages/builder/src/stores/backend/tests/tables.spec.js
  10. 2
      packages/server/__mocks__/mysql.js
  11. 4
      packages/server/src/api/controllers/row/internal.js
  12. 8
      packages/server/src/integrations/microsoftSqlServer.js
  13. 8
      packages/server/src/integrations/mysql.js
  14. 2
      packages/server/src/integrations/postgres.js
  15. 4
      packages/server/src/integrations/tests/microsoftSqlServer.spec.js
  16. 8
      packages/server/src/integrations/tests/mysql.spec.js
  17. 8
      packages/server/src/integrations/tests/postgres.spec.js

5
packages/builder/cypress/support/commands.js

@ -37,7 +37,7 @@ Cypress.Commands.add("createApp", name => {
cy.contains("Create app").click()
})
.then(() => {
cy.get("[data-cy=new-table]", {
cy.contains("Budibase DB", {
timeout: 20000,
}).should("be.visible")
})
@ -72,7 +72,8 @@ Cypress.Commands.add("createTestTableWithData", () => {
Cypress.Commands.add("createTable", tableName => {
// Enter table name
cy.get("[data-cy=new-table]").click()
cy.get("Budibase DB")
cy.contains("Create new table").click()
cy.get(".spectrum-Modal").within(() => {
cy.get("input").first().type(tableName).blur()
cy.get(".spectrum-ButtonGroup").contains("Create").click()

2
packages/builder/src/components/backend/DataTable/DataTable.svelte

@ -74,6 +74,6 @@
<HideAutocolumnButton bind:hideAutocolumns />
{/if}
<!-- always have the export last -->
<ExportButton view={tableView} />
<ExportButton view={$tables.selected?._id} />
{/if}
</Table>

2
packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte

@ -20,7 +20,7 @@
async function exportView() {
download(
`/api/views/export?view=${encodeURIComponent(
view.name
view
)}&format=${exportFormat}`
)
}

3
packages/builder/src/components/deploy/DeploymentHistory.svelte

@ -88,8 +88,7 @@
onMount(() => {
fetchDeployments()
// TODO: fix
// poll = setInterval(fetchDeployments, POLL_INTERVAL)
poll = setInterval(fetchDeployments, POLL_INTERVAL)
})
onDestroy(() => clearInterval(poll))

2
packages/builder/src/pages/builder/app/[application]/data/table/_layout.svelte

@ -9,7 +9,7 @@
if (
!$leftover &&
$tables.list.length > 0
// (!$tables.selected || !$tables.selected._id)
(!$tables.selected || !$tables.selected._id)
) {
$goto(`./${$tables.list[0]._id}`)
}

4
packages/builder/src/stores/backend/datasources.js

@ -16,12 +16,12 @@ export function createDatasourcesStore() {
init: async () => {
const response = await api.get(`/api/datasources`)
const json = await response.json()
set({ list: json })
set({ list: json, selected: null })
},
fetch: async () => {
const response = await api.get(`/api/datasources`)
const json = await response.json()
update(state => ({ ...state, list: json }))
update(state => ({ ...state, list: json, selected: null }))
return json
},
select: async datasourceId => {

6
packages/builder/src/stores/backend/tests/datasources.spec.js

@ -24,10 +24,10 @@ describe("Datasources Store", () => {
})
it("fetches all the datasources and updates the store", async () => {
api.get.mockReturnValue({ json: () => [SOME_DATASOURCE]})
api.get.mockReturnValue({ json: () => [SOME_DATASOURCE] })
await store.fetch()
expect(get(store)).toEqual({ list: [SOME_DATASOURCE], selected: null})
expect(get(store)).toEqual({ list: [SOME_DATASOURCE], selected: null })
})
it("selects a datasource", async () => {
@ -44,7 +44,7 @@ describe("Datasources Store", () => {
})
it("saves the datasource, updates the store and returns status message", async () => {
api.post.mockReturnValue({ json: () => SAVE_DATASOURCE})
api.post.mockReturnValue({ status: 200, json: () => SAVE_DATASOURCE})
await store.save({
name: 'CoolDB',

7
packages/builder/src/stores/backend/tests/queries.spec.js

@ -30,13 +30,6 @@ describe("Queries Store", () => {
expect(get(store)).toEqual({ list: [SOME_QUERY], selected: null})
})
it("selects a query and updates selected datasource", async () => {
await store.select(SOME_QUERY)
expect(get(store).selected).toEqual(SOME_QUERY._id)
expect(get(datasources).selected).toEqual(SOME_QUERY.datasourceId)
})
it("saves the query, updates the store and returns status message", async () => {
api.post.mockReturnValue({ json: () => SAVE_QUERY_RESPONSE})

8
packages/builder/src/stores/backend/tests/tables.spec.js

@ -41,14 +41,6 @@ describe("Tables Store", () => {
expect(get(store).draft).toEqual({})
})
it("selecting a table updates the view store", async () => {
const tableToSelect = SOME_TABLES[0]
await store.select(tableToSelect)
expect(get(store).selected).toEqual(tableToSelect)
expect(get(views).selected).toEqual({ name: tableToSelect._id })
})
it("saving a table also selects it", async () => {
api.post.mockReturnValue({ json: () => SAVE_TABLES_RESPONSE})

2
packages/server/__mocks__/mysql.js

@ -2,7 +2,7 @@ const mysql = {}
const client = {
connect: jest.fn(),
query: jest.fn((query, fn) => {
query: jest.fn((query, bindings, fn) => {
fn(null, [])
}),
}

4
packages/server/src/api/controllers/row/internal.js

@ -135,8 +135,8 @@ exports.fetchView = async ctx => {
const viewName = ctx.params.viewName
// if this is a table view being looked for just transfer to that
if (viewName.startsWith(TABLE_VIEW_BEGINS_WITH)) {
ctx.params.tableId = viewName.substring(4)
if (viewName.includes(DocumentTypes.TABLE)) {
ctx.params.tableId = viewName
return exports.fetch(ctx)
}

8
packages/server/src/integrations/microsoftSqlServer.js

@ -85,25 +85,25 @@ class SqlServerIntegration extends Sql {
async read(query) {
await this.connect()
const response = await internalQuery(this.client, query.sql)
const response = await internalQuery(this.client, query)
return response.recordset
}
async create(query) {
await this.connect()
const response = await internalQuery(this.client, query.sql)
const response = await internalQuery(this.client, query)
return response.recordset || [{ created: true }]
}
async update(query) {
await this.connect()
const response = await internalQuery(this.client, query.sql)
const response = await internalQuery(this.client, query)
return response.recordset || [{ updated: true }]
}
async delete(query) {
await this.connect()
const response = await internalQuery(this.client, query.sql)
const response = await internalQuery(this.client, query)
return response.recordset || [{ deleted: true }]
}

8
packages/server/src/integrations/mysql.js

@ -79,21 +79,21 @@ class MySQLIntegration extends Sql {
}
async create(query) {
const results = await internalQuery(this.client, query.sql)
const results = await internalQuery(this.client, query)
return results.length ? results : [{ created: true }]
}
read(query) {
return internalQuery(this.client, query.sql)
return internalQuery(this.client, query)
}
async update(query) {
const results = await internalQuery(this.client, query.sql)
const results = await internalQuery(this.client, query)
return results.length ? results : [{ updated: true }]
}
async delete(query) {
const results = await internalQuery(this.client, query.sql)
const results = await internalQuery(this.client, query)
return results.length ? results : [{ deleted: true }]
}

2
packages/server/src/integrations/postgres.js

@ -168,7 +168,7 @@ class PostgresIntegration extends Sql {
return response.rows.length ? response.rows : [{ updated: true }]
}
async delete({ sql }) {
async delete(sql) {
const response = await internalQuery(this.client, sql)
return response.rows.length ? response.rows : [{ deleted: true }]
}

4
packages/server/src/integrations/tests/microsoftSqlServer.spec.js

@ -20,7 +20,7 @@ describe("MS SQL Server Integration", () => {
const response = await config.integration.create({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined)
})
it("calls the read method with the correct params", async () => {
@ -28,7 +28,7 @@ describe("MS SQL Server Integration", () => {
const response = await config.integration.read({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql)
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined)
})
describe("no rows returned", () => {

8
packages/server/src/integrations/tests/mysql.spec.js

@ -19,7 +19,7 @@ describe("MySQL Integration", () => {
await config.integration.create({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, expect.any(Function))
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function))
})
it("calls the read method with the correct params", async () => {
@ -27,7 +27,7 @@ describe("MySQL Integration", () => {
await config.integration.read({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, expect.any(Function))
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function))
})
it("calls the update method with the correct params", async () => {
@ -35,7 +35,7 @@ describe("MySQL Integration", () => {
await config.integration.update({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, expect.any(Function))
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function))
})
it("calls the delete method with the correct params", async () => {
@ -43,7 +43,7 @@ describe("MySQL Integration", () => {
await config.integration.delete({
sql
})
expect(config.integration.client.query).toHaveBeenCalledWith(sql, expect.any(Function))
expect(config.integration.client.query).toHaveBeenCalledWith(sql, undefined, expect.any(Function))
})
describe("no rows returned", () => {

8
packages/server/src/integrations/tests/postgres.spec.js

@ -20,7 +20,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.create({
sql
})
expect(pg.queryMock).toHaveBeenCalledWith(sql)
expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined)
})
it("calls the read method with the correct params", async () => {
@ -28,7 +28,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.read({
sql
})
expect(pg.queryMock).toHaveBeenCalledWith(sql)
expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined)
})
it("calls the update method with the correct params", async () => {
@ -36,7 +36,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.update({
sql
})
expect(pg.queryMock).toHaveBeenCalledWith(sql)
expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined)
})
it("calls the delete method with the correct params", async () => {
@ -44,7 +44,7 @@ describe("Postgres Integration", () => {
await config.integration.delete({
sql
})
expect(pg.queryMock).toHaveBeenCalledWith(sql)
expect(pg.queryMock).toHaveBeenCalledWith(sql, undefined)
})
describe("no rows returned", () => {

Loading…
Cancel
Save