DILJAM
DILJAM
TTCTheo's Typesafe Cult
Created by DILJAM on 3/19/2024 in #questions
What Arc browser settings / extensions is Theo using?
I've noticed in his videos that his Arc browser looks different from mine; localhost tabs appear with a dashed outline. Also, the full page URL is shown on the top of the page, which it isn't on my machine.
4 replies
TTCTheo's Typesafe Cult
Created by DILJAM on 2/1/2023 in #questions
How well can I rely on Tailwinds ability to know what classes to include in the CSS?
I'm new to Tailwind and I'm trying to understand how it works under the hood. More specifically how well can I rely on its "engine" to find all references to Tailwind classes in my source code to know which classes to include in the CSS that it generates? For example, will Tailwind work (include the correct classes in the generated CSS) in the following scenario?
const baseClassNames = "px-1 py-0.5"

const Component = ({green}) => {
return <span className={clsx(baseClassNames, green && "text-green")}>Example</span>
}
const baseClassNames = "px-1 py-0.5"

const Component = ({green}) => {
return <span className={clsx(baseClassNames, green && "text-green")}>Example</span>
}
The classes I would expect to be included in the generated CSS are px-1, py-0.5 and text-green. What about this scenario?
const baseClassNames = "px-1 py-0.5"
const getTextColor = (textColor) => `text-${textColor}`

const Component = ({textColor}) => {
return <span className={clsx(baseClassNames, textColor && getTextColor(textColor))}>Example</span>
}
const baseClassNames = "px-1 py-0.5"
const getTextColor = (textColor) => `text-${textColor}`

const Component = ({textColor}) => {
return <span className={clsx(baseClassNames, textColor && getTextColor(textColor))}>Example</span>
}
7 replies
TTCTheo's Typesafe Cult
Created by DILJAM on 9/30/2022 in #questions
Many-to-many relationship in SQL as table or JSONB array?
Hi! I'm new to SQL and I'm wondering which way to model data makes more sense. I want queries to be performant, yet I don't want to over-engineer. My database is PostgreSQL in Supabase. I'm modeling players and games where each player can be in many games and each game can have many players — so a many-to-many relationship. I've enabled Row Level Security so a player only has access to the games that they participate in. Currently I have it set up so that the players-games relationship is stored in a table players_games. Something like this:
create table players (
id uuid primary key
);

create table games (
id uuid primary key
);

create table players_games (
id uuid primary key,
player uuid references players,
game uuid references games,

unique(player, game)
);
create table players (
id uuid primary key
);

create table games (
id uuid primary key
);

create table players_games (
id uuid primary key,
player uuid references players,
game uuid references games,

unique(player, game)
);
The security policy uses the following check:
exists(
select 1
from players_games
where player = player_id
and game = game_id
);
exists(
select 1
from players_games
where player = player_id
and game = game_id
);
At the time when I implemented this I didn't know about JSON functions and operators in PostgreSQL. See https://www.postgresql.org/docs/current/functions-json.html and https://supabase.com/docs/guides/database/json#query-the-jsonb-data. So the same could be implemented like this as well:
create table players (
id uuid primary key
);

create table games (
id uuid primary key,
players jsonb
);
create table players (
id uuid primary key
);

create table games (
id uuid primary key,
players jsonb
);
games.players would be an array of player UUIDs, e.g.
[
"cf7...9f5",
"de0...91d",
...
]
[
"cf7...9f5",
"de0...91d",
...
]
The check would then be implemented like this:
exists(
select 1
from games
where id = game_id
and players @> player_id
);
exists(
select 1
from games
where id = game_id
and players @> player_id
);
Which approach would you suggest as a more experienced SQL developer? What are the pros and cons for each approach and the things worth considering?
9 replies