为什么我可以使用'@@' prisma mysql全文搜索中的符号?

发布于 2025-01-23 00:16:21 字数 1418 浏览 0 评论 0原文

我已经与Prisma客户端一起编写了一个简单的文本搜索查询,以在我的用户表中搜索用户名或电子邮件。虽然它正确地与用户名一起使用,但错误地说,意外' @'。我相信这是 @是一个特殊的符号。电子邮件地址。 (电子邮件正确保存在数据库中)。如果我从 @.ex省略零件,请结果结果结果:in ,查询返回匹配匹配如果我只是搜索abc..tut,如果我使用  part  protect ] ,由于此错误而失败。

 Error occurred during query execution:
 ConnectorError(
  ConnectorError { 
   user_facing_error: None, 
   kind: QueryError(Server(ServerError { 
                           code: 1064, message: "syntax error, 
                           unexpected '@',expecting $end", state: "42000" }
)) })

我如何解决这个问题,我搜索了文档,但是找不到与此相关的任何内容。 我的用户模型看起来像

model User {
  id              Int     @id @default(autoincrement())
  username        String  @db.VarChar(255)
  email           String  @db.VarChar(255)
  avatar          String? @db.VarChar(255)
  password        String  @default("1") @db.VarChar(255)
  friends         User[]  @relation("friends")
  friendsRelation User[]  @relation("friends")
  hashRT          String? @db.VarChar(255)

  @@fulltext([username])
  @@fulltext([email])
  @@fulltext([username, email])
  @@map("users")
}

I've written a simple text search query with the Prisma client to search Usernames or emails in my users table. While it correctly works with usernames, it errors out saying, Unexpected '@'.I believe that's due to @ is a special symbol.Is there anyway around this, because I need to be able to search full email addresses. (Emails are correctly saved in the database). And query return results if I omit the part from @.Ex: in [email protected], query returns match if I just search abc.But If I use [email protected], it fails with this error.

 Error occurred during query execution:
 ConnectorError(
  ConnectorError { 
   user_facing_error: None, 
   kind: QueryError(Server(ServerError { 
                           code: 1064, message: "syntax error, 
                           unexpected '@',expecting $end", state: "42000" }
)) })

How do I solve this, I searched the documentation, but I couldn't find anything related to this.
My User model looks like this,

model User {
  id              Int     @id @default(autoincrement())
  username        String  @db.VarChar(255)
  email           String  @db.VarChar(255)
  avatar          String? @db.VarChar(255)
  password        String  @default("1") @db.VarChar(255)
  friends         User[]  @relation("friends")
  friendsRelation User[]  @relation("friends")
  hashRT          String? @db.VarChar(255)

  @@fulltext([username])
  @@fulltext([email])
  @@fulltext([username, email])
  @@map("users")
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆里有你的影子 2025-01-30 00:16:21

这是一个较晚的答案,但是如果您仍然遇到相同的错误,这可能会帮助我通过用这样的包含替换搜索来解决此错误

prisma.user.findMany({where:{email:{contains:"[email protected]"}}})

this is a late answer but if you still had the same error this might help I fixed this error by replacing search with contains like this

prisma.user.findMany({where:{email:{contains:"[email protected]"}}})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文