Skip to content

Commit

Permalink
add turso integration
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Jan 10, 2025
1 parent 8205310 commit e1aecbf
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/app/(theme)/embed/turso/page-client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";
import { Studio } from "@/components/gui/studio";
import { IframeSQLiteDriver } from "@/drivers/iframe-driver";
import { useSearchParams } from "next/navigation";
import { useEffect, useMemo } from "react";

export default function EmbedPageClient() {
const searchParams = useSearchParams();

const driver = useMemo(
() =>
new IframeSQLiteDriver({
supportPragmaList: false,
supportBigInt: true,
}),
[]
);

useEffect(() => {
return driver.listen();
}, [driver]);

return (
<Studio
driver={driver}
name={searchParams.get("name") || "Unnamed Connection"}
color={searchParams.get("color") || "gray"}
/>
);
}
4 changes: 4 additions & 0 deletions src/app/(theme)/embed/turso/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createEmbedPage } from "../embed-page";
import EmbedPageClient from "./page-client";

export default createEmbedPage(() => <EmbedPageClient />);
10 changes: 9 additions & 1 deletion src/components/gui/schema-editor/schema-editor-column-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,16 @@ function ColumnItemType({
databaseDriver.columnTypeSelector.type === "dropdown" &&
databaseDriver.columnTypeSelector.dropdownOptions
) {
const normalizedValue = databaseDriver.columnTypeSelector.dropdownNormalized
? databaseDriver.columnTypeSelector.dropdownNormalized(value) || value
: value;

return (
<Select value={value} onValueChange={onChange} disabled={disabled}>
<Select
value={normalizedValue}
onValueChange={onChange}
disabled={disabled}
>
<SelectTrigger className="bg-inherit border-0 rounded-none shadow-none text-sm">
<SelectValue placeholder="Select datatype" />
</SelectTrigger>
Expand Down
1 change: 1 addition & 0 deletions src/drivers/base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export interface ColumnTypeSuggestion {
export interface ColumnTypeSelector {
type: "dropdown" | "text";
dropdownOptions?: { value: string; text: string }[];
dropdownNormalized?: (value: string) => string;
typeSuggestions?: ColumnTypeSuggestionGroup[];

// This will use for auto field when create table column
Expand Down
20 changes: 19 additions & 1 deletion src/drivers/iframe-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,29 @@ export class IframeSQLiteDriver extends SqliteLikeBaseDriver {
? new ElectronConnection()
: new IframeConnection();

constructor(options?: { supportPragmaList: boolean }) {
protected supportBigInt = false;

constructor(options?: {
supportPragmaList: boolean;
supportBigInt: boolean;
}) {
super();
if (options?.supportPragmaList !== undefined) {
this.supportPragmaList = options.supportPragmaList;
}

if (options?.supportBigInt !== undefined) {
this.supportBigInt = options.supportBigInt;
}
}

getFlags(): DriverFlags {
return {
...super.getFlags(),
supportCreateUpdateTable: true,
supportModifyColumn: true,
supportBigInt: this.supportBigInt,
};
}

listen() {
Expand Down
10 changes: 9 additions & 1 deletion src/drivers/sqlite-base-driver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {
import {
ColumnTypeSelector,
DatabaseResultSet,
DatabaseSchemaItem,
Expand Down Expand Up @@ -28,6 +28,14 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement {

columnTypeSelector: ColumnTypeSelector = {
type: "dropdown",
dropdownNormalized: (typeName: string): string => {
const type = convertSqliteType(typeName);
if (type === undefined) return "TEXT";
if (type === TableColumnDataType.INTEGER) return "INTEGER";
if (type === TableColumnDataType.REAL) return "REAL";
if (type === TableColumnDataType.BLOB) return "BLOB";
return "TEXT";
},
dropdownOptions: [
{ text: "Integer", value: "INTEGER" },
{ text: "Real", value: "REAL" },
Expand Down

0 comments on commit e1aecbf

Please sign in to comment.