cosbgn
cosbgn
Explore posts from servers
DTDrizzle Team
Created by cosbgn on 7/5/2024 in #help
D1_ERROR: near "in": syntax error at offset 153
I can't seem to use inArray with d1:
D1_ERROR: near "in": syntax error at offset 153
D1_ERROR: near "in": syntax error at offset 153
With
const result = await db
.select()
.from(posts)
.where(
and(
inArray(posts.content, ["book"] ),
eq(posts.isActive, true)
)
)
const result = await db
.select()
.from(posts)
.where(
and(
inArray(posts.content, ["book"] ),
eq(posts.isActive, true)
)
)
Any suggestions?
2 replies
NNuxt
Created by cosbgn on 7/4/2024 in #❓・help
Is there an easy way to get `event`?
I use drizzle and cloudflare so I have an util like this one:
export const useDb = (event) => drizzle(event.context.cloudflare.env.DB, { schema })
export const useDb = (event) => drizzle(event.context.cloudflare.env.DB, { schema })
My issue is that I need always event and it's annoying to pass it around betwen functions. I know there is useEvent() but it requires an experimental asyncContext which is not available on cloudflare. How is everyone solving this?
3 replies
NNuxt
Created by cosbgn on 6/1/2024 in #❓・help
Props based on route generate hydration missmatch
// /pages/tools/[tool_slug].vue
<template>
<div>
<tool :config="tools[tool_slug]" />
</div>
</template>
<script setup>
import tools from '~/assets/templates/en.json'
const route = useRoute()
const { tool_slug } = route.params
if (!tools?.[tool_slug]?.title) {
throw createError({ statusCode:404, statusMessage:"Tool not found" })
}
</script>
// /pages/tools/[tool_slug].vue
<template>
<div>
<tool :config="tools[tool_slug]" />
</div>
</template>
<script setup>
import tools from '~/assets/templates/en.json'
const route = useRoute()
const { tool_slug } = route.params
if (!tools?.[tool_slug]?.title) {
throw createError({ statusCode:404, statusMessage:"Tool not found" })
}
</script>
I want to do something like the above. My issue is that I get a missmatch because confi is empty on server and filled in client. Is there a way to have it filled also on server?
8 replies
NNuxt
Created by cosbgn on 5/24/2024 in #❓・help
get `event` in `/utils/db.js` - Can I be done?
I would like to do something like this:
// utils/db.js
import { drizzle } from 'drizzle-orm/d1';
import * as schema_file from "../db/schema.js";

let cached_db = null

export const useDb = () => {
if (!cached_db) {
const event = useRequestEvent()
cached_db = drizzle(event.context.cloudflare.env.D1_PROD_BINDING, { schema: schema_file })
}
return cached_db
}

export const db = useDb()
export const schema = schema_file
// utils/db.js
import { drizzle } from 'drizzle-orm/d1';
import * as schema_file from "../db/schema.js";

let cached_db = null

export const useDb = () => {
if (!cached_db) {
const event = useRequestEvent()
cached_db = drizzle(event.context.cloudflare.env.D1_PROD_BINDING, { schema: schema_file })
}
return cached_db
}

export const db = useDb()
export const schema = schema_file
So then in any route I can do db.select() - However useRequestEvent() is not defined somehow? I know I can simply pass const db = useDb(event) on top of each route, I just would like to avoid passing event on every route and hopefully get better types. Should this instead be a plugin? What's the best practice here?
2 replies
NNuxt
Created by cosbgn on 5/3/2024 in #❓・help
Did anyone manage to handle CORS with h3/nuxt/nitro?
I'm trying everything like this:
export default defineEventHandler( async (event) => {
const cors_headers = {
origin: '*',
preflight: { statusCode: 204 },
methods: '*'
}
await handleCors(event, cors_headers)
await appendCorsHeaders(event, cors_headers)
await appendResponseHeaders(event, {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, HEAD, POST, OPTIONS",
"Access-Control-Allow-Headers": "*"
})
return "hello"
})
export default defineEventHandler( async (event) => {
const cors_headers = {
origin: '*',
preflight: { statusCode: 204 },
methods: '*'
}
await handleCors(event, cors_headers)
await appendCorsHeaders(event, cors_headers)
await appendResponseHeaders(event, {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, HEAD, POST, OPTIONS",
"Access-Control-Allow-Headers": "*"
})
return "hello"
})
I always get: request blocked: (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
15 replies
DTDrizzle Team
Created by cosbgn on 4/18/2024 in #help
Cannot read properties of null (reading 'dialect')
await migrate(db, { migrationsFolder: "server/db/migrations" }) is failing. I'm using d1. What could be the issue?
1 replies
CDCloudflare Developers
Created by cosbgn on 4/10/2024 in #pages-help
Mailchannels: sender is not authorized
I'm getting:
0 "Failed to send email: 550 5.7.1 This sender is not authorized to send from my-site.com. See https://bit.ly/domain-lockdown. cfid=my-site-v3.pages.dev"
0 "Failed to send email: 550 5.7.1 This sender is not authorized to send from my-site.com. See https://bit.ly/domain-lockdown. cfid=my-site-v3.pages.dev"
I have a TXT record with: name: _mailchannels
value: =mc1 cfid=my-site-v3.pages.dev (copied as is from error message) --- Do I need to just wait for DNS to catch up, or am I missing something?
6 replies
NNuxt
Created by cosbgn on 4/5/2024 in #❓・help
error loading dynamically imported module
No description
1 replies
DTDrizzle Team
Created by cosbgn on 4/3/2024 in #help
How do you deal with migrations? on postbuild?
So, usually while developing locally, whenever I change my schema I run:
drizzle-kit generate:sqlite
// and then
node ./server/db/migrate.js
drizzle-kit generate:sqlite
// and then
node ./server/db/migrate.js
This first generates the migrations and then applies them to my local db. Once I deploy in my package.json postbuild script I have:
postbuild:"node ./server/db/migrate.js"
postbuild:"node ./server/db/migrate.js"
So if my build runs without issues, it will apply the migrations to my production DB. Is this correct?
1 replies
DTDrizzle Team
Created by cosbgn on 3/13/2024 in #help
How do I mark "migration as applied" after using "push"?
I've been using push for a while, now my migrations don't work anymore because:
[ResponseError: error executing a request on the primary: table `actions` already exists in CREATE TABLE `actions`
[ResponseError: error executing a request on the primary: table `actions` already exists in CREATE TABLE `actions`
10 replies
DTDrizzle Team
Created by cosbgn on 3/13/2024 in #help
returning with onConflictDoUpdate - How do I know if it was updated?
If I do:
await db.insert(users)
.values({ id: 1, name: 'Dan' })
.onConflictDoUpdate({ target: users.id, set: { name: 'John' } })
await db.insert(users)
.values({ id: 1, name: 'Dan' })
.onConflictDoUpdate({ target: users.id, set: { name: 'John' } })
Without returning I know if the row was added or edited, but I don't get the ID - With returning, I get the id but I don't know if it was created or just updated. Any way to know both?
1 replies
DTDrizzle Team
Created by cosbgn on 2/27/2024 in #help
Do I need to cache `createClient`?
I use turso on the edge (CF Workers). I see a lot of implementations do something like this:
let cached_db = null
export const useDb = () => {
if (!cached_db){
const client = createClient({ url, authToken })
cached_db = drizzle(client, { schema:schema_file })
}
return cached_db
}
// And then use it like:
const db = useDb()
let cached_db = null
export const useDb = () => {
if (!cached_db){
const client = createClient({ url, authToken })
cached_db = drizzle(client, { schema:schema_file })
}
return cached_db
}
// And then use it like:
const db = useDb()
Is that the right approach? Or can I simply do:
const client = createClient({ url, authToken })
export const db = drizzle(client, { schema:schema_file })
const client = createClient({ url, authToken })
export const db = drizzle(client, { schema:schema_file })
Like can I call createClient() hundreds of times without issues or I should actually cache it?
1 replies
DTDrizzle Team
Created by cosbgn on 1/25/2024 in #help
Why do I need to duplicate names in my schema?
For example:
name: text('name').notNull(),
name: text('name').notNull(),
Why do I need name twice? I can easily forget to update one or another creating a mess, like name: text('old_name') Any way to avoid it?
2 replies
DDeno
Created by cosbgn on 1/22/2024 in #help
Subhosting API protection
Is there a way to setup custom auth via some header for example for all subhosting routes? I.e. Deno will throw an error is Authorization!=="foo"?
2 replies
NNuxt
Created by cosbgn on 1/19/2024 in #❓・help
Do I need to use "lazy" with `useFetch/useAsyncData` when deploying to vercel?
So before I used to have a fully static fronted (nuxt-generate) and a backend API. Now with nuxt3 this got blurred. When I deploy to vercel (without changing any config), nuxt still builds the frontend fully static and backend is lambdas right? Meaning it's all generated at build time, which means I always have to use lazy right?
13 replies
CDCloudflare Developers
Created by cosbgn on 11/12/2023 in #workers-help
Rewrite traffic based on hostname
I'm building a site with custom domains. I would like to have my base domain (base-example.com) render normally, but IF hostname !== base-example.com I want to render the content of base-example.com/api/custom-content?host=some-hostname.com - How can I do that? I use workers, but could switch to pages if needed.
2 replies
CDCloudflare Developers
Created by cosbgn on 10/25/2023 in #pages-help
does cloudflare pages cache workers?
Can I be sure that my backend functions are not cached? They return different data depending on the logged in user.
1 replies
CDCloudflare Developers
Created by cosbgn on 10/21/2023 in #workers-help
How to set `logpush=true` without `wrangler.toml`
I use nuxt.js which automatically builds the app for cloudflare pages. This is great, however I do not have access to a wrangler.toml file. Is there any way to set logpush=true without a wrangler file?
2 replies
CDCloudflare Developers
Created by cosbgn on 8/30/2023 in #general-help
Best tool for long lasting background work? (e.g. 15 mins)
I have an app which runs on cloudflare pages. This means that my backend runs on workers on the edge, and have a 30 second timeout. Is there a tool in cloudflare, which allows me to run a specific worker/function for longer? like 15 minutes? It doesn't need to return anything, it needs just to compute something and save it in the database.
4 replies
NNuxt
Created by cosbgn on 8/12/2023 in #❓・help
Use wrangler as a dev server in localhost
I currently deploy on vercel-edge (cf workers), since this is a special environment many libraries don't work there. I would like to emulate the edge while using nuxt dev. I currently use: npm run build && npx wrangler pages dev dist/ --port 3000 This works perfectly as a preview, but I always need to generate and run a new build. Would it be possible to use wrangler with nuxt dev?
5 replies