Skip to content

Commit

Permalink
change: schema database
Browse files Browse the repository at this point in the history
  • Loading branch information
sokphaladam committed Dec 16, 2024
1 parent e98ba7a commit cb51a10
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/components/gui/schema-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function SchemaView() {

const ActivatorButton = () => {

if (!databaseDriver.getFlags().suppoerCreateUpdateDatabase && !databaseDriver.getFlags().supportCreateUpdateTable) {
if (!databaseDriver.getFlags().supportCreateUpdateDatabase && !databaseDriver.getFlags().supportCreateUpdateTable) {
return <></>
}

Expand Down Expand Up @@ -68,7 +68,7 @@ export default function SchemaView() {
<Command>
<CommandList>
{
databaseDriver.getFlags().suppoerCreateUpdateDatabase && <CommandItem onSelect={() => onNewDatabase()}>New schema/database</CommandItem>
databaseDriver.getFlags().supportCreateUpdateDatabase && <CommandItem onSelect={() => onNewDatabase()}>New schema/database</CommandItem>
}
{
databaseDriver.getFlags().supportCreateUpdateTable && <CommandItem onSelect={() => onNewTable()}>New table</CommandItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { cn } from "@/components/lib/utils";
import { Button } from "@/components/ui/button";
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { useDatabaseDriver } from "@/context/driver-provider";
import { Check, ChevronsUpDown } from "lucide-react";
import { useState } from "react";
import { ChevronsUpDown } from "lucide-react";

interface SchemaCollateSelectProps {
value?: string;
Expand All @@ -19,11 +16,10 @@ export function SchemaDatabaseCollation(
}: SchemaCollateSelectProps
) {
const driver = useDatabaseDriver();
const [open, setOpen] = useState(false);

return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant={"outline"}
role="combobox"
Expand All @@ -32,35 +28,18 @@ export function SchemaDatabaseCollation(
{value || "Select collate"}
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-[200px] p-0">
<Command>
<CommandInput placeholder="Search collation" />
<CommandList>
<CommandEmpty>No matched collation</CommandEmpty>
<CommandGroup>
{
driver.databaseDriver.getCollationList().map(x => {
return (
<CommandItem key={x} value={x} onSelect={() => {
onChange(x);
setOpen(false)
}}>
<Check
className={cn(
"mr-2 h-4 w-4",
value === x ? "opacity-100" : "opacity-0"
)}
/>
{x}
</CommandItem>
)
})
}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-[200px] p-0 overflow-y-auto h-[500px]">
{
driver.databaseDriver.getCollationList().map(x => {
return (
<DropdownMenuItem key={x} onClick={() => {
onChange(x);
}}>{x}</DropdownMenuItem>
)
})
}
</DropdownMenuContent>
</DropdownMenu>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function SchemaDatabaseDialog({ previewScript, onClose, schema }: Props)
setIsExecuting(false);
})
}
}, [databaseDriver, onClose, previewScript, refreshSchema])
}, [databaseDriver, onClose, previewScript, refreshSchema, replaceCurrentTab, schema.name.new])

return (
<AlertDialog open onOpenChange={onClose}>
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export interface DriverFlags {
supportInsertReturning: boolean;
supportUpdateReturning: boolean;
supportRowId: boolean;
suppoerCreateUpdateDatabase: boolean;
supportCreateUpdateDatabase: boolean;
}

export interface DatabaseTableColumnChange {
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/mysql/mysql-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default abstract class MySQLLikeDriver extends CommonSQLImplement {
supportModifyColumn: true,
mismatchDetection: false,
supportCreateUpdateTable: true,
suppoerCreateUpdateDatabase: true,
supportCreateUpdateDatabase: true,
dialect: "mysql",

supportUseStatement: true,
Expand Down
5 changes: 2 additions & 3 deletions src/drivers/postgres/postgres-driver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
ColumnTypeSelector,
DatabaseSchemaChange,
DatabaseSchemaItem,
DatabaseSchemas,
DatabaseTableColumn,
Expand Down Expand Up @@ -78,7 +77,7 @@ export default abstract class PostgresLikeDriver extends CommonSQLImplement {
supportModifyColumn: false,
mismatchDetection: false,
supportCreateUpdateTable: false,
suppoerCreateUpdateDatabase: false,
supportCreateUpdateDatabase: false,
supportInsertReturning: true,
supportUpdateReturning: true,
};
Expand Down Expand Up @@ -352,7 +351,7 @@ WHERE
throw new Error("Not implemented");
}

createUpdateDatabaseSchema(change: DatabaseSchemaChange): string[] {
createUpdateDatabaseSchema(): string[] {
throw new Error("Not implemented");
}

Expand Down
5 changes: 5 additions & 0 deletions src/drivers/sqlite-base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement {
optionalSchema: true,
mismatchDetection: false,
supportCreateUpdateTable: true,
supportCreateUpdateDatabase: false,
dialect: "sqlite",
};
}
Expand Down Expand Up @@ -230,6 +231,10 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement {
return generateSqlSchemaChange(change);
}

createUpdateDatabaseSchema(): string[] {
throw new Error("Not implemented");
}

override async findFirst(
schemaName: string,
tableName: string,
Expand Down

0 comments on commit cb51a10

Please sign in to comment.