还有其他方法可以用prisma-client-go生成客户端吗?

f45qwnt8  于 2023-05-27  发布在  Go
关注(0)|答案(1)|浏览(168)

我在go中建立了一个项目,我想使用prisma-client-go作为ORM工具。我已经安装了schema.prisma文件如下

datasource db {
    // could be postgresql or mysql
    provider = "sqlite"
    url      = "file:dev.db"
}

generator db {
    provider = "go run github.com/prisma/prisma-client-go"
    // set the output folder and package name
    output           = "./db"
    package          = "db"
}

model Post {
    id        String   @default(cuid()) @id
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
    title     String
    published Boolean
    desc      String?
}

从github文档中,我必须运行generate命令,但当我运行这个

go run github.com/prisma/prisma-client-go migrate dev --name init

仅输出迁移目录。没有生成的客户端文件夹,因此我无法使用上述模式...有什么能告诉我哪里错了吗?我已经创建了一个全新的项目,以及只是为了双重检查,但我得到了相同的行为

tjvv9vkg

tjvv9vkg1#

该命令会自动将客户端生成到./db文件夹中,在本例中也是如此,但它与默认值相同。

❯ go run github.com/prisma/prisma-client-go migrate dev --name init
Prisma schema loaded from schema.prisma
Datasource "db": SQLite database "dev.db" at "file:dev.db"

SQLite database dev.db created at file:dev.db

Applying migration `20230526010255_init`

The following migration(s) have been created and applied from new schema changes:

migrations/
  └─ 20230526010255_init/
    └─ migration.sql

Your database is now in sync with your schema.

✔ Generated Prisma Client Go to ./db in 909ms

要重新生成客户端库,您可以始终运行generate

go run github.com/prisma/prisma-client-go generate

相关问题