Braveheart
Braveheart
Explore posts from servers
DTDrizzle Team
Created by Braveheart on 1/10/2024 in #help
Temporal custom type "TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and nul"
No description
3 replies
DTDrizzle Team
Created by Braveheart on 1/3/2024 in #help
Performing Drizzle ORM migration in vitest results in permission errors
In a test i'm using Drizzle ORM to do migrations in vitest beforeAll, but it doesn't work like when I run a script from
"db:migrate": "tsx db/migrate.ts", //runs with no issues
"db:migrate": "tsx db/migrate.ts", //runs with no issues
which then calls this
import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import { db } from './db'

import { fileURLToPath } from 'url'
import { dirname, join } from 'path'

export const migrateWrapper = async () => {
await migrate(db, { migrationsFolder: migrationsPath }) // does the actual migration
}
import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import { db } from './db'

import { fileURLToPath } from 'url'
import { dirname, join } from 'path'

export const migrateWrapper = async () => {
await migrate(db, { migrationsFolder: migrationsPath }) // does the actual migration
}
but when running in a test file I get root cause error:
// console.log('yearly-recurring-events.test.ts')
beforeAll(async () => {
await resetDatabase() //includes the migration call
await seedRecurringEvents()
})
// console.log('yearly-recurring-events.test.ts')
beforeAll(async () => {
await resetDatabase() //includes the migration call
await seedRecurringEvents()
})
Caused by: SqliteError: disk I/O error
❯ PreparedQuery.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/better-sqlite3/session.ts:103:20
❯ BetterSQLiteSession.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/session.ts:140:67
❯ SQLiteSyncDialect.migrate node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/dialect.ts:721:11
.
.
Caused by: SqliteError: disk I/O error
❯ PreparedQuery.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/better-sqlite3/session.ts:103:20
❯ BetterSQLiteSession.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/session.ts:140:67
❯ SQLiteSyncDialect.migrate node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/dialect.ts:721:11
.
.
and then results in
Migrating the database...

stderr | Module.migrateWrapper (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/db/migrateUtil.ts:19:13)
Failed to migrate the database: DrizzleError: Failed to run the query '
CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
id SERIAL PRIMARY KEY,
hash text NOT NULL,
created_at numeric
)
'
Migrating the database...

stderr | Module.migrateWrapper (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/db/migrateUtil.ts:19:13)
Failed to migrate the database: DrizzleError: Failed to run the query '
CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
id SERIAL PRIMARY KEY,
hash text NOT NULL,
created_at numeric
)
'
1 replies
DTDrizzle Team
Created by Braveheart on 12/29/2023 in #help
Extract type from drizzle join for use elsewhere or exporting
I get the type in the same function scope like so
let query = db
.select()
.from(schema.event)
.where(and(...filters))
.leftJoin(schema.recurring_pattern, eq(schema.event.id, schema.recurring_pattern.event_id))

const eventRecurringPatterns = await query.execute()
let query = db
.select()
.from(schema.event)
.where(and(...filters))
.leftJoin(schema.recurring_pattern, eq(schema.event.id, schema.recurring_pattern.event_id))

const eventRecurringPatterns = await query.execute()
eventRecurringPatterns is typed with {event ,recurring_pattern} but how do I extract this type for use in other function params? Maybe with Parameters<typeof theJoin> I want to avoid doing it manually I imagine it starts something like this screenshot
3 replies
DTDrizzle Team
Created by Braveheart on 12/27/2023 in #help
disk I/O error when running migration in context of vitest runner
I'm building a robust drizzle event selector https://github.com/quantuminformation/drizzle-sqlite-recurring-events In my test suite I am doing this:
7 replies
DTDrizzle Team
Created by Braveheart on 12/26/2023 in #help
inferSelect doesnt take into account defaults in schema
No description
13 replies
DTDrizzle Team
Created by Braveheart on 12/26/2023 in #help
value.getTime is not a function
this code in this basic repo https://github.com/quantuminformation/drizzle-sqlite-recurring-events when running pnpm run db:seed gives error
//https://github.com/quantuminformation/drizzle-sqlite-recurring-events/blob/main/db/seed.ts
const events = await db
.insert(schema.event)
.values([
{
name: 'Event 1',
startTime: new Date(2025, 1, 1, 19, 0, 0).getTime(),
endTime: new Date(2025, 1, 1, 20, 0, 0).getTime(),
},
])
.returning()
//https://github.com/quantuminformation/drizzle-sqlite-recurring-events/blob/main/db/seed.ts
const events = await db
.insert(schema.event)
.values([
{
name: 'Event 1',
startTime: new Date(2025, 1, 1, 19, 0, 0).getTime(),
endTime: new Date(2025, 1, 1, 20, 0, 0).getTime(),
},
])
.returning()
TypeError: value.getTime is not a function
at SQLiteTimestamp.mapToDriverValue (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/node_modules/.pnpm/[email protected][email protected]/node_modules/src/sqlite-core/columns/integer.ts:150:22)
TypeError: value.getTime is not a function
at SQLiteTimestamp.mapToDriverValue (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/node_modules/.pnpm/[email protected][email protected]/node_modules/src/sqlite-core/columns/integer.ts:150:22)
you can see that getTime works when debugging in vscode so I don't know where this error originates
3 replies
DTDrizzle Team
Created by Braveheart on 11/25/2023 in #help
Steps to fix errors like `drizzle/meta/0000_snapshot.json data is malformed`
No description
1 replies
DDeno
Created by Braveheart on 7/25/2023 in #help
Prisma and deno
getting this
error: could not find package '.prisma' from referrer 'file:///Users/nikos/WebstormProjects/vanillajs-patterns/backend/node_modules/.deno/@[email protected]/node_modules/@prisma/client/index.js'.
error: could not find package '.prisma' from referrer 'file:///Users/nikos/WebstormProjects/vanillajs-patterns/backend/node_modules/.deno/@[email protected]/node_modules/@prisma/client/index.js'.
from this
import { Prisma, PrismaClient } from '@prisma/client';

import { config } from 'https://deno.land/[email protected]/dotenv/mod.ts';
import * as bcrypt from 'https://deno.land/x/bcrypt/mod.ts';

const envVars = await config();

const prisma = new PrismaClient({
datasources: {
db: {
url: envVars.DATABASE_URL,
},
},
});

const seedData: Prisma.UserCreateInput[] = [
{
name: 'Tony',
passwordHash: await bcrypt.hash('password', 10),
emailVerified: true,
customFields: {
test: 'field',
},
},
{
name: 'Nikos',
passwordHash: await bcrypt.hash('password', 10),
emailVerified: true,
},
];

/**
* Seed the database.
*/

for (const u of seedData) {
const dinosaur = await prisma.user.create({
data: u,
});
console.log(`Created dinosaur with id: ${dinosaur.id}`);
}
console.log(`Seeding finished.`);

await prisma.$disconnect();
import { Prisma, PrismaClient } from '@prisma/client';

import { config } from 'https://deno.land/[email protected]/dotenv/mod.ts';
import * as bcrypt from 'https://deno.land/x/bcrypt/mod.ts';

const envVars = await config();

const prisma = new PrismaClient({
datasources: {
db: {
url: envVars.DATABASE_URL,
},
},
});

const seedData: Prisma.UserCreateInput[] = [
{
name: 'Tony',
passwordHash: await bcrypt.hash('password', 10),
emailVerified: true,
customFields: {
test: 'field',
},
},
{
name: 'Nikos',
passwordHash: await bcrypt.hash('password', 10),
emailVerified: true,
},
];

/**
* Seed the database.
*/

for (const u of seedData) {
const dinosaur = await prisma.user.create({
data: u,
});
console.log(`Created dinosaur with id: ${dinosaur.id}`);
}
console.log(`Seeding finished.`);

await prisma.$disconnect();
following https://github.com/denoland/examples/tree/main/with-prisma
22 replies
SSolidJS
Created by Braveheart on 5/22/2023 in #support
force a dom update when updating a signal before the rest of the onMount function
in this code csvColumns is dependant on setData, how can I force the render update?
const csvColumns = (
<Show when={data()}>
<For each={data()}>{(item, index) => <ConnectionTarget name={item} />}</For>
</Show>
);

onMount(() => {
const csv = `Name,Email,Age
John Doe,[email protected],30
Jane Smith,[email protected],25
Alice Johnson,[email protected],35
`;
const rows = csv.split('\n');
const firstRow = rows[0].split(',');
setData(firstRow);

//offload the line drawing
debugger;
const colsX = csvColumns.map((component) => component());
});
const csvColumns = (
<Show when={data()}>
<For each={data()}>{(item, index) => <ConnectionTarget name={item} />}</For>
</Show>
);

onMount(() => {
const csv = `Name,Email,Age
John Doe,[email protected],30
Jane Smith,[email protected],25
Alice Johnson,[email protected],35
`;
const rows = csv.split('\n');
const firstRow = rows[0].split(',');
setData(firstRow);

//offload the line drawing
debugger;
const colsX = csvColumns.map((component) => component());
});
10 replies
SSolidJS
Created by Braveheart on 5/15/2023 in #support
using the callback to <Show> and update store, results in whole store being set to new value
<Show when={'companyName' in formDataStore && formDataStore}>
{(currentDataStore) => {
return (
<Show when={'companyName' in formDataStore && formDataStore}>
{(currentDataStore) => {
return (
if I do this in form setFormDataStore({ companyDetails: { phoneNumber: e.currentTarget.value } }); then the only value in the store is as follows: causing other part to throw undefined errors
34 replies
SSolidJS
Created by Braveheart on 5/11/2023 in #support
Typesafe <Show> only when store has data
the end result I want
return (
<Show when={mockDataStore}>
{mockDataStore.prop} // don't want this to be called giving runtime errors on render when mockDataStore has empty object
return (
<Show when={mockDataStore}>
{mockDataStore.prop} // don't want this to be called giving runtime errors on render when mockDataStore has empty object
I've tried various things like createStore<StoreType | {}>({}); -> results in ts errors X doesn't exist on {} re assigning store to previous declarations
const [mockDataStore2, setMockDataStore2] = createStore<StoreType | {}>({});

mockDataStore = mockDataStore2;
setMockDataStore = setMockDataStore2;
const [mockDataStore2, setMockDataStore2] = createStore<StoreType | {}>({});

mockDataStore = mockDataStore2;
setMockDataStore = setMockDataStore2;
the easy way around this is to create store type object of just empty values until the real values come, but that just seems lame :
const mockData: StoreType = {
companyName: 'Test Company',
date: new Date(),
selectType: 'Grocery',
address: {
addressLine1: '123 Test Street',
},
};
const [mockDataStore, setMockDataStore] = createStore<StoreType | {}>(mockData);
const mockData: StoreType = {
companyName: 'Test Company',
date: new Date(),
selectType: 'Grocery',
address: {
addressLine1: '123 Test Street',
},
};
const [mockDataStore, setMockDataStore] = createStore<StoreType | {}>(mockData);
49 replies
SSolidJS
Created by Braveheart on 5/5/2023 in #support
suspense + store
if I have a form tied to a store that gets populated async, how do i use this with <suspense so i don't need loading state management
50 replies
SSolidJS
Created by Braveheart on 2/15/2023 in #support
False positive: `Make sure your app is wrapped in a <Router />` , @solidjs/router 0:7:0 - in npm lib
I have a npm component ( <O_Header) that assumes a router is wrapping it, ie, uses <A> tags wrapping the app in a router:
/* @refresh reload */
import { render } from 'solid-js/web';
import { Router } from '@solidjs/router';

import './index.css';
import { App } from './app';
render(
() => (
<Router>
<App />
</Router>
),
document.getElementById('root') as HTMLElement
);
/* @refresh reload */
import { render } from 'solid-js/web';
import { Router } from '@solidjs/router';

import './index.css';
import { App } from './app';
render(
() => (
<Router>
<App />
</Router>
),
document.getElementById('root') as HTMLElement
);
usage in the problem project
export const App: Component = () => {
return (
<>
<O_Header
NavItems={[
{ url: '/home', text: 'Home' },
]}>
<A href="/">Your logo here</A>
</O_Header>
<Routes>
<Route path="/" component={Home} />
<Route path="/users" component={Users} />
</Routes>
</>
);
};
export const App: Component = () => {
return (
<>
<O_Header
NavItems={[
{ url: '/home', text: 'Home' },
]}>
<A href="/">Your logo here</A>
</O_Header>
<Routes>
<Route path="/" component={Home} />
<Route path="/users" component={Users} />
</Routes>
</>
);
};
utils.js?v=84c27385:28 Uncaught Error: Make sure your app is wrapped in a <Router /> at invariant (utils.js?v=84c27385:28:15) at useRouter (routing.js?v=84c27385:9:32) at useRoute (routing.js?v=84c27385:11:75) at useResolvedPath (routing.js?v=84c27385:13:19) at A (components.jsx:80:16) at dev.js:524:12 at untrack (dev.js:427:12) at Object.fn (dev.js:520:37)
9 replies
SSolidJS
Created by Braveheart on 1/2/2023 in #support
Docs for debugging Solid Start
2 replies
SSolidJS
Created by Braveheart on 12/29/2022 in #support
Access dynamic route params in components outside of the FileRouter
In this structure:
<Body class="h-full bg-slate-900 text-slate-300">
<ErrorBoundary>
<Suspense fallback={<div>Loading</div>}>
<O_header />

<Routes>
<FileRoutes />
</Routes>
<O_Footer></O_Footer>
</Suspense>
</ErrorBoundary>
<Scripts />
</Body>
<Body class="h-full bg-slate-900 text-slate-300">
<ErrorBoundary>
<Suspense fallback={<div>Loading</div>}>
<O_header />

<Routes>
<FileRoutes />
</Routes>
<O_Footer></O_Footer>
</Suspense>
</ErrorBoundary>
<Scripts />
</Body>
I need the header to render the following: <A href={/${params.lang}/sign_in} class="navAction"> where lang is derived from this url http://localhost:3000/en however params.lang is undefined unless its inside a route
7 replies
SSolidJS
Created by Braveheart on 12/15/2022 in #support
SOLID svg tsc error
8 replies