lutefd
lutefd
DTDrizzle Team
Created by lutefd on 1/20/2024 in #help
Next auth with extended columns not able to create a user
It seems to be a next-auth issue, when i create the user via credentials it works fine, even when not specified it uses the default and create the user with the values expected, but when the user is created via their sso providers it breaks trying to insert null
5 replies
DTDrizzle Team
Created by lutefd on 1/20/2024 in #help
Next auth with extended columns not able to create a user
I've tried like this as well but no success
export const users = pgTable('user', {
id: text('id')
.$default(() => cuid2.createId())
.notNull()
.primaryKey(),
name: text('name'),
email: text('email').notNull(),
emailVerified: timestamp('emailVerified', { mode: 'date' }),
password: text('password'),
image: text('image'),
role: RoleEnum('role')
.$default(() => sql`'USER'`)
.notNull(),
status: UserStatusEnum('status')
.$default(() => sql`'ACTIVE'`)
.notNull(),
});
export const users = pgTable('user', {
id: text('id')
.$default(() => cuid2.createId())
.notNull()
.primaryKey(),
name: text('name'),
email: text('email').notNull(),
emailVerified: timestamp('emailVerified', { mode: 'date' }),
password: text('password'),
image: text('image'),
role: RoleEnum('role')
.$default(() => sql`'USER'`)
.notNull(),
status: UserStatusEnum('status')
.$default(() => sql`'ACTIVE'`)
.notNull(),
});
5 replies
DTDrizzle Team
Created by lutefd on 1/20/2024 in #help
Next auth with extended columns not able to create a user
I put in the not null constraint because if it doesn't have it there for some reason it overides the default and inserts as null
5 replies
DTDrizzle Team
Created by lutefd on 1/20/2024 in #help
Next auth with extended columns not able to create a user
When i create them manually through drizzle studio it works fine
5 replies
DTDrizzle Team
Created by lutefd on 1/10/2024 in #help
Reusing db connection in lambda with Drizzle
Also tried something more like this sst guide but no luck again Guide: https://sst.dev/examples/how-to-use-mongodb-atlas-in-your-serverless-app.html Code for the config:
import { type MySql2Database, drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import { env } from "@/env";
import * as myschema from "./schema";

let cachedDbPromise: MySql2Database<typeof myschema> | null = null;

async function connectToDatabase() {
if (cachedDbPromise) {
return cachedDbPromise;
}
const connection = await mysql.createConnection({
host: env.MYSQL_HOST,
user: env.MYSQL_USER,
port: 3306,
password: env.MYSQL_PASSWORD,
database: env.MYSQL_DATABASE,
});
cachedDbPromise = drizzle(connection, {
schema: myschema,
mode: "default",
});
return cachedDbPromise;
}

export const dbPromise = connectToDatabase();
import { type MySql2Database, drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import { env } from "@/env";
import * as myschema from "./schema";

let cachedDbPromise: MySql2Database<typeof myschema> | null = null;

async function connectToDatabase() {
if (cachedDbPromise) {
return cachedDbPromise;
}
const connection = await mysql.createConnection({
host: env.MYSQL_HOST,
user: env.MYSQL_USER,
port: 3306,
password: env.MYSQL_PASSWORD,
database: env.MYSQL_DATABASE,
});
cachedDbPromise = drizzle(connection, {
schema: myschema,
mode: "default",
});
return cachedDbPromise;
}

export const dbPromise = connectToDatabase();
3 replies
DTDrizzle Team
Created by lutefd on 1/10/2024 in #help
Reusing db connection in lambda with Drizzle
I've tried something closer to their example modifying the config like this:
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

import { env } from "@/env";
import * as myschema from "./schema";

const connectionPromise = mysql.createConnection({
host: env.MYSQL_HOST,
user: env.MYSQL_USER,
port: 3306,
password: env.MYSQL_PASSWORD,
database: env.MYSQL_DATABASE,
});
export const dbPromise = connectionPromise.then((connection) => {
return drizzle(connection, {
schema: myschema,
mode: "default",
});
});
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

import { env } from "@/env";
import * as myschema from "./schema";

const connectionPromise = mysql.createConnection({
host: env.MYSQL_HOST,
user: env.MYSQL_USER,
port: 3306,
password: env.MYSQL_PASSWORD,
database: env.MYSQL_DATABASE,
});
export const dbPromise = connectionPromise.then((connection) => {
return drizzle(connection, {
schema: myschema,
mode: "default",
});
});
And the action like this:
"use server";
import { dbPromise } from "@/server/db";

export const getPosts = async () => {
const db = await dbPromise;
const posts = await db.query.posts.findMany();
return posts;
};
"use server";
import { dbPromise } from "@/server/db";

export const getPosts = async () => {
const db = await dbPromise;
const posts = await db.query.posts.findMany();
return posts;
};
But had no success with the db connection limit still being reached
3 replies