Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove row limit #45

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion graphql-server/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ enum QueryExecutionStatus {
Success
Error
Timeout
RowLimit
}

type Status {
Expand Down
2 changes: 1 addition & 1 deletion graphql-server/src/branches/branch.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SortBranchesBy } from "./branch.enum";
export const branchQuery = `SELECT * FROM dolt_branches WHERE name=?`;

export const getBranchesQuery = (sortBy?: SortBranchesBy) =>
`SELECT * FROM dolt_branches ${getOrderByForBranches(sortBy)}LIMIT 200`;
`SELECT * FROM dolt_branches ${getOrderByForBranches(sortBy)}`;

export const callNewBranch = `CALL DOLT_BRANCH(?, ?)`;

Expand Down
1 change: 0 additions & 1 deletion graphql-server/src/sqlSelects/sqlSelect.enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export enum QueryExecutionStatus {
Success,
Error,
Timeout,
RowLimit,
}

registerEnumType(QueryExecutionStatus, { name: "QueryExecutionStatus" });
16 changes: 3 additions & 13 deletions graphql-server/src/sqlSelects/sqlSelect.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,13 @@ export function fromSqlSelectRow(
};
}

// Get first 201 rows to determine if limit has been reached
const sliced = doltRows.slice(0, 201);
const rows: row.Row[] = sliced.map(row.fromDoltRowRes);
if (!rows.length) {
if (!doltRows.length) {
return res;
}
const columns: column.Column[] = Object.keys(sliced[0]).map(c => {
const rows: row.Row[] = doltRows.map(row.fromDoltRowRes);
const columns: column.Column[] = Object.keys(doltRows[0]).map(c => {
return { name: c, isPrimaryKey: false, type: "unknown" };
});

if (rows.length > 200) {
return {
...res,
columns,
rows: rows.slice(0, 200),
queryExecutionStatus: QueryExecutionStatus.RowLimit,
};
}
return { ...res, columns, rows };
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,23 @@ import Btn from "@components/Btn";
import Loader from "@components/Loader";
import MobileSqlViewer from "@components/SqlEditor/MobileSqlViewer";
import { useSqlEditorContext } from "@contexts/sqleditor";
import {
ColumnForDataTableFragment,
useDataTableQuery,
} from "@gen/graphql-types";
import { OptionalRefParams, RefParams } from "@lib/params";
import { OptionalRefParams } from "@lib/params";
import { FaChevronDown } from "@react-icons/all-files/fa/FaChevronDown";
import { FaChevronUp } from "@react-icons/all-files/fa/FaChevronUp";
import { useEffect } from "react";
import Errors from "../Errors";
import { getEditorString, getSqlString } from "../utils";
import css from "./index.module.css";

type Params = OptionalRefParams & {
q?: string;
tableName?: string;
};
type RequireParams = RefParams & {
q?: string;
tableName: string;
};

type Props = {
params: Params;
params: OptionalRefParams & {
q?: string;
tableName?: string;
};
empty?: boolean;
};

type InnerProps = Props & {
cols?: ColumnForDataTableFragment[];
};

type QueryProps = Props & {
params: RequireParams;
};

function Inner(props: InnerProps) {
export default function DatabaseTableHeaderMobile(props: Props) {
const sqlString = getSqlString(
props.params.q,
props.params.tableName,
Expand All @@ -47,30 +29,20 @@ function Inner(props: InnerProps) {
useSqlEditorContext();

useEffect(() => {
const sqlRes = getEditorString(
const sqlQuery = getEditorString(
props.params.q,
props.params.tableName,
props.empty,
props.cols,
);
setEditorString(sqlRes.sqlQuery);
}, [
props.cols,
props.empty,
props.params.q,
props.params.tableName,
setEditorString,
]);
setEditorString(sqlQuery);
}, [props.empty, props.params.q, props.params.tableName]);

return props.empty ? (
<div className={css.empty}>Databases are read-only.</div>
) : (
return (
<div className={css.editorContainer}>
<Loader loaded={!loading} />
<div className={css.editorHeader}>
<Btn className={css.queryHeader} onClick={() => toggleSqlEditor()}>
<span>Query</span>

{showSqlEditor ? (
<FaChevronDown className={css.caret} />
) : (
Expand All @@ -89,27 +61,3 @@ function Inner(props: InnerProps) {
</div>
);
}

function WithQuery(props: QueryProps) {
const res = useDataTableQuery({
variables: props.params,
});
if (res.loading) return <Loader loaded={false} />;
return <Inner {...props} cols={res.data?.table.columns} />;
}

export default function DatabaseTableHeaderMobile(props: Props) {
if (props.params.tableName && props.params.refName) {
return (
<WithQuery
{...props}
params={{
...props.params,
refName: props.params.refName,
tableName: props.params.tableName,
}}
/>
);
}
return <Inner {...props} />;
}
69 changes: 11 additions & 58 deletions web/components/DatabaseTableHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import Btn from "@components/Btn";
import Loader from "@components/Loader";
import SqlEditor from "@components/SqlEditor";
import { useSqlEditorContext } from "@contexts/sqleditor";
import {
ColumnForDataTableFragment,
useDataTableQuery,
} from "@gen/graphql-types";
import { OptionalRefParams, RefParams } from "@lib/params";
import { OptionalRefParams } from "@lib/params";
import { BiPencil } from "@react-icons/all-files/bi/BiPencil";
import dynamic from "next/dynamic";
import { useEffect, useState } from "react";
import { useEffect } from "react";
import Buttons from "./Buttons";
import Errors from "./Errors";
import css from "./index.module.css";
Expand All @@ -19,32 +15,15 @@ const AceEditor = dynamic(async () => import("@components/AceEditor"), {
ssr: false,
});

type Params = OptionalRefParams & {
q?: string;
tableName?: string;
};

type RequireParams = RefParams & {
q?: string;
tableName: string;
};

type Props = {
params: Params;
params: OptionalRefParams & {
q?: string;
tableName?: string;
};
empty?: boolean;
};

type InnerProps = Props & {
cols?: ColumnForDataTableFragment[];
};

type QueryProps = Props & {
params: RequireParams;
};

function Inner(props: InnerProps) {
const [showDefaultQueryInfo, setShowDefaultQueryInfo] = useState(false);

export default function DatabaseTableHeader(props: Props) {
const sqlString = getSqlString(
props.params.q,
props.params.tableName,
Expand All @@ -60,15 +39,13 @@ function Inner(props: InnerProps) {
} = useSqlEditorContext();

useEffect(() => {
const sqlRes = getEditorString(
const sqlQuery = getEditorString(
props.params.q,
props.params.tableName,
props.empty,
props.cols,
);
setEditorString(sqlRes.sqlQuery);
setShowDefaultQueryInfo(sqlRes.showDefaultQueryInfo);
}, [props.cols]);
setEditorString(sqlQuery);
}, [props.params.q, props.params.tableName, props.empty]);

return (
<div className={css.editorContainer}>
Expand All @@ -86,7 +63,7 @@ function Inner(props: InnerProps) {
<Buttons sqlString={editorString} params={props.params} />
</div>
{showSqlEditor ? (
<SqlEditor {...props} showDefaultQueryInfo={showDefaultQueryInfo} />
<SqlEditor {...props} />
) : (
<Btn
data-cy="sql-editor-collapsed"
Expand Down Expand Up @@ -120,27 +97,3 @@ function getQueryTitle(sqlString: string, empty?: boolean): string {
if (empty) return "Sample Query";
return "Query";
}

function WithQuery(props: QueryProps) {
const res = useDataTableQuery({
variables: props.params,
});
if (res.loading) return <Loader loaded={false} />;
return <Inner {...props} cols={res.data?.table.columns} />;
}

export default function DatabaseTableHeader(props: Props) {
if (props.params.tableName && props.params.refName) {
return (
<WithQuery
{...props}
params={{
...props.params,
refName: props.params.refName,
tableName: props.params.tableName,
}}
/>
);
}
return <Inner {...props} />;
}
45 changes: 5 additions & 40 deletions web/components/DatabaseTableHeader/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,41 @@
import { ColumnForDataTableFragment } from "@gen/graphql-types";
import { sampleQuery } from "./utils";

const idPKColumn: ColumnForDataTableFragment = {
name: "id",
isPrimaryKey: true,
type: "INT",
};

const pkPKColumn: ColumnForDataTableFragment = {
name: "pk2",
isPrimaryKey: true,
type: "INT",
};

const nameColumn: ColumnForDataTableFragment = {
name: "name",
isPrimaryKey: false,
type: "VARCHAR(16383)",
};

describe("tests sampleQuery", () => {
const tests: Array<{
desc: string;
cols: ColumnForDataTableFragment[];
expectedQuery: string;
expectedShowLink: boolean;
tableName?: string;
}> = [
{
desc: "Keyless table",
cols: [nameColumn],
expectedQuery: `SELECT *\nFROM \`Keyless table\`\nLIMIT 200;\n`,
expectedShowLink: false,
expectedQuery: `SELECT * FROM \`Keyless table\``,
tableName: "Keyless table",
},
{
desc: "One key and data",
cols: [idPKColumn, nameColumn],
expectedQuery: `SELECT *\nFROM \`One key and data table\`\nORDER BY \`id\` ASC\nLIMIT 200;\n`,
expectedShowLink: true,
expectedQuery: `SELECT * FROM \`One key and data table\``,
tableName: "One key and data table",
},
{
desc: "Two Key",
cols: [idPKColumn, pkPKColumn],
expectedQuery: `SELECT *\nFROM \`Two Keys table\`\nORDER BY \`id\` ASC, \`pk2\` ASC\nLIMIT 200;\n`,
expectedShowLink: true,
expectedQuery: `SELECT * FROM \`Two Keys table\``,
tableName: "Two Keys table",
},
{
desc: "Two Keys and data",
cols: [idPKColumn, pkPKColumn, nameColumn],
expectedQuery: `SELECT *\nFROM \`Two Keys and data table\`\nORDER BY \`id\` ASC, \`pk2\` ASC\nLIMIT 200;\n`,
expectedShowLink: true,
expectedQuery: `SELECT * FROM \`Two Keys and data table\``,
tableName: "Two Keys and data table",
},
{
desc: "no table Name",
cols: [idPKColumn, pkPKColumn, nameColumn],
expectedShowLink: false,
expectedQuery: `SHOW TABLES;\n`,
},
];

tests.forEach(test => {
it(`tests ${test.desc} table default query`, () => {
const { sqlQuery, showDefaultQueryInfo } = sampleQuery(
test.tableName,
test.cols,
);
const sqlQuery = sampleQuery(test.tableName);
expect(sqlQuery).toContain(test.expectedQuery);
expect(showDefaultQueryInfo).toBe(test.expectedShowLink);
});
});
});
Loading
Loading