Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert

Qquan5/8/2023
This is my account model
export const accounts = mysqlTable("accounts", {
    id: nanoid("id", {}).primaryKey(),
    userId: varchar("userId", { length: 25 }),
    displayName: text("displayName"),
    metadata: json("metadata"),
    externalId: varchar("externalId", { length: 25 }),
    createdAt: timestamp("createdAt").defaultNow().notNull(),
    updatedAt: timestamp("updatedAt"),
});

This issue happens to both my db.insert and db.select requests. Any guidance would be much appreciated.
ASAndrii Sherman5/8/2023
eq() should get column as first param
ASAndrii Sherman5/8/2023
And value for it as second
Qquan5/8/2023
Thanks for that @Andrew Sherman , the original issue with accounts didn't go away unfortunately
ASAndrii Sherman5/8/2023
Can you please show part where you create db from drizzle()
ASAndrii Sherman5/8/2023
And where did you import drizzle from
Qquan5/8/2023
import { Config } from "sst/node/config";

import { connect } from "@planetscale/database";
import { drizzle } from "drizzle-orm/planetscale-serverless";

export const connection = connect({
    host: Config.PLANETSCALE_HOST,
    username: Config.PLANETSCALE_USERNAME,
    password: Config.PLANETSCALE_PASSWORD,
});
export const db = drizzle(connection);
Qquan5/8/2023
^ this is the db.ts file
Qquan5/8/2023
Then in my accounts file I have
import { accounts, NewAccount } from "@models/account";
import { db } from "@connectors/db";
import { eq } from "drizzle-orm";

export const createAccount = async (newAccount: NewAccount) => {
    await db.insert(accounts).values(newAccount);
};

export const getAccountByExternalId = async (externalId: string) => {
    return db.select({
        id: accounts.id,
    }).from(accounts).where(eq(accounts.externalId, externalId));
};
Qquan5/8/2023
version: "drizzle-orm": "^0.23.13"
ASAndrii Sherman5/8/2023
let me test it locally
ASAndrii Sherman5/8/2023
so It works for me
ASAndrii Sherman5/8/2023
could you please send your table schema + imports for it and nanoId implementation?
ASAndrii Sherman5/8/2023
maybe something wrong there
ASAndrii Sherman5/8/2023
because everything else was taken from you example
Qquan5/8/2023
accounts.ts
import { json, text, varchar } from "drizzle-orm/mysql-core";
import { InferModel } from "drizzle-orm";
import { nanoid } from "./utils";

import { timestamp } from "drizzle-orm/mysql-core";
import { table } from "./table";
export const accounts = table("accounts", {
    id: nanoid("id", {}).primaryKey(),
    userId: varchar("userId", { length: 32 }).notNull(),
    displayName: text("displayName").notNull(),
    metadata: json("metadata"),
    externalId: varchar("externalId", { length: 36 }),
    createdAt: timestamp("createdAt").defaultNow().notNull(),
    updatedAt: timestamp("updatedAt"),
});

export type Account = InferModel<typeof accounts>;
export type NewAccount = InferModel<typeof accounts, "insert">;
Qquan5/8/2023
table.ts
import { mysqlTable } from "drizzle-orm/mysql-core";

export const table = mysqlTable;
Qquan5/8/2023
nanoid
import { customType } from "drizzle-orm/mysql-core";
import { nanoid as nanoidLib } from "nanoid";

export const nanoid = customType<{
    data: string;
    notNull: true;
    default: true;
}>({
    dataType() {
        return "varchar(20)";
    },
    toDriver(value): string {
        return typeof value === "undefined" ? nanoidLib() : value;
    },
});
Qquan5/8/2023
I believe that should be everything
ASAndrii Sherman5/8/2023
yes
ASAndrii Sherman5/8/2023
thanks
ASAndrii Sherman5/8/2023
still works
ASAndrii Sherman5/8/2023
another question
ASAndrii Sherman5/8/2023
do you have 1 drizzle-orm installed?
ASAndrii Sherman5/8/2023
or are you using monorepo and having several drizzle-orm instances?
Qquan5/8/2023
I am using monorepo but I only have drizzle-orm only in 1 package.json
Qquan5/8/2023
whelp, other than it looking ugly in my IDE it's not preventing my code from executing so it's fine for now I guess
Qquan5/8/2023
Thanks for looking into it @Andrew Sherman
ASAndrii Sherman5/8/2023
it shouldn't be this way
Qquan5/8/2023
let me try a different IDE
ASAndrii Sherman5/8/2023
I guess you can try installing drizzle-orm globally in monorepo to check if it will work
ASAndrii Sherman5/8/2023
but if you have only 1 drizzle-orm installed - no errors should be displayed
Qquan5/8/2023
Very intersting, doesn't happen on Vscode
Qquan5/8/2023
Oh damn, I restarted my webstorm IDE and now the error is also gone.
Qquan5/8/2023
I dunno how it worked but it did
Qquan5/8/2023
Thanks again @Andrew Sherman
ASAndrii Sherman5/8/2023
🫡