Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
make grpc work
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyendu Singh committed Jun 18, 2019
1 parent efc2cd1 commit ebcae8e
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,4 +1,6 @@
node_modules
.DS_Store

dist/
*.db

dist/
3 changes: 2 additions & 1 deletion examples/javascript/grpc/package.json
Expand Up @@ -8,6 +8,7 @@
},
"scripts": {
"start": "node ./server/server.js",
"seed": "node prisma/seed.js",
"feed": "node ./client/feed.js",
"filterPosts": "node ./client/filterPosts.js",
"post": "node ./client/post.js",
Expand All @@ -17,6 +18,6 @@
"deletePost": "node ./client/deletePost.js"
},
"devDependencies": {
"prisma2": "^0.0.57"
"prisma2": "^0.0.79"
}
}
@@ -0,0 +1,68 @@
# Migration `20190618162719`

This migration has been generated by Divyendu Singh at 6/18/2019, 4:27:19 PM.
You can check out the [state of the datamodel](./datamodel.prisma) after the migration.

## Database Steps

```sql
CREATE TABLE "file:dev"."User"("id" TEXT NOT NULL ,"email" TEXT NOT NULL DEFAULT '' ,"name" TEXT ,PRIMARY KEY ("id"));

CREATE TABLE "file:dev"."Post"("id" TEXT NOT NULL ,"createdAt" DATE NOT NULL ,"updatedAt" DATE NOT NULL DEFAULT '1970-01-01 00:00:00' ,"published" BOOLEAN NOT NULL DEFAULT false ,"title" TEXT NOT NULL DEFAULT '' ,"content" TEXT ,"author" TEXT REFERENCES User(id),PRIMARY KEY ("id"));
```

## Changes

```diff
diff --git datamodel.mdl datamodel.mdl
migration ..20190618162719
--- datamodel.dml
+++ datamodel.dml
@@ -1,0 +1,27 @@
+datasource db {
+ provider = "sqlite"
+ url = "file:dev.db"
+ default = true
+}
+
+generator photon {
+ provider = "photonjs"
+ output = "../node_modules/@generated/photon"
+}
+
+model User {
+ id String @default(cuid()) @id @unique
+ email String @unique
+ name String?
+ posts Post[]
+}
+
+model Post {
+ id String @default(cuid()) @id @unique
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ published Boolean
+ title String
+ content String?
+ author User?
+}
```

## Photon Usage

You can use a specific Photon built for this migration (20190618162719)
in your `before` or `after` migration script like this:

```ts
import Photon from '@generated/photon/20190618162719'

const photon = new Photon()

async function main() {
const result = await photon.users()
console.dir(result, { depth: null })
}

main()

```
@@ -0,0 +1,27 @@
datasource db {
provider = "sqlite"
url = "file:dev.db"
default = true
}

generator photon {
provider = "photonjs"
output = "../node_modules/@generated/photon"
}

model User {
id String @default(cuid()) @id @unique
email String @unique
name String?
posts Post[]
}

model Post {
id String @default(cuid()) @id @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
published Boolean
title String
content String?
author User?
}
166 changes: 166 additions & 0 deletions examples/javascript/grpc/prisma/migrations/20190618162719/steps.json
@@ -0,0 +1,166 @@
{
"version": "0.0.104",
"steps": [
{
"stepType": "CreateModel",
"name": "User",
"embedded": false
},
{
"stepType": "CreateModel",
"name": "Post",
"embedded": false
},
{
"stepType": "CreateField",
"model": "User",
"name": "id",
"type": {
"Base": "String"
},
"arity": "required",
"isUnique": true,
"id": {
"strategy": "Auto",
"sequence": null
},
"default": {
"Expression": [
"cuid",
"String",
[]
]
}
},
{
"stepType": "CreateField",
"model": "User",
"name": "email",
"type": {
"Base": "String"
},
"arity": "required",
"isUnique": true
},
{
"stepType": "CreateField",
"model": "User",
"name": "name",
"type": {
"Base": "String"
},
"arity": "optional",
"isUnique": false
},
{
"stepType": "CreateField",
"model": "User",
"name": "posts",
"type": {
"Relation": {
"to": "Post",
"to_fields": [],
"name": "PostToUser",
"on_delete": "None"
}
},
"arity": "list",
"isUnique": false
},
{
"stepType": "CreateField",
"model": "Post",
"name": "id",
"type": {
"Base": "String"
},
"arity": "required",
"isUnique": true,
"id": {
"strategy": "Auto",
"sequence": null
},
"default": {
"Expression": [
"cuid",
"String",
[]
]
}
},
{
"stepType": "CreateField",
"model": "Post",
"name": "createdAt",
"type": {
"Base": "DateTime"
},
"arity": "required",
"isUnique": false,
"default": {
"Expression": [
"now",
"DateTime",
[]
]
}
},
{
"stepType": "CreateField",
"model": "Post",
"name": "updatedAt",
"type": {
"Base": "DateTime"
},
"arity": "required",
"isUnique": false
},
{
"stepType": "CreateField",
"model": "Post",
"name": "published",
"type": {
"Base": "Boolean"
},
"arity": "required",
"isUnique": false
},
{
"stepType": "CreateField",
"model": "Post",
"name": "title",
"type": {
"Base": "String"
},
"arity": "required",
"isUnique": false
},
{
"stepType": "CreateField",
"model": "Post",
"name": "content",
"type": {
"Base": "String"
},
"arity": "optional",
"isUnique": false
},
{
"stepType": "CreateField",
"model": "Post",
"name": "author",
"type": {
"Relation": {
"to": "User",
"to_fields": [
"id"
],
"name": "PostToUser",
"on_delete": "None"
}
},
"arity": "optional",
"isUnique": false
}
]
}
6 changes: 6 additions & 0 deletions examples/javascript/grpc/prisma/migrations/lift.lock
@@ -0,0 +1,6 @@
# IF THERE'S A GIT CONFLICT IN THIS FILE, DON'T SOLVE IT MANUALLY!
# INSTEAD EXECUTE `prisma lift fix`
# lift lockfile v1
# Read more about conflict resolution here: TODO

20190618162719
2 changes: 1 addition & 1 deletion examples/javascript/grpc/prisma/project.prisma
Expand Up @@ -23,5 +23,5 @@ model Post {
published Boolean
title String
content String?
author User
author User?
}
9 changes: 5 additions & 4 deletions examples/javascript/grpc/prisma/seed.js
@@ -1,8 +1,8 @@
const Photon = require('../prisma/generated/photon')
const photon = new Photon()
const Photon = require('@generated/photon')
const photon = new Photon.default()

async function main() {
await photon.users.create({
const user1 = await photon.users.create({
data: {
email: 'alice@prisma.io',
name: 'Alice',
Expand All @@ -15,7 +15,7 @@ async function main() {
},
},
})
await photon.users.create({
const user2 = await photon.users.create({
data: {
email: 'bob@prisma.io',
name: 'Bob',
Expand All @@ -35,6 +35,7 @@ async function main() {
},
},
})
console.log({ user1, user2 })
}

main()
Expand Down
4 changes: 2 additions & 2 deletions examples/javascript/grpc/server/server.js
@@ -1,7 +1,7 @@
const chalk = require('chalk')
const PROTO_PATH = __dirname + '/../service.proto'

const Photon = require('../prisma/generated/photon')
const Photon = require('@generated/photon')
const photon = new Photon()

const grpc = require('grpc')
Expand Down Expand Up @@ -76,7 +76,7 @@ async function createDraft(call, callback) {
title,
content,
published: false,
author: { connect: { email: authorEmail } },
// author: { connect: { email: authorEmail } },
},
})
callback(null, newDraft)
Expand Down
8 changes: 4 additions & 4 deletions examples/javascript/grpc/yarn.lock
Expand Up @@ -886,10 +886,10 @@ prisma-generate-schema@1.34.0:
popsicle "10"
prisma-datamodel "1.34.0"

prisma2@^0.0.57:
version "0.0.57"
resolved "https://registry.yarnpkg.com/prisma2/-/prisma2-0.0.57.tgz#67a0ad7d6e5c7b0f6465e0568ed3b1f6737a445f"
integrity sha512-w4HkbD2db2Esu4UNtpbU6rasVliwMwzbOLuT+MO9yw8JdtnUf6rz9tLhFJaTFIIbxLPxTIlQvzzGB9i5+6lUUw==
prisma2@^0.0.79:
version "0.0.79"
resolved "https://registry.yarnpkg.com/prisma2/-/prisma2-0.0.79.tgz#4f6568ffdbe90c2f3e995f51874bd9cd6959e824"
integrity sha512-E1acg5zysYVjydWRb5M1MHv08Tw0XeW712jBMrOnDafKtIvQWFxuoeVBRoSj2/AsnlTjBmdLEV3R0RM5+qgCsg==

process-nextick-args@~2.0.0:
version "2.0.0"
Expand Down

0 comments on commit ebcae8e

Please sign in to comment.