Skip to content
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

Improve asDrizzleTable() types #10882

Merged
merged 6 commits into from
Apr 26, 2024
Merged

Improve asDrizzleTable() types #10882

merged 6 commits into from
Apr 26, 2024

Conversation

delucis
Copy link
Member

@delucis delucis commented Apr 25, 2024

Changes

  • Improves the typing of the asDrizzleTable() utility

  • Fixes a type error when passing the output of defineTable() to the utility and returns a more detailed type inferred from the columns of the passed table config.

Testing

Tested manually in an integration

Docs

n/a — bug fix

Copy link

changeset-bot bot commented Apr 25, 2024

🦋 Changeset detected

Latest commit: 2aedfce

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@delucis delucis requested a review from bholmesdev April 25, 2024 20:42
@@ -8,8 +8,14 @@ import {
sqliteTable,
text,
} from 'drizzle-orm/sqlite-core';
import { type DBColumn, type DBTable } from '../core/types.js';
import { type SerializedSQL, isSerializedSQL } from './types.js';
import { tableSchema } from '../core/schemas.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ha, it looks like tableSchema would pull a core module into the runtime. We have a lint check against this. Perhaps we can move asDrizzleTable from runtime/ to core/ and still expose as a package export?

Copy link
Member Author

@delucis delucis Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a quick look, but not sure if that would work? asDrizzleTable is used in the Vite plugin:

import { asDrizzleTable, createLocalDatabaseClient, normalizeDatabaseUrl } from ${RUNTIME_IMPORT};

`export const ${name} = asDrizzleTable(${JSON.stringify(name)}, ${JSON.stringify(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, tried a different approach, which seems to work. I think the asDrizzleTable() we expose to users needs to be different from the one we use internally, so in the latest commit I wrapped the internal version with the tweaks we made for use only by integration authors.

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad we could addrizz the issue!

@delucis delucis merged commit cf58d1e into main Apr 26, 2024
13 checks passed
@delucis delucis deleted the chris/improve-asDrizzleTable branch April 26, 2024 14:07
@astrobot-houston astrobot-houston mentioned this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants