Skip to content

Instantly share code, notes, and snippets.

@joshnuss
Last active April 12, 2023 09:46
Show Gist options
  • Save joshnuss/a00355b3a290142f34c120d7d5a38866 to your computer and use it in GitHub Desktop.
Save joshnuss/a00355b3a290142f34c120d7d5a38866 to your computer and use it in GitHub Desktop.
Prisma snippets

Prisma Snippets

For ViM and VSCode.

Commands

  • model<tab>: defines a model
  • field<tab>: defines a field
  • index<tab>: defines an index
  • unique<tab>: defines a unique index
  • belongs<tab>: defines a "belongs to" relationship
  • many<tab>: defines a "has many" relationship
  • enum<tab>: defines an enum

Converted to VS Code using convert-snippets

/*
Prisma snippets for VS Code
To Install:
1. Open command palette: CMD+Shift+P
2. Choose "Configure User Snippets"
3. Choose "Prisma" (prisma.json)
4. Copy and paste this file
*/
{
"model": {
"prefix": "model",
"body": "model ${1:Name} {\n\tid Int @id @default(autoincrement())\n\t${2}\n\n\tcreatedAt DateTime @default(now())\n\tupdatedAt DateTime @updatedAt\n}",
"description": "define a model"
},
"enum": {
"prefix": "enum",
"body": "enum ${1:Name} {\n\t${2:VALUE}\n}",
"description": "define an enum"
},
"field": {
"prefix": "field",
"body": "${1:name} ${2:String}",
"description": "define a field"
},
"many": {
"prefix": "many",
"body": "${1:authors} ${2:Author}[]",
"description": "define a has many relationship"
},
"belongs": {
"prefix": "belongs",
"body": "${1:author} ${2:Author} @relation(fields: [$1Id], references: [id])\n$1Id Int",
"description": "define a belongs to relationship"
},
"index": {
"prefix": "index",
"body": "@@index([${1:field}])",
"description": "define an index"
},
"unique": {
"prefix": "unique",
"body": "@@unique([${1:field}])",
"description": "define a unique index"
}
}
# Prisma snippets for VIM
#
# To install:
# Copy this file to ~/.vim/snippets/prisma.snippets
snippet model "define a model"
model ${1:Name} {
id Int @id @default(autoincrement())
${2}
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
endsnippet
snippet enum "define an enum"
enum ${1:Name} {
${2:VALUE}
}
endsnippet
snippet field "define a field"
${1:name} ${2:String}
endsnippet
snippet many "define a has many relationship"
${1:authors} ${2:Author}[]
endsnippet
snippet belongs "define a belongs to relationship"
${1:author} ${2:Author} @relation(fields: [$1Id], references: [id])
$1Id Int
endsnippet
snippet index "define an index"
@@index([${1:field}])
endsnippet
snippet unique "define a unique index"
@@unique([${1:field}])
endsnippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment