tcurdt
tcurdt
Explore posts from servers
DTDrizzle Team
Created by tcurdt on 5/29/2024 in #help
schema validation enforcement
const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
email: text('email').notNull(),
role: text('role', { enum: ['admin', 'user'] }).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
});
const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
email: text('email').notNull(),
role: text('role', { enum: ['admin', 'user'] }).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
});
The above schema is nice and well - but how can I enforce that email actually only allows to store strings that are emails? So I looked at drizzle-zod but it looks like I would have to define the schema twice?
const insertUserSchema = createInsertSchema(users, {
id: (schema) => schema.id.positive(),
email: (schema) => schema.email.email(),
role: z.string(),
});
const insertUserSchema = createInsertSchema(users, {
id: (schema) => schema.id.positive(),
email: (schema) => schema.email.email(),
role: z.string(),
});
There is no way to attach this to the table schema itself? What about using postgres constraints? https://www.postgresql.org/docs/current/ddl-constraints.html
1 replies
HHono
Created by tcurdt on 5/24/2024 in #help
[solved] HtmlEscapedString not rendering?
When I have this function
import { HtmlEscapedString } from 'hono/utils/html'

async function render (c): Promise<HtmlEscapedString> {
return c.html(<button>FOO</button>)
}
import { HtmlEscapedString } from 'hono/utils/html'

async function render (c): Promise<HtmlEscapedString> {
return c.html(<button>FOO</button>)
}
Why would this not render?
.get('/', async (c) => {
return c.html(
<BaseLayout>
button: {await render(c)}
</BaseLayout>
)
.get('/', async (c) => {
return c.html(
<BaseLayout>
button: {await render(c)}
</BaseLayout>
)
3 replies
HHono
Created by tcurdt on 5/24/2024 in #help
validating arrays coming from forms
The following code works
<form
action='?'
hx-delete='foo'
hx-target='#list'
>
<ul>
{state.foo.map(item => (
<li
id={`foo-${item.id}`}
key={item.id}>

{item.name} ({item.id})

<input type='checkbox' name="foo[]" value={item.id} />
</li>
))}
</ul>

<button type='submit' name='delete'>Delete Selected</button>
</form>


.delete('/foos', zValidator('form', z.object({
'foos[]': z.coerce.number().array(),
delete: z.string().optional()
})), async (c) => {
const { 'foos[]': foos } = c.req.valid('form')
<form
action='?'
hx-delete='foo'
hx-target='#list'
>
<ul>
{state.foo.map(item => (
<li
id={`foo-${item.id}`}
key={item.id}>

{item.name} ({item.id})

<input type='checkbox' name="foo[]" value={item.id} />
</li>
))}
</ul>

<button type='submit' name='delete'>Delete Selected</button>
</form>


.delete('/foos', zValidator('form', z.object({
'foos[]': z.coerce.number().array(),
delete: z.string().optional()
})), async (c) => {
const { 'foos[]': foos } = c.req.valid('form')
But it feels a little clunky. Is there a nicer way of doing this?
1 replies
HHono
Created by tcurdt on 5/24/2024 in #help
[solved] return type of request handler
Why is 1) is fine and 2) has a type problem? 1)
.get('/foo', async (c) => {
return await c.html(<body/>)
})
.get('/foo', async (c) => {
return await c.html(<body/>)
})
2)
.get('/bar', async (c) => {
return await render(c)
})

async function render(c) : Promise<HtlEscapedString> {
return await c.html(<body/>)
}
.get('/bar', async (c) => {
return await render(c)
})

async function render(c) : Promise<HtlEscapedString> {
return await c.html(<body/>)
}
I don't see it
8 replies
HHono
Created by tcurdt on 5/24/2024 in #help
[solved] route param validation with zod
.delete('/foo/:id', zValidator('param', z.object({
id: z.number()
})), async (c) => {
const { id } = c.req.valid('param')
.delete('/foo/:id', zValidator('param', z.object({
id: z.number()
})), async (c) => {
const { id } = c.req.valid('param')
This is rejecting /foo/1 - shouldn't this work?
8 replies
CDCloudflare Developers
Created by tcurdt on 2/27/2024 in #pages-help
Cloudflare pages very slow
Cloudflare has become very(!) slow for me. Before I was just proxying my VPS. To remove this from the equation I moved the site(s) directly to Cloudflare pages. Unfortunately this did not help much. Sometimes I am still looking at only 40-100Kbytes/sec for some images. It takes so long that Lighthouse times out. I tried from various locations. What is going on? How can I track down this down?
ab -n 10 https://torstencurdt.com/
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking torstencurdt.com (be patient).....done


Server Software: cloudflare
Server Hostname: torstencurdt.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-ECDSA-CHACHA20-POLY1305,256,256
Server Temp Key: ECDH X25519 253 bits
TLS Server Name: torstencurdt.com

Document Path: /
Document Length: 18823 bytes

Concurrency Level: 1
Time taken for tests: 5.435 seconds
Complete requests: 10
Failed requests: 0
Total transferred: 195598 bytes
HTML transferred: 188230 bytes
Requests per second: 1.84 [#/sec] (mean)
Time per request: 543.523 [ms] (mean)
Time per request: 543.523 [ms] (mean, across all concurrent requests)
Transfer rate: 35.14 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 332 339 12.8 336 375
Processing: 173 204 38.4 194 284
Waiting: 163 194 39.1 181 276
Total: 508 543 39.9 531 618

Percentage of the requests served within a certain time (ms)
50% 531
66% 534
75% 569
80% 603
90% 618
95% 618
98% 618
99% 618
100% 618 (longest request)
ab -n 10 https://torstencurdt.com/
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking torstencurdt.com (be patient).....done


Server Software: cloudflare
Server Hostname: torstencurdt.com
Server Port: 443
SSL/TLS Protocol: TLSv1.2,ECDHE-ECDSA-CHACHA20-POLY1305,256,256
Server Temp Key: ECDH X25519 253 bits
TLS Server Name: torstencurdt.com

Document Path: /
Document Length: 18823 bytes

Concurrency Level: 1
Time taken for tests: 5.435 seconds
Complete requests: 10
Failed requests: 0
Total transferred: 195598 bytes
HTML transferred: 188230 bytes
Requests per second: 1.84 [#/sec] (mean)
Time per request: 543.523 [ms] (mean)
Time per request: 543.523 [ms] (mean, across all concurrent requests)
Transfer rate: 35.14 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 332 339 12.8 336 375
Processing: 173 204 38.4 194 284
Waiting: 163 194 39.1 181 276
Total: 508 543 39.9 531 618

Percentage of the requests served within a certain time (ms)
50% 531
66% 534
75% 569
80% 603
90% 618
95% 618
98% 618
99% 618
100% 618 (longest request)
7 replies
DTDrizzle Team
Created by tcurdt on 7/19/2023 in #help
accessing results of a select
I am confused. Based on this docs https://orm.drizzle.team/docs/crud this here
const todos = await db
.select({
id: todosTable.id,
completed: todosTable.completed,
description: todosTable.description,
title: todosTable.title,
})
.from(todosTable);
console.log(todos);
const todos = await db
.select({
id: todosTable.id,
completed: todosTable.completed,
description: todosTable.description,
title: todosTable.title,
})
.from(todosTable);
console.log(todos);
todos should be an array of objects. But it seems to be
SQLiteSelect {
_: {
selectedFields: {
id: [SQLiteInteger],
completed: [SQLiteInteger],
description: [SQLiteText],
title: [SQLiteText]
}
},
config: {
...
SQLiteSelect {
_: {
selectedFields: {
id: [SQLiteInteger],
completed: [SQLiteInteger],
description: [SQLiteText],
title: [SQLiteText]
}
},
config: {
...
What am I missing?
9 replies