yarn create redwood-app javascript-jam-redwood
cd javascript-jam-redwood
yarn rw dev
Open localhost:8910
yarn rw g page home /
// web/src/pages/HomePage/HomePage.js
import { MetaTags } from '@redwoodjs/web'
const HomePage = () => {
return (
<>
<MetaTags
title="Home"
description="This is the home page"
/>
<h1>Hello JavaScript Jam 🍯</h1>
</>
)
}
export default HomePage
// api/db/schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = "native"
}
model Post {
id Int @id @default(autoincrement())
title String
body String
createdAt DateTime @default(now())
}
First you need to create a Railway account and install the Railway CLI
railway login
Run the following command, select “Create new Project,” and add a plugin to your Railway project.
railway init
railway add
Select PostgreSQL.
Create a .env
file with your "DATABASE_URL".
echo DATABASE_URL=`railway variables get DATABASE_URL` > .env
Running yarn rw prisma migrate dev
generates the folders and files necessary to create a new migration. We will name our migration nailed-it
.
yarn rw prisma migrate dev --name nailed-it
A scaffold quickly creates a CRUD interface for a model by generating all the necessary files and corresponding routes.
yarn rw g scaffold post
You likely need to restart your development server for the environment variables to take effect.
yarn rw dev
Open localhost:8910/posts
Create a post and click save.
yarn rw g cell BlogPosts
// web/src/components/BlogPostsCell/BlogPostsCell.js
export const QUERY = gql`
query POSTS {
posts {
id
title
body
createdAt
}
}
`
export const Loading = () => <div>Loading...</div>
export const Empty = () => <div>Empty</div>
export const Failure = ({ error }) => (
<div style={{ color: 'red' }}>Error: {error.message}</div>
)
export const Success = ({ posts }) => {
return posts.map((post) => (
<article key={post.id}>
<header>
<h2>{post.title}</h2>
</header>
<p>{post.body}</p>
<time>{post.createdAt}</time>
</article>
))
}
// web/src/pages/HomePage/HomePage.js
import BlogPostsCell from 'src/components/BlogPostsCell'
import { MetaTags } from '@redwoodjs/web'
const HomePage = () => {
return (
<>
<MetaTags
title="Home"
description="This is the home page"
/>
<h1>Hello JavaScript Jam 🍯</h1>
<BlogPostsCell />
</>
)
}
export default HomePage
yarn rw setup deploy netlify
git init
git add .
git commit -m "we jammin, we jammin, hope you like jammin too"
gh repo create javascript-jam-redwood
git push -u origin main
Set DATABASE_URL
in Netlify dashboard.
postgresql://postgres:[email protected]:5958/railway?connection_limit=1