cobite
cobite
DTDrizzle Team
Created by cobite on 9/24/2023 in #help
Making a column only allow letters and characters, including capitals
Yeah i'm just validating it on the backend via yup, was just wondering if I could do it on the database side also. Thanks
4 replies
DTDrizzle Team
Created by cobite on 9/24/2023 in #help
Trying to generate a short id via a random string function
Just wondering if the search isn't great, or if it's something on my side.
18 replies
DTDrizzle Team
Created by cobite on 9/24/2023 in #help
Trying to generate a short id via a random string function
I so have trouble with the search functionality on the documentation. I've searched for inferselectmodel and infermodel before I asked etc but nothing shows.
18 replies
DTDrizzle Team
Created by cobite on 9/24/2023 in #help
Trying to generate a short id via a random string function
Just a side question, since updating, the following is deprecated:
export type Post = InferModel<typeof posts>;
export type Post = InferModel<typeof posts>;
have tried export type Post = typeof posts;
have tried export type Post = typeof posts;
But it shows too much data (the whole PgTable):
18 replies
DTDrizzle Team
Created by cobite on 9/24/2023 in #help
Trying to generate a short id via a random string function
thanks! Going to try the following now:
shortId: varchar('shortId')
.$defaultFn(() => generateRandomString(7))
.unique()
.notNull(),
shortId: varchar('shortId')
.$defaultFn(() => generateRandomString(7))
.unique()
.notNull(),
18 replies
DTDrizzle Team
Created by cobite on 9/24/2023 in #help
Trying to generate a short id via a random string function
hmm when I try $default I get:
Property '$default' does not exist on type 'PgVarcharBuilderInitial<"shortId", [string, ...string[]]>'. Did you mean 'default'?
Property '$default' does not exist on type 'PgVarcharBuilderInitial<"shortId", [string, ...string[]]>'. Did you mean 'default'?
18 replies
DTDrizzle Team
Created by cobite on 9/24/2023 in #help
Trying to generate a short id via a random string function
Thank you, I will try that now, I assume it's something along the lines of:
shortId: varchar('shortId').default(generateRandomString(7)).unique().notNull(),
shortId: varchar('shortId').default(generateRandomString(7)).unique().notNull(),
18 replies
DTDrizzle Team
Created by cobite on 9/24/2023 in #help
Trying to generate a short id via a random string function
Hey! I want the shortId to use the generateRandomString function to populate when a new item for that schema is generated on the database.
18 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
I do have a level and an amountChildren (only gets direct children) so far, but I guess I need a totalDescendents too
100 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
I've seemed to have come full circle. So by just getting some of the comments back to the client, i'm only getting the amount of children within the data in the client, not the entire dataset. So I do actually need to get this at the server side 😅
100 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
Hey, it's a project that me and a bunch of friends are working on. I managed to get it working with (based on your tip) :
(
SELECT COUNT(*)
FROM comments
WHERE parent_id = cte_comments.id
) AS hasChildren
(
SELECT COUNT(*)
FROM comments
WHERE parent_id = cte_comments.id
) AS hasChildren
How would adding the metadata on insert work if I don't know how many replies a comment would get beforehand? You mean on each reply, update the parent ids hasChildren?
100 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
The complexity creep is real.. 🥲 I'm trying to add a little feature that if it reaches the level 3 comments, it will check if they have children, and if they do then add a field called hasChildren. The reason for this is to be able to determine on the client side if a level 3 comment has children so that a load more button can be shown. Was trying something like:
CASE WHEN EXISTS (
SELECT 1
FROM comments nc
WHERE nc.parent_id = c.id
AND c.level = 3
) THEN TRUE ELSE FALSE END AS has_children
CASE WHEN EXISTS (
SELECT 1
FROM comments nc
WHERE nc.parent_id = c.id
AND c.level = 3
) THEN TRUE ELSE FALSE END AS has_children
and below:
CASE WHEN EXISTS (
SELECT 1
FROM comments nc
WHERE nc.parent_id = e.id
AND c.level + 1 = 3
) THEN TRUE ELSE FALSE END AS has_children
CASE WHEN EXISTS (
SELECT 1
FROM comments nc
WHERE nc.parent_id = e.id
AND c.level + 1 = 3
) THEN TRUE ELSE FALSE END AS has_children
No luck yet! I could just get max levels + 1, and then on the client side add the amount of children to level 3 objects and just do nothing with the level 4s, but I think it might be cleaner to just find out the amount via sql
100 replies
DTDrizzle Team
Created by cobite on 9/1/2023 in #help
Transforming SELECT from case to camelCase via sql with execute
😂 so simple!
6 replies
DTDrizzle Team
Created by cobite on 9/1/2023 in #help
Transforming SELECT from case to camelCase via sql with execute
What i'm doing at the comment is this after the execute:
const transformedResults: Comment[] = results.map((row) => ({
id: row.id,
createdAt: row.created_at,
}));
const transformedResults: Comment[] = results.map((row) => ({
id: row.id,
createdAt: row.created_at,
}));
6 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
Think I have it working:
SELECT
cte_comments.id,
cte_comments.parent_id,
users.username
FROM
cte_comments
INNER JOIN
users on users.id = cte_comments.user_id
SELECT
cte_comments.id,
cte_comments.parent_id,
users.username
FROM
cte_comments
INNER JOIN
users on users.id = cte_comments.user_id
100 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
Oh ok, I was just adding username to the select and added your inner join, and the error was: error rendering: PostgresError: column reference "id" is ambiguous Get back to work though there's no rush with this. I'm learning a ton from you though so thanks!
100 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
I was previously doing it the other way:
.leftJoin(users, eq(users.id, comments.userId))
.leftJoin(users, eq(users.id, comments.userId))
and
username: users.username,
username: users.username,
100 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
Yes finally! Now I just need to add a join to use the comment.user_id to get the username from the users table. Not sure where to fit that in, but i'll get there eventually 🙂
100 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
Had to just add the c to:
INNER JOIN cte_comments c ON e.parent_id = c.id
INNER JOIN cte_comments c ON e.parent_id = c.id
100 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
If I remove the trailing , from here:
id,
parent_id,
FROM
id,
parent_id,
FROM
I get:
error rendering: PostgresError: missing FROM-clause entry for table "c"
error rendering: PostgresError: missing FROM-clause entry for table "c"
100 replies