pal schema
Alias: pal s
> pal schema CONVERTER
CONVERTER | description |
---|---|
json | Convert your schema.prisma file into JavaScript , TypeScript and Json files |
camel-case | Convert your schema.prisma file from Snake case eg first_name to Camel case eg firstName |
typescript | Convert your schema.prisma file into TypeScript definitions |
CONTENT
Convert to file
Convert your schema.prisma
file into JavaScript
, TypeScript
and Json
files.
options
char | flag | description |
---|---|---|
-h | --help | show CLI help |
-o | --output-path=output-path | [default: prisma/] folder path for converted file |
-t | --type=(js|ts|json) | [default: ts] type of output file type when you convert to json |
-v | --version | show CLI version |
Run
pal schema json
Example
model User {
id Int @default(autoincrement()) @id
createdAt DateTime @default(now())
email String @unique
name String?
password String
// field comment
posts Post[]
group Group? @relation(fields: [groupId], references: [id])
groupId Int?
// field comment
comments Comment[]
// some model comments
// another model comments
}
Convert to Camel case
Most of use after using Prisma Introspection
.
Convert your schema.prisma
file from Snake case
to Camel case
.
options
char | flag | description |
---|---|---|
-s | --schema=schema | [default: prisma/schema.prisma] Add your schema.prisma file path |
Run
pal schema camel-case
Example
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @default(autoincrement()) @id
created_at DateTime @default(now())
email String @unique
first_name String?
password String
// @onDelete(CASCADE)
posts Post[]
group Group? @relation(fields: [group_id], references: [id])
group_id Int?
// @onDelete(SET_NULL)
comments post_comment[]
}
model Post {
id Int @default(autoincrement()) @id
published Boolean @default(false)
title String
author User? @relation(fields: [author_id], references: [id])
author_id Int?
// @onDelete(CASCADE)
comments post_comment[]
created_at DateTime @default(now())
updated_at DateTime @updatedAt
}
model post_comment {
id Int @default(autoincrement()) @id
contain String
post Post @relation(fields: [post_id], references: [id])
post_id Int
author User? @relation(fields: [author_id], references: [id])
author_id Int?
created_at DateTime @default(now())
updated_at DateTime @updatedAt
}
model Group {
id Int @default(autoincrement()) @id
name String
created_at DateTime @default(now())
updated_at DateTime @updatedAt
// @onDelete(SET_NULL)
users User[]
}
Convert to TypeScript definitions
Convert your schema.prisma
file into TypeScript
definitions.
options
char | flag | description |
---|---|---|
-s | --schema=schema | [default: prisma/schema.prisma] Add your schema.prisma file path |
-o | --output-path=output-path | [default: src/] folder path for converted file |
Run
pal schema typescript
Example
// schema.prisma
datasource postgresql {
url = env("DATABASE_URL")
provider = "postgresql"
}
generator client {
provider = "prisma-client-js"
}
model User {
id String @id @default(cuid())
email String @unique
birthDate DateTime?
role UserRole
posts Post[]
}
model Post {
id String @id @default(cuid())
author User[]
}
enum UserRole {
USER
ADMIN
}
OutPut
// schema.ts
export interface User {
id: string;
email: string;
birthDate: Date | null;
role: UserRole;
posts: Post[];
}
export interface Post {
id: string;
author: User[];
}
enum UserRole {
USER = 'USER',
ADMIN = 'ADMIN',
}
Schema Type
You can import this types from our tool
import { SchemaObject, Model, Enums, Field } from '@paljs/schema';
export interface Model {
name: string;
documentation?: string;
map?: string;
fields: Field[];
}
export interface Enums {
name: string;
fields: string[];
}
export interface Field {
name: string;
type: string;
list: boolean;
required: boolean;
isId: boolean;
unique: boolean;
kind: 'object' | 'enum' | 'scalar';
map?: string;
relationField?: boolean;
documentation?: string;
relation?: { name?: string; fields?: string[]; references?: string[] };
}
export type SchemaObject = { models: Model[]; enums: Enums[] };