quan2796
quan2796
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
Thanks again @Andrew Sherman
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
I dunno how it worked but it did
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
let me try a different IDE
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
Thanks for looking into it @Andrew Sherman
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
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
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
I am using monorepo but I only have drizzle-orm only in 1 package.json
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
I believe that should be everything
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
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;
},
});
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;
},
});
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
table.ts
import { mysqlTable } from "drizzle-orm/mysql-core";

export const table = mysqlTable;
import { mysqlTable } from "drizzle-orm/mysql-core";

export const table = mysqlTable;
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
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">;
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">;
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
version: "drizzle-orm": "^0.23.13"
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
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));
};
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));
};
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
^ this is the db.ts file
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
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);
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);
37 replies
DTDrizzle Team
Created by quan2796 on 5/8/2023 in #help
Typescript error that doesn't make a whole lot of sense when calling db.select or db.insert
37 replies