-
Notifications
You must be signed in to change notification settings - Fork 1
Standardize table schema format #75
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
Changes from 4 commits
4b6a256
f94f48b
c548837
e198e05
dc408e4
c0b5382
8f45f90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { Table as TablelandTable } from "@tableland/sdk"; | ||
| import { InferInsertModel, InferSelectModel } from "drizzle-orm"; | ||
| import { | ||
| integer, | ||
|
|
@@ -150,7 +151,11 @@ export const teamInvites = sqliteTable("team_invites", { | |
| claimedAt: text("claimed_at"), | ||
| }); | ||
|
|
||
| export type Table = InferSelectModel<typeof tables>; | ||
| export type Schema = TablelandTable["schema"]; | ||
|
|
||
| export type Table = Omit<InferSelectModel<typeof tables>, "schema"> & { | ||
| schema: Schema; | ||
| }; | ||
| export type NewTable = InferInsertModel<typeof tables>; | ||
|
||
|
|
||
| export type UserSealed = InferSelectModel<typeof users>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { | |
| SelectTrigger, | ||
| SelectValue, | ||
| } from "@/components/ui/select"; | ||
| import { generateCreateTableStatement } from "@/lib/schema"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { | ||
| Database, | ||
|
|
@@ -108,8 +109,9 @@ export default function ExecDeployment({ | |
| baseUrl: helpers.getBaseUrl(chainId), | ||
| autoWait: false, | ||
| }); | ||
| // TODO: Table.schema will be JSON, convert it to SQL create table statement. | ||
| const res = await tbl.exec(table.schema); | ||
|
|
||
| const stmt = generateCreateTableStatement(table.name, table.schema); | ||
| const res = await tbl.exec(stmt); | ||
|
Comment on lines
+112
to
+114
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Convert the |
||
| if (res.error) { | ||
| throw new Error(res.error); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,7 @@ | ||
| "use client"; | ||
|
|
||
| import { newTable } from "@/app/actions"; | ||
| import SchemaBuilder, { | ||
| createTableStatementFromObject, | ||
| } from "@/components/schema-builder"; | ||
| import SchemaBuilder from "@/components/schema-builder"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Form, | ||
|
|
@@ -16,14 +14,13 @@ import { | |
| } from "@/components/ui/form"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { Textarea } from "@/components/ui/textarea"; | ||
| import { createTableAtom } from "@/store/create-table"; | ||
| import { cleanSchema, generateCreateTableStatement } from "@/lib/schema"; | ||
| import { zodResolver } from "@hookform/resolvers/zod"; | ||
| import { helpers } from "@tableland/sdk"; | ||
| import { schema } from "@tableland/studio-store"; | ||
| import { useAtom } from "jotai"; | ||
| import { Loader2 } from "lucide-react"; | ||
| import { useRouter } from "next/navigation"; | ||
| import { useTransition } from "react"; | ||
| import { useState, useTransition } from "react"; | ||
| import { useFieldArray, useForm } from "react-hook-form"; | ||
| import * as z from "zod"; | ||
|
|
||
|
|
@@ -51,7 +48,7 @@ export default function NewTable({ project, team, envs }: Props) { | |
| const [pending, startTransition] = useTransition(); | ||
| const router = useRouter(); | ||
|
|
||
| const [createTable, setCreateTable] = useAtom(createTableAtom); | ||
| const [schema, setSchema] = useState<schema.Schema>({ columns: [] }); | ||
|
|
||
| const form = useForm<z.infer<typeof formSchema>>({ | ||
| resolver: zodResolver(formSchema), | ||
|
|
@@ -73,17 +70,13 @@ export default function NewTable({ project, team, envs }: Props) { | |
|
|
||
| function onSubmit(values: z.infer<typeof formSchema>) { | ||
| startTransition(async () => { | ||
| const statement = createTableStatementFromObject( | ||
| createTable, | ||
| await newTable( | ||
| project, | ||
| values.name, | ||
| values.description, | ||
| cleanSchema(schema), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ); | ||
| if (!statement) { | ||
| console.error("No statement"); | ||
| return; | ||
| } | ||
| await newTable(project, values.name, statement, values.description); | ||
| router.replace(`/${team.slug}/${project.slug}`); | ||
| setCreateTable({ columns: [] }); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -128,8 +121,8 @@ export default function NewTable({ project, team, envs }: Props) { | |
| /> | ||
| <div className="space-y-2"> | ||
| <FormLabel>Columns</FormLabel> | ||
| <SchemaBuilder /> | ||
| <pre>{createTableStatementFromObject(createTable, name)}</pre> | ||
| <SchemaBuilder schema={schema} setSchema={setSchema} /> | ||
| <pre>{generateCreateTableStatement(name, schema)}</pre> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Display the equivalent create statement in real time. |
||
| </div> | ||
| {/* <div className="space-y-2"> | ||
| <FormLabel>Deployments</FormLabel> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird, see my comment in
packages/store/src/schema/index.tsfor an explanation.