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

[Mysql] No unknown keys allowed to be passed to insert #1160

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Angelelz
Copy link
Collaborator

@Angelelz Angelelz commented Sep 2, 2023

This PR closes #572 .

  • Added new generic type helper ValidateShape that works on objects and arrays (KnownKeysOnly would only work on objects).
  • Added generic parameter TValue to the values method in MySqlInsertBuilder class.
  • Changed values parameter type for type validation.
  • Replaced the deprecated InferModel for the new $inferInsert.

Given the schema:

export const users = mysqlTable("users", {
    id: serial("id", { length: 26 }),
    username: varchar("username", { length: 191 }).notNull(),
})

If the user passes the following object to values()

const newUser = {
  username: "drizzler",
  firstName: "mysql"
}
const response = db.insert(users).values(newUser);

Argument of type '{ id: string; username: string; firstName: string; }' is not assignable to parameter of type '"Invalid key(s): firstName"'.

Angelelz and others added 5 commits September 1, 2023 23:43
When the user passes on unknown key to the values method on insert, an error will be shown pointing to the incorrect key in the argument passed in.
Validated that the values() shows a type error when unknown keys are passed to it.
@Angelelz
Copy link
Collaborator Author

This PR should also fix #362

@shellking4
Copy link

This PR should also fix #362

Guess what, it didn't fix it. Still getting the error in latest version 0.30.1

@danielsharvey
Copy link
Contributor

It would be good to see this merged.

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.

Don't allow unknown keys in .insert().values()
3 participants