ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Teamโ€ข3y agoโ€ข
6 replies
Frosty

insert with InferModel not working

Hey, playing with Drizzle, like it a lot but I am having an issue where I inferred the model of a schema as
type NewUser = InferModel<typeof Users, "insert">;
type NewUser = InferModel<typeof Users, "insert">;
and try to insert. It doesn't give an error, simply does nothing. In my app I have it do many different selects so I know the schema is fine and everything is connected and working. Yet when I execute this insert nothing is added to the db.

import { InferModel } from "drizzle-orm";

type NewUser = InferModel<typeof Users, "insert">;
 
const insertUser = async (userNew: NewUser) => {
    return db.insert(Users).values(userNew)
}

async function main() {
    let userNew : NewUser = {
        email: "xxx@xxx.net",
        password: "xxx",
        token: "xxx"
    };
    console.log(userNew);

    await insertUser(userNew);
}

main();
import { InferModel } from "drizzle-orm";

type NewUser = InferModel<typeof Users, "insert">;
 
const insertUser = async (userNew: NewUser) => {
    return db.insert(Users).values(userNew)
}

async function main() {
    let userNew : NewUser = {
        email: "xxx@xxx.net",
        password: "xxx",
        token: "xxx"
    };
    console.log(userNew);

    await insertUser(userNew);
}

main();


Here is the table schema (sqlite):
export const Users = sqliteTable("users", {
    id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
    email: text("email").notNull(),
    password: text("password").notNull(),
    token: text("token"),
    createdAt: integer("createdAt", { mode: "timestamp" }).notNull().defaultNow(),
    updatedAt: integer("updatedAt", { mode: "timestamp" }).notNull().defaultNow(),
})
export const Users = sqliteTable("users", {
    id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
    email: text("email").notNull(),
    password: text("password").notNull(),
    token: text("token"),
    createdAt: integer("createdAt", { mode: "timestamp" }).notNull().defaultNow(),
    updatedAt: integer("updatedAt", { mode: "timestamp" }).notNull().defaultNow(),
})
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Nested insert not working
Drizzle TeamDTDrizzle Team / help
2y ago
InferModel including relations?
Drizzle TeamDTDrizzle Team / help
3y ago
Insert into sqlite3 with better-sqlite3 not working
Drizzle TeamDTDrizzle Team / help
3y ago
Insert returning: partial return not working
Drizzle TeamDTDrizzle Team / help
2y ago