npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lexmata/prisma-ent-generator

v0.2.2

Published

Prisma generator that produces Go Ent schema files from your Prisma schema

Readme

prisma-ent-generator

A Prisma generator that produces a complete Go Ent installation from your Prisma schema.

Define your data model once in Prisma and generate fully working Ent schemas — including fields, edges, enums, and the generate.go / entc.go scaffolding needed to run go generate.

Features

  • Full Ent install — generates generate.go, entc.go, and schema/*.go so you can immediately run go generate ./ent
  • Environment variable toggle — controlled by GENERATE_ENT; skips when unset or false, runs when set to true
  • Scalar type mappingString, Int, BigInt, Float, Decimal, Boolean, DateTime, Json, Bytes
  • Enum support — Prisma enums map to inline field.Enum(...).Values(...) with defaults
  • Relationship edges — O2O, O2M, and M2M relations are translated to edge.To / edge.From with correct ownership, .Ref(), .Unique(), and .Required()
  • FK edge fields — foreign key scalars are included in Fields() and bound to edges via .Field()
  • Defaults@default(now()), @default(uuid()), @default(autoincrement()), @default(false), @default(0), @default("value"), and enum defaults
  • @updatedAt — maps to .Default(time.Now).UpdateDefault(time.Now)
  • UUID IDs@id @default(uuid()) generates field.UUID("id", uuid.UUID{}).Default(uuid.New)
  • Optional / Nillable — optional fields get .Optional().Nillable() (except JSON, which only gets .Optional())

Installation

npm install @lexmata/prisma-ent-generator
# or
pnpm add @lexmata/prisma-ent-generator

Usage

1. Add the generator to your Prisma schema

generator ent {
  provider = "@lexmata/prisma-ent-generator"
  output   = "./ent"
}

2. Run Prisma generate with the environment variable

GENERATE_ENT=true npx prisma generate

Without GENERATE_ENT=true, the generator prints a skip message and produces no output:

prisma-ent-generator: Skipping — set GENERATE_ENT=true to enable.

3. Run Ent code generation

cd your-go-project
go generate ./ent

This triggers Ent's own pipeline via the generated generate.go, producing the full client, queries, mutations, migrations, and predicates.

Output Structure

ent/
├── generate.go          # go:generate directive for Ent codegen
├── entc.go              # Ent codegen configuration (build-tag guarded)
└── schema/
    ├── user.go           # One file per Prisma model
    ├── post.go
    ├── profile.go
    └── tag.go

generate.go and entc.go are only written if they don't already exist, so your customizations are preserved across re-runs. Schema files are always overwritten.

Example

Given this Prisma schema:

enum Role {
  USER
  ADMIN
  MODERATOR
}

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  role      Role     @default(USER)
  posts     Post[]
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  author   User   @relation(fields: [authorId], references: [id])
  authorId Int
  tags     Tag[]
}

model Tag {
  id    Int    @id @default(autoincrement())
  name  String @unique
  posts Post[]
}

The generator produces:

ent/schema/user.go

package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/edge"

	"time"
)

type User struct {
	ent.Schema
}

func (User) Fields() []ent.Field {
	return []ent.Field{
		field.String("email").Unique(),
		field.String("name").Optional().Nillable(),
		field.Enum("role").Values("USER", "ADMIN", "MODERATOR").Default("USER"),
		field.Time("created_at").Default(time.Now),
		field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
	}
}

func (User) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("posts", Post.Type),
	}
}

ent/schema/post.go

package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/edge"
)

type Post struct {
	ent.Schema
}

func (Post) Fields() []ent.Field {
	return []ent.Field{
		field.String("title"),
		field.Int("author_id"),
	}
}

func (Post) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("author", User.Type).Ref("posts").Unique().Field("author_id").Required(),
		edge.To("tags", Tag.Type),
	}
}

Type Mapping

| Prisma Type | Ent Field | Notes | |---|---|---| | String | field.String | | | Boolean | field.Bool | | | Int | field.Int | | | BigInt | field.Int | int64 in Go | | Float | field.Float | | | Decimal | field.Float | float64 in Go | | DateTime | field.Time | Imports "time" | | Json | field.JSON | Second arg: map[string]interface{}{} | | Bytes | field.Bytes | | | Enums | field.Enum | Inline .Values(...) |

Edge Mapping

| Prisma Relation | Ent Edge | |---|---| | O2O (owner side) | edge.To("name", Type.Type).Unique() | | O2O (FK side) | edge.From("name", Type.Type).Ref("...").Unique().Field("fk") | | O2M (owner side) | edge.To("name", Type.Type) | | O2M (FK side) | edge.From("name", Type.Type).Ref("...").Unique().Field("fk") | | M2M (owner side) | edge.To("name", Type.Type) | | M2M (inverse side) | edge.From("name", Type.Type).Ref("...") |

M2M ownership is determined alphabetically by model name when neither side holds a FK.

Development

pnpm install
pnpm build
pnpm test

To test generation locally:

pnpm build
GENERATE_ENT=true npx prisma generate --schema=prisma/schema.prisma

License

MIT - Lexmata LLC