Skip to content

Commit

Permalink
WIP ways to be better dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dthyresson committed Dec 8, 2022
1 parent 6055431 commit 480807e
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 2022-12-00-redwood-retro-lists/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 2022 Redwood Year in Review. Top 10 Lists. Stats. Retrospectives.

## Year in Review

## Top 10 Lists

- [10 Ways to Become a Better RedwoodJS Developer](ten-ways-to-become-better-redwood-developer.md)

## Stats

## Retrospectives
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# 10 Ways to Become a Better RedwoodJS Developer

1. How to Ask Questions

1. Postgres and General Data Design

- [Prisma's Data Guide](https://www.prisma.io/dataguide)
Learn how databases work, how to choose the right one, and how to use databases with your applications to their full potential
- [About PostgreSQL](https://www.prisma.io/dataguide#postgresql)

1. Postgres CTEs & Window Functions

### Window Functions

- Window functions provide the ability to perform calculations across sets of rows that are related to the current query row
- https://www.postgresql.org/docs/15/functions-window.html
- `row_number()`
- `dense_rank()`
- `ntile()`
- `lag()`
- `lead()`
- the `OVER` clause
- the `PARTITION BY` [list](https://www.postgresql.org/docs/15/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS)

### Example

```ts
/**
* Calculates the leaders for a leaderboard based on the number of plays,
* the total correct, incorrect, and unanswered.
*
* Uses a CTE and a Postgres DENSE_RANK() window function to ranking each players place
*
* Dense ranking gives the player with teh same score, the same rank (ie, share place)
*
* The top player is the one with the most correct plays.
*
* I *really* wish Prisma supported views.
*
* @returns an array of <Leaderboard>
* @see Postgres Window Functions https://www.postgresql.org/docs/current/functions-window.html
*/
export const leaderboards = async () => {
// how can I import the Leaderboard type for the graphql types (not Prisma types)?
const leaders = await db.$queryRaw<typeof Leaderboard[]>`
WITH correct_counts AS (
SELECT
p. "playerId",
1 AS played,
CASE WHEN correctness = TRUE THEN
1
END AS correct,
CASE WHEN correctness = FALSE THEN
1
END AS incorrect,
CASE WHEN correctness IS NULL THEN
1
END AS unanswered
FROM
"Play" p
),
totals AS (
SELECT
"playerId",
coalesce(sum(played),
0) AS "playedTotal",
coalesce(sum(correct),
0) AS "correctTotal",
coalesce(sum(incorrect),
0) AS "incorrectTotal",
coalesce(sum(unanswered),
0) AS "unansweredTotal"
FROM
correct_counts
GROUP BY
"playerId"
)
SELECT
t. "playerId",
p.name,
p. "gravatarHash",
t. "playedTotal",
t. "correctTotal",
t. "incorrectTotal",
t. "unansweredTotal",
DENSE_RANK() OVER (ORDER BY t. "correctTotal" DESC) AS place,
ROW_NUMBER() OVER () AS "leaderboardRowNumber"
FROM
totals t
JOIN "Player" p ON p.id = t. "playerId"
ORDER BY
"leaderboardRowNumber" ASC,
place DESC,
p.name ASC`;

return leaders;
};
```

1. Postgres Functions & Triggers

1. Views and Materialized Views

1. Prisma Nested Reads and Writes

When to use [`connect`](https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-an-existing-record), [`create` or `createMany`](https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#create-a-related-record) and [`connectOrCreate`](https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-or-create-a-record).

- https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-reads
- https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-writes

Office Hours Example: - https://github.com/redwoodjs/redwood-office-hours/tree/main/2022-10-26-nested-writes-demo

1. Data Model vs GraphQL API

1. Understanding Resolvers

- Default Resolvers: https://redwoodjs.com/docs/graphql#understanding-default-resolvers
- Relation Resolvers: https://redwoodjs.com/docs/typescript/strict-mode#relation-resolvers-in-services

1. Naming

1. Caching

No when to hold them ... when to walk way. when to ru.

1. Documentation

- reading
- writing
- Docusaurus
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This repo is where these demos and examples live.
- [2022-10-26-nested-writes-demo](2022-10-26-nested-writes-demo/README.md) - How To Perform Nested Writes with RedwoodJS and GraphQL
- [2022-11-02-og-image-demo](2022-11-02-og-image-demo/README.md) - How to Generate OG Images for Social Cards using Netlify Edge Functions and RedwoodJS MetaTags
- [2022-11-13-custom-md5-auth](2022-11-13-custom-md5-auth/README.md) - How to Implement Custom Auth in RedwoodJS v4
- [2022-11-13-custom-md5-auth](2022-11-13-custom-md5-auth/README.md) - How to Implement Custom Auth in RedwoodJS v4

## Discord Invite Link

Expand Down

0 comments on commit 480807e

Please sign in to comment.