utybo / Tegral

🟣 A Kotlin framework for web applications, cool libraries that go along with it!
https://tegral.zoroark.guru
Apache License 2.0
37 stars 3 forks source link

Tegral PrismaKT: Prisma integration with JetBrains Exposed #81

Open utybo opened 1 year ago

utybo commented 1 year ago

Hi to whoever will read this, long time no see! I'm back and am finally able to reveal some stuff I've been working on in the past months.

Tegral PrismaKT

Tegral PrismaKT is a module that generates JetBrains Exposed DAOs and table definitions from your Prisma schema.

In short, automatically get from this:

generator prismakt {
  provider      = "gradle --console=plain -q runGeneratorInternal"
  output        = "../build/prismaGeneratedSrc"
  exposedTarget = "sql" // or dao
}

datasource db {
  provider = "postgresql"
  url      = "file:./dev.db"
}

model User {
  identifier Int     @id @default(autoincrement())
  email      String  @unique
  name       String?
}

To this:

public object UserTable : IdTable<Int>() {
  public val email: Column<String> = text(name = "email")

  public val name: Column<String?> = text(name = "name").nullable()

  public val identifier: Column<EntityID<Int>> = integer(name = "identifier").entityId()

  public override val id: Column<EntityID<Int>>
    get() = identifier
}

public class UserEntity(
  id: EntityID<Int>,
) : Entity<Int>(id) {
  public var email: String by UserTable.email

  public var name: String? by UserTable.name

  public companion object : EntityClass<Int, UserEntity>(UserTable)
}

It integrates into Prisma's existing "generator" concept and generates classes via Prisma's datamodel (DMMF). For more information, check Prisma's article here. Massive thanks to the work done by YassinEldeeb on create-prisma-generator that allowed me to get good documentation on how to do things :)

Status

This will be a "long-life" issue which tracks the progress on PrismaKT. Due to the high complexity of what Prisma can handle, there will be a fairly long period spent debugging things PrismaKT gets totally wrong.

Expected initial release for 0.0.4 along with Tegral Niwen (which is required for this issue)

Initial release: 0.0.4 (planned)

Next release: 0.0.5

For alpha release

For beta release

For stable release