-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug?]: export class
crashes in 'use server' module
#1689
Labels
bug
Something isn't working
Comments
To complete the issue. This will work "use server";
import { eq } from "drizzle-orm";
import { db } from "~/db/client";
import { users } from "~/db/schema";
import type { InsertUser } from "./user.entity";
import type { UserRepositoryInterface } from "./user.interface";
export class UserRepository implements UserRepositoryInterface {
async create(values: InsertUser) {
const [row] = await db.insert(users).values(values).returning();
return row;
}
async findAll() {
return db.select().from(users);
}
async findById(id: string) {
const row = await db.select().from(users).where(eq(users.id, id));
return row.length > 0 ? row[0] : null;
}
async findByEmail(email: string) {
const row = await db.select().from(users).where(eq(users.email, email));
return row.length > 0 ? row[0] : null;
}
async update(id: string, values: Partial<InsertUser>) {
const [row] = await db
.update(users)
.set(values)
.where(eq(users.id, id))
.returning();
return row;
}
async delete(id: string) {
await db.delete(users).where(eq(users.id, id));
}
} This will work import { eq } from "drizzle-orm";
import { db } from "~/db/client";
import { users } from "~/db/schema";
import type { InsertUser } from "./user.entity";
import type { UserRepositoryInterface } from "./user.interface";
export class UserRepository implements UserRepositoryInterface {
async create(values: InsertUser) {
"use server";
const [row] = await db.insert(users).values(values).returning();
return row;
}
async findAll() {
"use server";
return db.select().from(users);
}
async findById(id: string) {
"use server";
const row = await db.select().from(users).where(eq(users.id, id));
return row.length > 0 ? row[0] : null;
}
async findByEmail(email: string) {
"use server";
const row = await db.select().from(users).where(eq(users.email, email));
return row.length > 0 ? row[0] : null;
}
async update(id: string, values: Partial<InsertUser>) {
"use server";
const [row] = await db
.update(users)
.set(values)
.where(eq(users.id, id))
.returning();
return row;
}
async delete(id: string) {
"use server";
await db.delete(users).where(eq(users.id, id));
}
} I don't know if this is expected or not 🤷♂️ |
Following a discussion with ryan on discord, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Duplicates
Latest version
Current behavior 😯
Expected behavior 🤔
No response
Steps to reproduce 🕹
If I refactor and split my class
AuthService
in functions, I don't get an error.Context 🔦
Most probably linked to #1226
Your environment 🌎
No response
The text was updated successfully, but these errors were encountered: