Amur
Amur
Explore posts from servers
CDCloudflare Developers
Created by Amur on 4/8/2025 in #general-help
Replacing Cloudfront with Cloudflare
Hey! At my company we heavily rely on AWS services but we are currently considering using some Cloudflare services as well since people are saying a lot of good things about them. As the first step I’m investing how could we leverage Cloudflare as a CDN instead of AWS cloudfront. We usually have Cloudfront in front of API Gateway for our BFF and then we also use Cloudfront in front of an S3 bucket where the frontend code is hosted. Are there any tutorials that i should look at? Or anyone has any pointers/recommendations/tips?
1 replies
DTDrizzle Team
Created by Amur on 2/5/2025 in #help
Conditional queries with $dynamic
Is there a way to not execute the query yet within the if statement?
const countQuery = db
.select({
count: sql<number>`count(${recipeTable.id})`.mapWith(Number),
})
.from(recipeTable)
.where(and(...where))
.$dynamic();

if (filters.language) {
countQuery.leftJoin(
recipeTranslationTable,
and(eq(recipeTable.id, recipeTranslationTable.recipeId), eq(recipeTranslationTable.locale, filters.language)),
);
}
const countQuery = db
.select({
count: sql<number>`count(${recipeTable.id})`.mapWith(Number),
})
.from(recipeTable)
.where(and(...where))
.$dynamic();

if (filters.language) {
countQuery.leftJoin(
recipeTranslationTable,
and(eq(recipeTable.id, recipeTranslationTable.recipeId), eq(recipeTranslationTable.locale, filters.language)),
);
}
2 replies
DTDrizzle Team
Created by Amur on 4/12/2024 in #help
Connection hangs in AWS Lambda when using response streaming
No description
1 replies
DTDrizzle Team
Created by Amur on 3/26/2024 in #help
Ignore foreign key violation on bulk insert
Is there a way to just skip the value, or even better make it null if one of the values from a bulk insert vauses a foreign key violation error for example i have this code, and the second element as a recipeId that doesn't exist so i would get a foreign key violation error Is there a way to just skip the second element or make recipeId null for the second element (recipeId is a nullable field)
await db.insert(menuItemTable).values([
{
menuId: 1,
name: "test item 1",
description: "item.description",
price: 12,
recipeId: 8,
},
{
menuId: 1,
name: "test item 2",
description: "item.description",
price: 12,
recipeId: 12, // there is no recipe with id 12
},
{
menuId: 1,
name: "test item 3",
description: "item.description",
price: 12,
recipeId: 8,
},
]);
await db.insert(menuItemTable).values([
{
menuId: 1,
name: "test item 1",
description: "item.description",
price: 12,
recipeId: 8,
},
{
menuId: 1,
name: "test item 2",
description: "item.description",
price: 12,
recipeId: 12, // there is no recipe with id 12
},
{
menuId: 1,
name: "test item 3",
description: "item.description",
price: 12,
recipeId: 8,
},
]);
1 replies
DTDrizzle Team
Created by Amur on 2/22/2024 in #help
Postgrest inserting json array results in stringified array
I'm trying to insert a an array of objects as a json array but it always ends up being strinfied if it would be just a json then i can do sql${recipeData.notes}::jsonb` but that doesn't work with arrays (cannot cast type record to jsonb`)
5 replies
DTDrizzle Team
Created by Amur on 2/20/2024 in #help
Drizzle-zod not inferring array field as array
No description
1 replies
TTCTheo's Typesafe Cult
Created by Amur on 11/22/2023 in #questions
Can't delete globally installed npm package
i want to delete the serverless.js npm package that's installed globally if i run serverless --version i see that there is a version installed globally
serverless --version
Running "serverless" from node_modules
Framework Core: 3.37.0 (local) 3.22.0 (global)
Plugin: 7.2.0
SDK: 4.5.1
serverless --version
Running "serverless" from node_modules
Framework Core: 3.37.0 (local) 3.22.0 (global)
Plugin: 7.2.0
SDK: 4.5.1
if i run npm ls -g it's not in the list
➜ ttttttttt git:(main) ✗ npm ls -g
/Users/me/Library/Application Support/fnm/node-versions/v18.17.1/installation/lib
➜ ttttttttt git:(main) ✗ npm ls -g
/Users/me/Library/Application Support/fnm/node-versions/v18.17.1/installation/lib
I switched to all installed node versions, checked npm ls -g for all but serverless wasn't in the list for any of them I'm thinking, maybe i installed serverless.js globally when i was still using nvm instead of fnm Is there a way to check the globally installed npm packages that were installed when i was using nvm ? 🤔
2 replies
TTCTheo's Typesafe Cult
Created by Amur on 11/6/2023 in #questions
Can npx execute packages without having the package installed?
In a lot of places i see people saying that npx can execute packages without instlalling them but whenever i try to exeute a package i get Need to install the following packages. example npx cowsay 'wow'
Need to install the following packages:
Ok to proceed? (y)
Need to install the following packages:
Ok to proceed? (y)
3 replies
DTDrizzle Team
Created by Amur on 9/15/2023 in #help
Add drizzle-kit check as a pre-commit hook
Is there a way to add drizzle-kit check as a pre-commit hook with husky that would actually prevent the commit if something is wrong with my migrations? Currently i can add it but it won't prevent commiting
1 replies
DTDrizzle Team
Created by Amur on 9/6/2023 in #help
Type of `tx` when using `db.transactions`
I want to use helper functions within db.transactions but I can't get the type of tx working so basically i don't know how to type tx in the updateUserNotifications function
const updateUserNotifications = async (
userId: UpdateUserAttributes["id"],
notifications: Required<UpdateUserAttributes>["notifications"],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
tx: any, // TODO: what's the type of this
) => {
// check if user has a notification settings record
const userNotificationSettings = await tx.select().from(userNotifications).where(eq(users.id, userId));

// create user notification settings record if it doesn't exist
if (!userNotificationSettings.length) {
await tx.insert(userNotifications).values({
userId,
favorites: notifications.favorites,
});
}

await tx.update(userNotifications).set({ favorites: notifications.favorites }).where(eq(users.id, userId));
};

export const updateUser = async (userAttributes: UpdateUserAttributes) => {
await db.transaction(async (tx) => {
// update user notification settings
if (userAttributes.notifications) {
await updateUserNotifications(userAttributes.id, userAttributes.notifications, tx);
}
});
};
const updateUserNotifications = async (
userId: UpdateUserAttributes["id"],
notifications: Required<UpdateUserAttributes>["notifications"],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
tx: any, // TODO: what's the type of this
) => {
// check if user has a notification settings record
const userNotificationSettings = await tx.select().from(userNotifications).where(eq(users.id, userId));

// create user notification settings record if it doesn't exist
if (!userNotificationSettings.length) {
await tx.insert(userNotifications).values({
userId,
favorites: notifications.favorites,
});
}

await tx.update(userNotifications).set({ favorites: notifications.favorites }).where(eq(users.id, userId));
};

export const updateUser = async (userAttributes: UpdateUserAttributes) => {
await db.transaction(async (tx) => {
// update user notification settings
if (userAttributes.notifications) {
await updateUserNotifications(userAttributes.id, userAttributes.notifications, tx);
}
});
};
19 replies
DTDrizzle Team
Created by Amur on 9/6/2023 in #help
Update relationship within 1 query
is it possible to update relationships? for example i have a one to one relationship between users and notifications but i couldn't find any example of how i could update the notifications of a user in 1 query
const updateduser = await db
.update(users)
.set({ email: userAttributes.email }) //i would expect `notifications` to be an option in `set`
.where(eq(users.id, userAttributes.id))
.returning();
const updateduser = await db
.update(users)
.set({ email: userAttributes.email }) //i would expect `notifications` to be an option in `set`
.where(eq(users.id, userAttributes.id))
.returning();
same question goes for many to many relationships lets say i have a many to many between users and interests i want to update the user attributes and the interests of the user do i have to: 1. update user attributes 2. delete the current interests of the user from the association table 3. insert updated interests of the user
5 replies
DTDrizzle Team
Created by Amur on 8/29/2023 in #help
Is it possible to do lateral sub-query join without relational queries?
I'm trying to rewrite the same query that the relation query builder does behind the scenes but not sure if it's possible If i log the query this is what i get
select "articles"."id", "articles"."title", "articles_keywords"."data" as "keywords" from "articles"
left join lateral (select coalesce(json_agg(json_build_array("articles_keywords"."article_id", "articles_keywords"."keyword_value")), '[]'::json)
as "data" from "article_keyword_association_table" "articles_keywords"
where "articles_keywords"."article_id" = "articles"."id") "articles_keywords" on true
where "articles"."id" in ('ec9ffb05-dfa0-455f-a71c-46ece3dc28a8', 'e56a9ae6-2373-4ad7-8d59-a76c7809d8ec')
select "articles"."id", "articles"."title", "articles_keywords"."data" as "keywords" from "articles"
left join lateral (select coalesce(json_agg(json_build_array("articles_keywords"."article_id", "articles_keywords"."keyword_value")), '[]'::json)
as "data" from "article_keyword_association_table" "articles_keywords"
where "articles_keywords"."article_id" = "articles"."id") "articles_keywords" on true
where "articles"."id" in ('ec9ffb05-dfa0-455f-a71c-46ece3dc28a8', 'e56a9ae6-2373-4ad7-8d59-a76c7809d8ec')
I would like to do the same logic with the query builder becauase the relational queries there are certain things i cant do
3 replies
DTDrizzle Team
Created by Amur on 8/22/2023 in #help
DB connections hangs after successful execution in Lambda locally
I'm testing my lambda functions locally with sls invoke local -f hello. after returning a success response, my execution doesnt end attached a video that shows the behaviour if i remove the db query then it works fine
22 replies
DTDrizzle Team
Created by Amur on 8/10/2023 in #help
Error: Can't find meta/_journal.json file when trying to apply migrations in a lambda
11 replies
DTDrizzle Team
Created by Amur on 7/24/2023 in #help
order by array_position does not order the records in postgres
Using array_positions either throws error or ignores the order If i try to do it this way i get an function array_position(record, character varying) does not exist error
const articleData = await db
.select()
.from(articles)
.where(inArray(articles.id, idsToInclude))
.orderBy(sql`array_position(${idsToInclude}, ${articles.id})`);
const articleData = await db
.select()
.from(articles)
.where(inArray(articles.id, idsToInclude))
.orderBy(sql`array_position(${idsToInclude}, ${articles.id})`);
If i join the array elements then I don't get an error but the order does not change
const ids = "'f02d422b-c8c7-49df-9240-1dcb5a9f4342','7cf70ee0-2e4c-4360-aa5d-8230973b7ec3','367c861c-3f46-4d1a-b1ac-3a25c13121bd','348ad8ab-e7e1-4bf0-b762-c7df0d9e3a75'";

const articleData = await db
.select()
.from(articles)
.where(inArray(articles.id, idsToInclude))
.orderBy(sql`array_position(ARRAY[${a}], ${articles.id})`);
const ids = "'f02d422b-c8c7-49df-9240-1dcb5a9f4342','7cf70ee0-2e4c-4360-aa5d-8230973b7ec3','367c861c-3f46-4d1a-b1ac-3a25c13121bd','348ad8ab-e7e1-4bf0-b762-c7df0d9e3a75'";

const articleData = await db
.select()
.from(articles)
.where(inArray(articles.id, idsToInclude))
.orderBy(sql`array_position(ARRAY[${a}], ${articles.id})`);
However, If I hardcode the ids I get the correct order
const articleData = await db
.select()
.from(articles)
.where(inArray(articles.id, idsToInclude))
.orderBy(sql`array_position(ARRAY[
'f02d422b-c8c7-49df-9240-1dcb5a9f4342',
'7cf70ee0-2e4c-4360-aa5d-8230973b7ec3',
'367c861c-3f46-4d1a-b1ac-3a25c13121bd',
'348ad8ab-e7e1-4bf0-b762-c7df0d9e3a75'
], ${articles.id})`);
const articleData = await db
.select()
.from(articles)
.where(inArray(articles.id, idsToInclude))
.orderBy(sql`array_position(ARRAY[
'f02d422b-c8c7-49df-9240-1dcb5a9f4342',
'7cf70ee0-2e4c-4360-aa5d-8230973b7ec3',
'367c861c-3f46-4d1a-b1ac-3a25c13121bd',
'348ad8ab-e7e1-4bf0-b762-c7df0d9e3a75'
], ${articles.id})`);
2 replies
DTDrizzle Team
Created by Amur on 7/10/2023 in #help
Including more than 1 relation in query throws error
If i try to include more than 1 relation i get an error 👇
{
"errorMessage": "could not identify an equality operator for type json",
"errorType": "Hw",
"stackTrace": [
"error: could not identify an equality operator for type json",
" at /serverless-app/eosw-ts/.esbuild/.build/eosw/api/edition.js:2:12873",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async /serverless-app/eosw-ts/.esbuild/.build/eosw/api/edition.js:59:42969",
" at async EQe (/serverless-app/eosw-ts/.esbuild/.build/eosw/api/edition.js:59:63260)"
]
}
{
"errorMessage": "could not identify an equality operator for type json",
"errorType": "Hw",
"stackTrace": [
"error: could not identify an equality operator for type json",
" at /serverless-app/eosw-ts/.esbuild/.build/eosw/api/edition.js:2:12873",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async /serverless-app/eosw-ts/.esbuild/.build/eosw/api/edition.js:59:42969",
" at async EQe (/serverless-app/eosw-ts/.esbuild/.build/eosw/api/edition.js:59:63260)"
]
}
This is the query 👇
await db.query.magazines.findFirst({
where: eq(magazines.id, "faa66220-0165-48f6-9895-afdab22d160d"),
with: {
editions: true,
publisher: true,
},
});
await db.query.magazines.findFirst({
where: eq(magazines.id, "faa66220-0165-48f6-9895-afdab22d160d"),
with: {
editions: true,
publisher: true,
},
});
If i remove either editions: true or publisher: true then it works
2 replies
DTDrizzle Team
Created by Amur on 7/7/2023 in #help
Create database if not exists
Is there a way to have create a database if it not exists? After i create my schema and a run the first migration, i would expect drizzle to create a database that's specified in my connection string if it doesn't exist
3 replies