Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Support drizzle-zod in Astro DB #1090

Closed
1 task
austinm911 opened this issue Jan 5, 2025 · 1 comment
Closed
1 task

Support drizzle-zod in Astro DB #1090

austinm911 opened this issue Jan 5, 2025 · 1 comment

Comments

@austinm911
Copy link

austinm911 commented Jan 5, 2025

Astro Info

Astro                    v5.1.2
Node                     v20.12.2
System                   macOS (arm64)
Package Manager          bun
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind
                         astro:db
                         @astrojs/db/file-url

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

createInsertSchema accepts a Table type from Drizzle. It appears the Table type created by defineTable is not compatible with drizzle zod.

It would be nice to be able to create or infer zod (i guess Valibot and others too) schemas either natively in Astro DB or be able to use the utilities like the drizzle-zod package.

// db/config.ts
const Character = defineTable({
	columns: {
		id: column.number({ primaryKey: true }),
		name: column.text(),
		age: column.number(),
		occupation: column.text(),
		createdAt: column.date({ default: new Date() }),
	},
})


// db/schema.ts
import { Character } from 'astro:db'
import { z } from 'zod'
import { createInsertSchema } from 'drizzle-zod'

export const CharacterSchema = createInsertSchema(Character) // CharacterSchema.shape has no properties
export type Character = z.infer<typeof CharacterSchema>
// type Character = {}

What's the expected result?

Character should contain the expected columns and their types.

Link to Minimal Reproducible Example

see description

Participation

  • I am willing to submit a pull request for this issue.
@ascorbic
Copy link
Contributor

ascorbic commented Jan 6, 2025

As this is a feature request I'm going to transfer it to discussions.

@ascorbic ascorbic transferred this issue from withastro/astro Jan 6, 2025
@github-project-automation github-project-automation bot moved this to Stage 2: Accepted Proposals, No RFC in Public Roadmap Jan 6, 2025
@withastro withastro locked and limited conversation to collaborators Jan 6, 2025
@ascorbic ascorbic converted this issue into discussion #1091 Jan 6, 2025
@ascorbic ascorbic removed this from Public Roadmap Jan 6, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants