rodrigo
rodrigo
Explore posts from servers
DTDrizzle Team
Created by rodrigo on 4/24/2024 in #help
classes to access db
Is this code possible? Copilot says it's valid but I cannot find it in the documentation
import { Model, STRING } from 'drizzle-orm';

class Organization extends Model {
static table = 'organizations';
static fields = {
id: {
type: STRING,
primaryKey: true,
},
name: {
type: STRING,
required: true,
},
};
}
...

async function createOrganization(name: string, adminUserId: string) {
const organization = new Organization();
organization.name = name;
organization.id = id;
await organization.save();
return organization;
}
import { Model, STRING } from 'drizzle-orm';

class Organization extends Model {
static table = 'organizations';
static fields = {
id: {
type: STRING,
primaryKey: true,
},
name: {
type: STRING,
required: true,
},
};
}
...

async function createOrganization(name: string, adminUserId: string) {
const organization = new Organization();
organization.name = name;
organization.id = id;
await organization.save();
return organization;
}
5 replies
DTDrizzle Team
Created by rodrigo on 7/22/2023 in #help
Insert multiple rows + onConflictDoUpdate
Is it possible to insert multiple rows (array) and at the same time using the onConflictDoUpdate? I'm trying it out but I get this error:
TypeError: Cannot read properties of undefined (reading 'name')
at ghh5w224esf.js:70758:77
at Array.flatMap (<anonymous>)
at SQLiteAsyncDialect.buildUpdateSet (ghh5w224esf.js:70757:36)
at SQLiteInsert.onConflictDoUpdate (ghh5w224esf.js:70637:186)
at D1_DB.pushCourse (ghh5w224esf.js:79896:65)
at OrgCourseService.insertCoursesFromNtnIntoD1 (ghh5w224esf.js:79874:36)
at async action2 (ghh5w224esf.js:58503:35)
at async callRouteActionRR (ghh5w224esf.js:3315:16)
at async callLoaderOrAction (ghh5w224esf.js:2436:16)
at async submit2 (ghh5w224esf.js:2080:25) {
stack: TypeError: Cannot read properties of undefined (re…16)
at async submit2 (ghh5w224esf.js:2080:25),
message: Cannot read properties of undefined (reading 'name')
}
TypeError: Cannot read properties of undefined (reading 'name')
at ghh5w224esf.js:70758:77
at Array.flatMap (<anonymous>)
at SQLiteAsyncDialect.buildUpdateSet (ghh5w224esf.js:70757:36)
at SQLiteInsert.onConflictDoUpdate (ghh5w224esf.js:70637:186)
at D1_DB.pushCourse (ghh5w224esf.js:79896:65)
at OrgCourseService.insertCoursesFromNtnIntoD1 (ghh5w224esf.js:79874:36)
at async action2 (ghh5w224esf.js:58503:35)
at async callRouteActionRR (ghh5w224esf.js:3315:16)
at async callLoaderOrAction (ghh5w224esf.js:2436:16)
at async submit2 (ghh5w224esf.js:2080:25) {
stack: TypeError: Cannot read properties of undefined (re…16)
at async submit2 (ghh5w224esf.js:2080:25),
message: Cannot read properties of undefined (reading 'name')
}
4 replies
DTDrizzle Team
Created by rodrigo on 7/12/2023 in #help
Error when deploying migrations with GH Action in Cloudflare D!
I'm trying to run migrations within a turborepo against a Cloudflare D1 instance. The command to run is this: wrangler d1 migrations apply d1_turbolang --preview I can run it from local (VS code) but when put it into an Github Action I get this error

Run pnpm preview:d1:migrations:apply

> @turbolang/root@ preview:d1:migrations:apply /home/runner/work/turbolang/turbolang
> pnpm --filter remix-admin preview:d1:migrations:apply


> @turbolang/remix-admin@ preview:d1:migrations:apply /home/runner/work/turbolang/turbolang/apps/remix-admin
> wrangler d1 migrations apply d1_turbolang --preview

▲ [WARNING] Processing wrangler.toml configuration:
--------------------
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
🚧 To give feedback, visit https://discord.gg/cloudflaredev
--------------------

undefined
/home/runner/work/turbolang/turbolang/apps/remix-admin:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @turbolang/remix-admin@ preview:d1:migrations:apply: `wrangler d1 migrations apply d1_turbolang --preview `
Exit status 1
 ELIFECYCLE  Command failed with exit code 1.
Error: Process completed with exit code 1.

Run pnpm preview:d1:migrations:apply

> @turbolang/root@ preview:d1:migrations:apply /home/runner/work/turbolang/turbolang
> pnpm --filter remix-admin preview:d1:migrations:apply


> @turbolang/remix-admin@ preview:d1:migrations:apply /home/runner/work/turbolang/turbolang/apps/remix-admin
> wrangler d1 migrations apply d1_turbolang --preview

▲ [WARNING] Processing wrangler.toml configuration:
--------------------
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
🚧 To give feedback, visit https://discord.gg/cloudflaredev
--------------------

undefined
/home/runner/work/turbolang/turbolang/apps/remix-admin:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @turbolang/remix-admin@ preview:d1:migrations:apply: `wrangler d1 migrations apply d1_turbolang --preview `
Exit status 1
 ELIFECYCLE  Command failed with exit code 1.
Error: Process completed with exit code 1.
The code in GH Action is :
- name: Deploying migrations to Staging
if: ${{ github.ref == 'refs/heads/dev' }}
run: pnpm preview:d1:migrations:apply
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Deploying migrations to Staging
if: ${{ github.ref == 'refs/heads/dev' }}
run: pnpm preview:d1:migrations:apply
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Any ideas what might be wrong?
6 replies