Skip to content
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: 1 addition & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage
.env*
*.log
pnpm-lock.yaml
openapi.json
2 changes: 1 addition & 1 deletion frontend/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
allowBuilds:
'@swc/core': true
"@swc/core": true
esbuild: true
28 changes: 12 additions & 16 deletions frontend/src/components/tables/RowDetailsSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export const RowDetailsSheet = () => {
deleteRow,
} = useRowContext();
if (!rowDetailssheetData) return null;
// todo : row itself can have a hash so we have to do something better
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { hash, ...row } = rowDetailssheetData.row;
const row = rowDetailssheetData.row.columns;
return (
<Sheet open={rowDetailsSheetOpen} onOpenChange={setRowDetailsSheetOpen}>
<SheetContent className="flex min-w-[90%] flex-col md:min-w-xl">
Expand All @@ -43,23 +41,21 @@ export const RowDetailsSheet = () => {

<ScrollArea type="always" className="min-h-0 flex-1">
<div className="flex flex-col divide-y p-4">
{Object.entries(row || {}).map(([key, value]) => (
<div key={key} className="flex flex-col gap-1 py-3">
{(row || []).map((col) => (
<div key={col.columnName} className="flex flex-col gap-1 py-3">
<label className="text-xs font-medium text-muted-foreground capitalize">
{key}
{col.columnName}
</label>
<p className="font-mono text-sm break-all whitespace-pre-wrap">
<div className="font-mono text-sm break-all whitespace-pre-wrap">
{(() => {
switch (typeof value) {
case "undefined":
return <p className="text-muted-foreground">-</p>;
case null:
return <p className="text-muted-foreground">null</p>;
default:
return formatValue(value);
}
const value = col.value;
if (value === undefined)
return <p className="text-muted-foreground">-</p>;
if (value === null)
return <p className="text-muted-foreground">null</p>;
return formatValue(value);
})()}
</p>
</div>
</div>
))}
</div>
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/components/tables/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import {
import { RowDetailsSheet } from "./RowDetailsSheet";
import { Input } from "@/components/ui/input";
import { ChevronRight } from "lucide-react";
import { useIsMobile } from "@/hooks/use-mobile";
import { useRowContext } from "@/hooks/useRows";
import { toast } from "sonner";
import type { RowSet } from "@/client";

interface TableViewProps {
tableName: string;
Expand All @@ -31,7 +32,6 @@ interface TableViewProps {
export type RowData = { hash: string } & Record<string, unknown>;

export const TableView = ({ tableName }: TableViewProps) => {
const isMobile = useIsMobile();
const { setRowDetailsSheetOpen, setRowDetailsSheetData, isLoading, data } =
useRowContext();
const [globalFilter, setGlobalFilter] = useState("");
Expand Down Expand Up @@ -60,6 +60,7 @@ export const TableView = ({ tableName }: TableViewProps) => {
() =>
data?.rows?.map((row) => ({
hash: row.hash,
__rowSet: row,
...Object.fromEntries(
(row.columns || []).map((col) => [col.columnName, col.value]),
),
Expand All @@ -68,9 +69,15 @@ export const TableView = ({ tableName }: TableViewProps) => {
);

const handleRowClick = (row: RowData) => {
setRowDetailsSheetData({ row: row, tableName });
const rowSet = row.__rowSet as RowSet;
if (!row) {
toast.error("Row not found");
return;
}
setRowDetailsSheetData({ row: rowSet, tableName });
setRowDetailsSheetOpen(true);
};
// eslint-disable-next-line react-hooks/incompatible-library
const table = useReactTable({
data: flattenedRows,
columns: columns,
Expand Down Expand Up @@ -142,7 +149,7 @@ export const TableView = ({ tableName }: TableViewProps) => {
position: isPinned ? "sticky" : undefined,
right: isPinned === "right" ? 0 : undefined,
zIndex: isPinned ? 1 : 0,
background: isMobile ? "var(--background)" : undefined,
background: "var(--background)",

maxWidth: `${cell.column.getSize()}px`,
overflow: "hidden",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/hooks/useRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
type Dispatch,
type SetStateAction,
} from "react";
import type { ErrorModel, ListRowsResponse } from "@/client";
import type { ErrorModel, ListRowsResponse, RowSet } from "@/client";
import {
deleteRowMutation,
listRowsOptions,
Expand All @@ -18,7 +18,7 @@ import { useSearchParams } from "react-router-dom";

export type RowData = { hash: string } & Record<string, unknown>;

type SheetData = { row: RowData; tableName: string };
type SheetData = { row: RowSet; tableName: string };

export interface RowContextType {
rowDetailsSheetData: SheetData | null;
Expand Down
9 changes: 7 additions & 2 deletions internal/database/repo/quires.sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ func (q *Queries) GetRow(ctx context.Context, tableName, hash string, offest, li
return nil, err
}
logger.Info("not found in cache! Fetching from db limit=%d offset=%d", limit, offest)
for offest <= limit {
totalCount, err := q.GetRowCount(ctx, tableName)
if err != nil {
return nil, err
}

for (offest <= limit) && (offest < totalCount) {
colValue := make([]models.ColValue, len(colValues))
copy(colValue, colValues)
query, args, err := q.queryBuilder.GetRows(tableName, offest+1, offest)
Expand All @@ -238,7 +243,7 @@ func (q *Queries) GetRow(ctx context.Context, tableName, hash string, offest, li
}
data, err := q.db.QueryRowxContext(ctx, query, args...).SliceScan()
if err != nil {
logger.Error("failed to query: %v", err)
logger.Error("offset=%d, limit=%d, totalCount=%d failed to query: %v", offest, limit, totalCount, err)
if !errors.Is(err, sql.ErrNoRows) {
return nil, err
}
Expand Down
18 changes: 15 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ GREETING := Hello from RowSQL!
default:
@echo "$(GREETING)"

generate-schema:
go run ./cmd/schema/main.go

backend-build:
go run ./cmd/schema/main.go
go build -o bin/rowsql ./cmd/server

frontend-build:

cd ./frontend && pnpm run build

backend-dev:
air -c air.toml

frontend-dev:
frontend-dev: generate-schema
cd ./frontend/ && pnpm run dev

dev: backend-dev frontend-dev
dev:
$(MAKE) -j2 frontend-dev backend-dev

build: doc frontend-build backend-build
echo "build was successful"
Expand All @@ -39,6 +44,9 @@ lint:
golangci-lint run
cd ./frontend && pnpm lint

lint-staged:
cd frontend && pnpx lint-staged

clean:
rm -rf dist/
rm -rf bin/
Expand All @@ -52,4 +60,8 @@ install:

format:
gofmt -w .
cd ./frontend && pnpm run format
cd ./frontend && pnpm run format

format-check:
gofmt -l .
cd ./frontend && pnpm run format:check
Loading