Insert silently fails with missing table name?

Hi everyone! I've been using Drizzle the past few days and so far it's been a breeze. However, I've ran into an issue today that I cannot seem to figure out. I have a schema file that contains table definitions, like:
export const clients = pgTable("clients", {
id: text("id").primaryKey().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
company: text("company").notNull().unique(),
// The rest of the columns
});

export type Client = typeof clients.$inferSelect;
export type NewClient = typeof clients.$inferInsert;

export const accounts = pgTable("accounts", {
id: text("id").primaryKey().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
email: text("email").unique().notNull(),
// The rest of the columns
});
export const clients = pgTable("clients", {
id: text("id").primaryKey().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
company: text("company").notNull().unique(),
// The rest of the columns
});

export type Client = typeof clients.$inferSelect;
export type NewClient = typeof clients.$inferInsert;

export const accounts = pgTable("accounts", {
id: text("id").primaryKey().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
email: text("email").unique().notNull(),
// The rest of the columns
});
I am using RDS Data API with Drizzle. Created a repository service class for Clients and Accounts as well. I have the necessary functions such as getters, inserts, etc. For example, this is how a new client is inserted into the database:
public async insertClient(client: NewClient) {
if (!this.repository) {
await this.createRepositoryAccess(); // Ensure that drizzle() is called already
}

return this.repository
.insert(clients)
.values(client)
.returning({
id: clients.id,
createdAt: clients.createdAt,
});
}
public async insertClient(client: NewClient) {
if (!this.repository) {
await this.createRepositoryAccess(); // Ensure that drizzle() is called already
}

return this.repository
.insert(clients)
.values(client)
.returning({
id: clients.id,
createdAt: clients.createdAt,
});
}
This works perfectly, the client is inserted, all good. When I try to do the exact same thing with the "accounts" table however, the insert fails silently with 0 logs, 0 errors (callers are wrapped with try/catch), and as return value, I just get an empty object. The "accounts" insert method:
public async createNewAccount(accountData: NewAccount) {
if (!this.repository) {
await this.createRepositoryAccess();
}

return this.repository
.insert(accounts)
.values(accountData)
.returning({
id: accounts.id,
createdAt: accounts.createdAt,
});
}
public async createNewAccount(accountData: NewAccount) {
if (!this.repository) {
await this.createRepositoryAccess();
}

return this.repository
.insert(accounts)
.values(accountData)
.returning({
id: accounts.id,
createdAt: accounts.createdAt,
});
}
Anyone has ever seen something like this?
1 Reply
Lostra
Lostra8mo ago
I used the getSQL() function on the whole insert thing, and logged it. At the start I can see the insert into section, and below that all of the table's columns (so it's picking up the schema) but in the rest of the object, there's not a single instance of accounts anywhere to be seen, and around the bottom I have a value: { " " } right before the actual insert values for the columns.
Want results from more Discord servers?
Add your server