feature (console): add DAL method to get defaultQueryRoot for a database based on driver type

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7569
GitOrigin-RevId: 22e86bece0c66b9a0a3af9d8085e493a311d1139
This commit is contained in:
Vijay Prasanna 2023-01-19 11:29:50 +05:30 committed by hasura-bot
parent f1328393b9
commit 42a536a8ab
10 changed files with 106 additions and 2 deletions

View File

@ -1,4 +1,6 @@
import { Table } from '@/features/hasura-metadata-types';
import { Database } from '..';
import { defaultDatabaseProps } from '../common/defaultDatabaseProps';
import {
getDatabaseConfiguration,
getTrackableTables,
@ -12,6 +14,7 @@ import { getTableRows } from '../postgres/query';
export type AlloyDbTable = { name: string; schema: string };
export const alloy: Database = {
...defaultDatabaseProps,
introspection: {
getDriverInfo: async () => ({
name: 'alloy',
@ -31,4 +34,10 @@ export const alloy: Database = {
query: {
getTableRows,
},
config: {
getDefaultQueryRoot: async (table: Table) => {
const { name, schema } = table as AlloyDbTable;
return schema === 'public' ? name : `${schema}_${name};`;
},
},
};

View File

@ -1,4 +1,6 @@
import { Table } from '@/features/hasura-metadata-types';
import { Database, Feature } from '..';
import { defaultDatabaseProps } from '../common/defaultDatabaseProps';
import {
getTrackableTables,
getTableColumns,
@ -10,6 +12,7 @@ import { getTableRows } from './query';
export type BigQueryTable = { name: string; dataset: string };
export const bigquery: Database = {
...defaultDatabaseProps,
introspection: {
getDriverInfo: async () => ({
name: 'bigquery',
@ -31,4 +34,10 @@ export const bigquery: Database = {
query: {
getTableRows,
},
config: {
getDefaultQueryRoot: async (table: Table) => {
const { name, dataset } = table as BigQueryTable;
return `${dataset}_${name};`;
},
},
};

View File

@ -1,5 +1,7 @@
import { Table } from '@/features/hasura-metadata-types';
import { Database, Feature } from '..';
import { runSQL } from '../api';
import { defaultDatabaseProps } from '../common/defaultDatabaseProps';
import { adaptIntrospectedTables } from '../common/utils';
import { GetTrackableTablesProps } from '../types';
import {
@ -13,6 +15,7 @@ import { getTableRows } from './query';
export type CitusTable = { name: string; schema: string };
export const citus: Database = {
...defaultDatabaseProps,
introspection: {
getDriverInfo: async () => ({
name: 'citus',
@ -66,4 +69,10 @@ export const citus: Database = {
query: {
getTableRows,
},
config: {
getDefaultQueryRoot: async (table: Table) => {
const { name, schema } = table as CitusTable;
return schema === 'public' ? name : `${schema}_${name};`;
},
},
};

View File

@ -1,5 +1,7 @@
import { Table } from '@/features/hasura-metadata-types';
import { Database, Feature } from '..';
import { runSQL } from '../api';
import { defaultDatabaseProps } from '../common/defaultDatabaseProps';
import { adaptIntrospectedTables } from '../common/utils';
import { GetTrackableTablesProps } from '../types';
import {
@ -13,6 +15,7 @@ import { getTableRows } from './query';
export type CockroachDBTable = { name: string; schema: string };
export const cockroach: Database = {
...defaultDatabaseProps,
introspection: {
getDriverInfo: async () => ({
name: 'cockroach',
@ -64,4 +67,10 @@ export const cockroach: Database = {
query: {
getTableRows,
},
config: {
getDefaultQueryRoot: async (table: Table) => {
const { name, schema } = table as CockroachDBTable;
return schema === 'public' ? name : `${schema}_${name};`;
},
},
};

View File

@ -0,0 +1,20 @@
import { Database, Feature } from '..';
export const defaultDatabaseProps: Database = {
config: {
getDefaultQueryRoot: async () => Feature.NotImplemented,
},
introspection: {
getDriverInfo: async () => Feature.NotImplemented,
getDatabaseConfiguration: async () => Feature.NotImplemented,
getTrackableTables: async () => Feature.NotImplemented,
getDatabaseHierarchy: async () => Feature.NotImplemented,
getTableColumns: async () => Feature.NotImplemented,
getFKRelationships: async () => Feature.NotImplemented,
getTablesListAsTree: async () => Feature.NotImplemented,
getSupportedOperators: async () => Feature.NotImplemented,
},
query: {
getTableRows: async () => Feature.NotImplemented,
},
};

View File

@ -1,3 +1,5 @@
import { Table } from '@/features/hasura-metadata-types';
import { defaultDatabaseProps } from '../common/defaultDatabaseProps';
import { Database, Feature } from '../index';
import {
getTablesListAsTree,
@ -17,6 +19,7 @@ import { getTableRows } from './query';
export type GDCTable = string[];
export const gdc: Database = {
...defaultDatabaseProps,
introspection: {
getDriverInfo: async () => Feature.NotImplemented,
getDatabaseConfiguration,
@ -35,4 +38,9 @@ export const gdc: Database = {
query: {
getTableRows,
},
config: {
getDefaultQueryRoot: async (table: Table) => {
return (table as GDCTable).join('_');
},
},
};

View File

@ -104,7 +104,11 @@ export type Database = {
props: GetTableRowsProps
) => Promise<TableRow[] | Feature.NotImplemented>;
};
modify?: null;
config: {
getDefaultQueryRoot: (
table: Table
) => Promise<string | Feature.NotImplemented>;
};
};
const drivers: Record<SupportedDrivers, Database> = {
@ -416,6 +420,22 @@ export const DataSource = (httpClient: AxiosInstance) => ({
return operators;
},
getDefaultQueryRoot: async ({
dataSourceName,
table,
}: {
dataSourceName: string;
table: Table;
}) => {
const database = await getDatabaseMethods({ dataSourceName, httpClient });
if (!database) return [];
const result = await database.config.getDefaultQueryRoot(table);
if (result === Feature.NotImplemented) return Feature.NotImplemented;
return result;
},
});
export { GDCTable } from './gdc';

View File

@ -1,5 +1,7 @@
import { Table } from '@/features/hasura-metadata-types';
import { Database, Feature } from '..';
import { NetworkArgs, runSQL } from '../api';
import { defaultDatabaseProps } from '../common/defaultDatabaseProps';
import { adaptIntrospectedTables } from '../common/utils';
import {
getTableColumns,
@ -12,6 +14,7 @@ import { getTableRows } from './query';
export type MssqlTable = { schema: string; name: string };
export const mssql: Database = {
...defaultDatabaseProps,
introspection: {
getDriverInfo: async () => ({
name: 'mssql',
@ -55,4 +58,10 @@ export const mssql: Database = {
query: {
getTableRows,
},
config: {
getDefaultQueryRoot: async (table: Table) => {
const { name, schema } = table as MssqlTable;
return schema === 'dbo' ? name : `${schema}_${name};`;
},
},
};

View File

@ -1,8 +1,10 @@
import { Database, Feature } from '..';
import { defaultDatabaseProps } from '../common/defaultDatabaseProps';
export type MySQLTable = { name: string };
export const postgres: Database = {
export const mysql: Database = {
...defaultDatabaseProps,
introspection: {
getDriverInfo: async () => ({
name: 'mysql',

View File

@ -1,4 +1,6 @@
import { Table } from '@/features/hasura-metadata-types';
import { Database } from '..';
import { defaultDatabaseProps } from '../common/defaultDatabaseProps';
import {
getDatabaseConfiguration,
getTrackableTables,
@ -12,6 +14,7 @@ import { getTableRows } from './query';
export type PostgresTable = { name: string; schema: string };
export const postgres: Database = {
...defaultDatabaseProps,
introspection: {
getDriverInfo: async () => ({
name: 'postgres',
@ -31,4 +34,10 @@ export const postgres: Database = {
query: {
getTableRows,
},
config: {
getDefaultQueryRoot: async (table: Table) => {
const { name, schema } = table as PostgresTable;
return schema === 'public' ? name : `${schema}_${name};`;
},
},
};