mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 22:26:16 +03:00
Try prisma in Netlify.
This commit is contained in:
parent
6eb4bff4bd
commit
93408eb17b
136
examples/pokedex/app/Route/Users.elm
Normal file
136
examples/pokedex/app/Route/Users.elm
Normal file
@ -0,0 +1,136 @@
|
||||
module Route.Users exposing (ActionData, Data, route, RouteParams, Msg, Model)
|
||||
|
||||
{-|
|
||||
|
||||
@docs ActionData, Data, route, RouteParams, Msg, Model
|
||||
|
||||
-}
|
||||
|
||||
import BackendTask
|
||||
import BackendTask.Custom
|
||||
import Effect
|
||||
import ErrorPage
|
||||
import FatalError
|
||||
import Head
|
||||
import Html
|
||||
import Json.Decode as Decode
|
||||
import Json.Encode as Encode
|
||||
import Pages.Msg
|
||||
import Pages.PageUrl
|
||||
import Path
|
||||
import Platform.Sub
|
||||
import RouteBuilder
|
||||
import Server.Request
|
||||
import Server.Response
|
||||
import Shared
|
||||
import View
|
||||
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
type Msg
|
||||
= NoOp
|
||||
|
||||
|
||||
type alias RouteParams =
|
||||
{}
|
||||
|
||||
|
||||
route : RouteBuilder.StatefulRoute RouteParams Data ActionData Model Msg
|
||||
route =
|
||||
RouteBuilder.buildWithLocalState
|
||||
{ view = view
|
||||
, init = init
|
||||
, update = update
|
||||
, subscriptions = subscriptions
|
||||
}
|
||||
(RouteBuilder.serverRender { data = data, action = action, head = head })
|
||||
|
||||
|
||||
init :
|
||||
Maybe Pages.PageUrl.PageUrl
|
||||
-> Shared.Model
|
||||
-> RouteBuilder.StaticPayload Data ActionData RouteParams
|
||||
-> ( Model, Effect.Effect Msg )
|
||||
init pageUrl sharedModel app =
|
||||
( {}, Effect.none )
|
||||
|
||||
|
||||
update :
|
||||
Pages.PageUrl.PageUrl
|
||||
-> Shared.Model
|
||||
-> RouteBuilder.StaticPayload Data ActionData RouteParams
|
||||
-> Msg
|
||||
-> Model
|
||||
-> ( Model, Effect.Effect msg )
|
||||
update pageUrl sharedModel app msg model =
|
||||
case msg of
|
||||
NoOp ->
|
||||
( model, Effect.none )
|
||||
|
||||
|
||||
subscriptions :
|
||||
Maybe Pages.PageUrl.PageUrl
|
||||
-> RouteParams
|
||||
-> Path.Path
|
||||
-> Shared.Model
|
||||
-> Model
|
||||
-> Sub Msg
|
||||
subscriptions maybePageUrl routeParams path sharedModel model =
|
||||
Platform.Sub.none
|
||||
|
||||
|
||||
type alias Data =
|
||||
{ users : List String
|
||||
}
|
||||
|
||||
|
||||
type alias ActionData =
|
||||
{}
|
||||
|
||||
|
||||
data :
|
||||
RouteParams
|
||||
-> Server.Request.Parser (BackendTask.BackendTask FatalError.FatalError (Server.Response.Response Data ErrorPage.ErrorPage))
|
||||
data routeParams =
|
||||
Server.Request.succeed
|
||||
(BackendTask.Custom.run "users"
|
||||
Encode.null
|
||||
(Decode.list (Decode.field "" Decode.string))
|
||||
|> BackendTask.allowFatal
|
||||
|> BackendTask.map
|
||||
(\users ->
|
||||
Server.Response.render
|
||||
{ users = users
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
head : RouteBuilder.StaticPayload Data ActionData RouteParams -> List Head.Tag
|
||||
head app =
|
||||
[]
|
||||
|
||||
|
||||
view :
|
||||
Maybe Pages.PageUrl.PageUrl
|
||||
-> Shared.Model
|
||||
-> Model
|
||||
-> RouteBuilder.StaticPayload Data ActionData RouteParams
|
||||
-> View.View (Pages.Msg.Msg Msg)
|
||||
view maybeUrl sharedModel model app =
|
||||
{ title = "Users"
|
||||
, body =
|
||||
[ Html.h2 [] [ Html.text "Users" ]
|
||||
, Html.text (app.data.users |> String.join ", ")
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
action :
|
||||
RouteParams
|
||||
-> Server.Request.Parser (BackendTask.BackendTask FatalError.FatalError (Server.Response.Response ActionData ErrorPage.ErrorPage))
|
||||
action routeParams =
|
||||
Server.Request.succeed (BackendTask.succeed (Server.Response.render {}))
|
@ -1,6 +1,19 @@
|
||||
import kleur from "kleur";
|
||||
import something from './something.ts'
|
||||
kleur.enabled = true;
|
||||
import something from "./something.ts";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export async function users() {
|
||||
try {
|
||||
const users = await prisma.user.findMany({
|
||||
include: { profile: true },
|
||||
});
|
||||
return users;
|
||||
} catch (error) {
|
||||
console.trace(error);
|
||||
return ["PRISMA ERROR"];
|
||||
}
|
||||
}
|
||||
|
||||
export async function environmentVariable(name) {
|
||||
const result = process.env[name];
|
||||
|
81
examples/pokedex/package-lock.json
generated
81
examples/pokedex/package-lock.json
generated
@ -8,6 +8,9 @@
|
||||
"name": "elm-pages-example",
|
||||
"version": "1.0.0",
|
||||
"license": "BSD-3",
|
||||
"dependencies": {
|
||||
"@prisma/client": "^4.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@dillonkearns/elm-graphql": "^4.2.3",
|
||||
"@netlify/functions": "^0.7.2",
|
||||
@ -18,6 +21,7 @@
|
||||
"elm-tailwind-modules": "^0.3.2",
|
||||
"elm-tooling": "^1.3.0",
|
||||
"postcss": "^8.4.5",
|
||||
"prisma": "^4.9.0",
|
||||
"tailwindcss": "^2.2.19"
|
||||
}
|
||||
},
|
||||
@ -589,6 +593,38 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/client": {
|
||||
"version": "4.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.9.0.tgz",
|
||||
"integrity": "sha512-bz6QARw54sWcbyR1lLnF2QHvRW5R/Jxnbbmwh3u+969vUKXtBkXgSgjDA85nji31ZBlf7+FrHDy5x+5ydGyQDg==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/engines-version": "4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"prisma": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"prisma": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/engines": {
|
||||
"version": "4.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.9.0.tgz",
|
||||
"integrity": "sha512-t1pt0Gsp+HcgPJrHFc+d/ZSAaKKWar2G/iakrE07yeKPNavDP3iVKPpfXP22OTCHZUWf7OelwKJxQgKAm5hkgw==",
|
||||
"devOptional": true,
|
||||
"hasInstallScript": true
|
||||
},
|
||||
"node_modules/@prisma/engines-version": {
|
||||
"version": "4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5.tgz",
|
||||
"integrity": "sha512-M16aibbxi/FhW7z1sJCX8u+0DriyQYY5AyeTH7plQm9MLnURoiyn3CZBqAyIoQ+Z1pS77usCIibYJWSgleBMBA=="
|
||||
},
|
||||
"node_modules/@sindresorhus/is": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-2.1.1.tgz",
|
||||
@ -4898,6 +4934,23 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/prisma": {
|
||||
"version": "4.9.0",
|
||||
"resolved": "https://registry.npmjs.org/prisma/-/prisma-4.9.0.tgz",
|
||||
"integrity": "sha512-bS96oZ5oDFXYgoF2l7PJ3Mp1wWWfLOo8B/jAfbA2Pn0Wm5Z/owBHzaMQKS3i1CzVBDWWPVnOohmbJmjvkcHS5w==",
|
||||
"devOptional": true,
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/engines": "4.9.0"
|
||||
},
|
||||
"bin": {
|
||||
"prisma": "build/index.js",
|
||||
"prisma2": "build/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/prompts": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz",
|
||||
@ -6603,6 +6656,25 @@
|
||||
"fastq": "^1.6.0"
|
||||
}
|
||||
},
|
||||
"@prisma/client": {
|
||||
"version": "4.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.9.0.tgz",
|
||||
"integrity": "sha512-bz6QARw54sWcbyR1lLnF2QHvRW5R/Jxnbbmwh3u+969vUKXtBkXgSgjDA85nji31ZBlf7+FrHDy5x+5ydGyQDg==",
|
||||
"requires": {
|
||||
"@prisma/engines-version": "4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5"
|
||||
}
|
||||
},
|
||||
"@prisma/engines": {
|
||||
"version": "4.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.9.0.tgz",
|
||||
"integrity": "sha512-t1pt0Gsp+HcgPJrHFc+d/ZSAaKKWar2G/iakrE07yeKPNavDP3iVKPpfXP22OTCHZUWf7OelwKJxQgKAm5hkgw==",
|
||||
"devOptional": true
|
||||
},
|
||||
"@prisma/engines-version": {
|
||||
"version": "4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5.tgz",
|
||||
"integrity": "sha512-M16aibbxi/FhW7z1sJCX8u+0DriyQYY5AyeTH7plQm9MLnURoiyn3CZBqAyIoQ+Z1pS77usCIibYJWSgleBMBA=="
|
||||
},
|
||||
"@sindresorhus/is": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-2.1.1.tgz",
|
||||
@ -9733,6 +9805,15 @@
|
||||
"integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=",
|
||||
"dev": true
|
||||
},
|
||||
"prisma": {
|
||||
"version": "4.9.0",
|
||||
"resolved": "https://registry.npmjs.org/prisma/-/prisma-4.9.0.tgz",
|
||||
"integrity": "sha512-bS96oZ5oDFXYgoF2l7PJ3Mp1wWWfLOo8B/jAfbA2Pn0Wm5Z/owBHzaMQKS3i1CzVBDWWPVnOohmbJmjvkcHS5w==",
|
||||
"devOptional": true,
|
||||
"requires": {
|
||||
"@prisma/engines": "4.9.0"
|
||||
}
|
||||
},
|
||||
"prompts": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz",
|
||||
|
@ -21,6 +21,10 @@
|
||||
"elm-tailwind-modules": "^0.3.2",
|
||||
"elm-tooling": "^1.3.0",
|
||||
"postcss": "^8.4.5",
|
||||
"prisma": "^4.9.0",
|
||||
"tailwindcss": "^2.2.19"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^4.9.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "Post" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"title" TEXT NOT NULL,
|
||||
"content" TEXT,
|
||||
"published" BOOLEAN NOT NULL DEFAULT false,
|
||||
"authorId" INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Profile" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"bio" TEXT,
|
||||
"userId" INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "User" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"email" TEXT NOT NULL,
|
||||
"name" TEXT,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Profile.userId_unique" ON "Profile"("userId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Post" ADD FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Profile" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
3
examples/pokedex/prisma/migrations/migration_lock.toml
Normal file
3
examples/pokedex/prisma/migrations/migration_lock.toml
Normal file
@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "postgresql"
|
34
examples/pokedex/prisma/schema.prisma
Normal file
34
examples/pokedex/prisma/schema.prisma
Normal file
@ -0,0 +1,34 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
binaryTargets = ["native", "rhel-openssl-1.0.x"]
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Post {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
title String
|
||||
content String?
|
||||
published Boolean @default(false)
|
||||
author User @relation(fields: [authorId], references: [id]) // renamed from `User` -> `author`
|
||||
authorId Int // relation scalar field
|
||||
}
|
||||
|
||||
model Profile {
|
||||
id Int @id @default(autoincrement())
|
||||
bio String?
|
||||
userId Int @unique // relation scalar field
|
||||
user User @relation(fields: [userId], references: [id]) // renamed from `User` -> `user`
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
name String?
|
||||
posts Post[] // renamed from `Post` -> `posts`
|
||||
profile Profile? // renamed from `User` -> `profile`
|
||||
}
|
@ -150,13 +150,15 @@ export async function run(options) {
|
||||
.build({
|
||||
entryPoints: ["./custom-backend-task"],
|
||||
platform: "node",
|
||||
outfile: ".elm-pages/compiled-ports/custom-backend-task.js",
|
||||
outfile: ".elm-pages/compiled-ports/custom-backend-task.mjs",
|
||||
assetNames: "[name]-[hash]",
|
||||
chunkNames: "chunks/[name]-[hash]",
|
||||
outExtension: { ".js": ".js" },
|
||||
metafile: true,
|
||||
bundle: true,
|
||||
watch: false,
|
||||
format: "esm",
|
||||
external: ["@prisma/client"],
|
||||
logLevel: "silent",
|
||||
})
|
||||
.then((result) => {
|
||||
@ -625,7 +627,7 @@ async function runAdapter(adaptFn, processedIndexTemplate) {
|
||||
apiRoutePatterns: JSON.parse(
|
||||
await fsPromises.readFile("./dist/api-patterns.json", "utf-8")
|
||||
),
|
||||
portsFilePath: "./.elm-pages/compiled-ports/custom-backend-task.js",
|
||||
portsFilePath: "./.elm-pages/compiled-ports/custom-backend-task.mjs",
|
||||
htmlTemplate: processedIndexTemplate,
|
||||
});
|
||||
console.log("Success - Adapter script complete");
|
||||
|
Loading…
Reference in New Issue
Block a user