TJ
TJ
Explore posts from servers
PPrisma
Created by TJ on 11/5/2024 in #help-and-questions
How to derive a type from types generated by Prisma?
Hi, The following TypeScript code snippet is working where I'm able to derive a type X from the query result from Prisma.
const rows = await prisma.role_users.findMany({
select: {
users: {
select: {
id: true,
email: true,
},
},
roles: {
select: {
members: {
select: {
groups: {
select: {
id: true,
name: true,
},
},
},
},
},
},
},
});

type X = (typeof rows)[number]["users"] & {
roles: (typeof rows)[number]["roles"]["members"][number]["groups"][];
};
const rows = await prisma.role_users.findMany({
select: {
users: {
select: {
id: true,
email: true,
},
},
roles: {
select: {
members: {
select: {
groups: {
select: {
id: true,
name: true,
},
},
},
},
},
},
},
});

type X = (typeof rows)[number]["users"] & {
roles: (typeof rows)[number]["roles"]["members"][number]["groups"][];
};
May I know how to create the type outside of the function instead of defining the type X on runtime in the function? Something like deriving the type from the database table types generated by Prisma and etc?
2 replies
PPrisma
Created by TJ on 11/1/2024 in #help-and-questions
Does Prisma support MariaDB 10.6
https://www.prisma.io/docs/orm/reference/supported-databases mentioned MariaDB 10.0+ Does the + means 10.0.x or the versions from 10.0 (including 10.6)?
7 replies
DTDrizzle Team
Created by TJ on 10/25/2024 in #help
drizzle-kit pull from MariaDB using mysql2 driver
Hi Do you have any idea what caused this error when pnpm drizzle-kit pull from a MariaDB?
$ pnpm drizzle-kit pull
No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/user/temp/bposa360-drizzle/drizzle.config.ts'
Pulling from ['public'] list of schemas

[✓] 274 tables fetched
[✓] 3340 columns fetched
[✓] 608 indexes fetched
[✓] 330 foreign keys fetched
[⣟] 3 check constraints fetching
[✓] 5 views fetched
TypeError: Cannot read properties of undefined (reading 'checkConstraint')
at fromDatabase (/home/user/temp/bposa360-drizzle/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:18825:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[user@LAPTOP-7U5LDLH9 bposa360-drizzle]$ pnpm drizzle-kit pull
$ pnpm drizzle-kit pull
No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/user/temp/bposa360-drizzle/drizzle.config.ts'
Pulling from ['public'] list of schemas

[✓] 274 tables fetched
[✓] 3340 columns fetched
[✓] 608 indexes fetched
[✓] 330 foreign keys fetched
[⣟] 3 check constraints fetching
[✓] 5 views fetched
TypeError: Cannot read properties of undefined (reading 'checkConstraint')
at fromDatabase (/home/user/temp/bposa360-drizzle/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:18825:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[user@LAPTOP-7U5LDLH9 bposa360-drizzle]$ pnpm drizzle-kit pull
1 replies
DTDrizzle Team
Created by TJ on 8/13/2024 in #help
MariaDB support?
I see that Support MariaDB is moved to done with the description of it been released to latest on NPM. Does this means MariaDB is officially supported in the latest release? https://github.com/drizzle-team/drizzle-orm/issues/203
1 replies
DTDrizzle Team
Created by TJ on 7/17/2024 in #help
Error handling
Hi, Currently this how I handle the database error thrown from Drizzle,
try {
...
} catch (error) {
if (error.sqlMessage) {
// toast a message "There was database error, contact administrator"
} else {
...
}
}
try {
...
} catch (error) {
if (error.sqlMessage) {
// toast a message "There was database error, contact administrator"
} else {
...
}
}
Is this the correct way to check if it is a database error?
3 replies
DTDrizzle Team
Created by TJ on 6/16/2024 in #help
Conflicting peer dependency of [email protected] when installing [email protected] in Next.js 14.2.4
Hi I'm install drizzle-orm in a Next.js project initialized with [email protected]. This new project has dependency to React 18.3.1. Unfortunately, we encounter the following dependency error when install latest drizzle-orm
$ npm install drizzle-orm
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! peer react@"^18.2.0" from [email protected]
npm ERR! node_modules/next
npm ERR! next@"14.2.4" from the root project
npm ERR! peer react@"^18.3.1" from [email protected]
npm ERR! node_modules/react-dom
npm ERR! peer react-dom@"^18.2.0" from [email protected]
npm ERR! node_modules/next
npm ERR! next@"14.2.4" from the root project
npm ERR! react-dom@"^18" from the root project
npm ERR! 2 more (styled-jsx, the root project)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! drizzle-orm@"*" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/react
npm ERR! peer react@"18.2.0" from [email protected]
npm ERR! node_modules/react-native
npm ERR! peer react-native@">0.73.0" from @op-engineering/[email protected]
npm ERR! node_modules/@op-engineering/op-sqlite
npm ERR! peerOptional @op-engineering/op-sqlite@">=2" from [email protected]
npm ERR! node_modules/drizzle-orm
npm ERR! drizzle-orm@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
$ npm install drizzle-orm
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! peer react@"^18.2.0" from [email protected]
npm ERR! node_modules/next
npm ERR! next@"14.2.4" from the root project
npm ERR! peer react@"^18.3.1" from [email protected]
npm ERR! node_modules/react-dom
npm ERR! peer react-dom@"^18.2.0" from [email protected]
npm ERR! node_modules/next
npm ERR! next@"14.2.4" from the root project
npm ERR! react-dom@"^18" from the root project
npm ERR! 2 more (styled-jsx, the root project)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! drizzle-orm@"*" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/react
npm ERR! peer react@"18.2.0" from [email protected]
npm ERR! node_modules/react-native
npm ERR! peer react-native@">0.73.0" from @op-engineering/[email protected]
npm ERR! node_modules/@op-engineering/op-sqlite
npm ERR! peerOptional @op-engineering/op-sqlite@">=2" from [email protected]
npm ERR! node_modules/drizzle-orm
npm ERR! drizzle-orm@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
Do you have any idea of what could be the problem? Shall we use --force to workaround this error?
6 replies
DTDrizzle Team
Created by TJ on 5/8/2024 in #help
How to share Drizzle schema in multiple projects?
Hi, I have an Express.js application running with Drizzle ORM. The schemas are defined and migration are generated in this repository, no problem. and now I'm going to have another application written in Next.js and it is going to access the same database. How can I share the Drizzle schema in multiple projects? Currently, I'm duplicating the Drizzle's schema from the previous Express.js application repository and make sure I don't run the migration. Do you have a better suggestion?
3 replies
DTDrizzle Team
Created by TJ on 5/7/2024 in #help
How to share the transaction in multiple services?
Hi, This is more like a design question. I'm using Drizzle ORM in Express.js application. I have userService and auditService to update the database records. Before the database transaction, I basically call the services like this,
router.post('/', async (req, res) => {
userService.create('john')
auditService.log('Create user john')
})
router.post('/', async (req, res) => {
userService.create('john')
auditService.log('Create user john')
})
and then with the database transaction,
router.post('/', async (req, res) => {
await db.transaction(async (tx) => {
userService.create(tx, 'john')
auditService.log(tx, 'Create user john')
})
})
router.post('/', async (req, res) => {
await db.transaction(async (tx) => {
userService.create(tx, 'john')
auditService.log(tx, 'Create user john')
})
})
Note that in the above, I have to pass the tx transaction to every service function. Is there a more elegant way than passing the tx to every function?
3 replies
KKinde
Created by TJ on 4/26/2024 in #💻┃support
Revoke all access tokens from Kinde
Hi, May I know how to revoke all access tokens from Kinde?
2 replies
KKinde
Created by TJ on 4/25/2024 in #💻┃support
Protect Next.js route handlers with machine-to-machine application?
Hi, I want to expose the route handlers defined in Next.js 14 application for external applications to call using OAuth 2 client credentials flow. Can I do this with machine-to-machine application? I tried to get the access token like this,
curl --request POST \
--url $KINDE_ISSUER_URL/oauth/token \
--header 'content-type: application/x-www-form-urlencoded' \
--header 'accept: application/json' \
--data grant_type=client_credentials \
--data client_id=$KINDE_CLIENT_ID \
--data client_secret=$KINDE_CLIENT_SECRET \
--data audience=$KINDE_ISSUER_URL/api
curl --request POST \
--url $KINDE_ISSUER_URL/oauth/token \
--header 'content-type: application/x-www-form-urlencoded' \
--header 'accept: application/json' \
--data grant_type=client_credentials \
--data client_id=$KINDE_CLIENT_ID \
--data client_secret=$KINDE_CLIENT_SECRET \
--data audience=$KINDE_ISSUER_URL/api
but it failed with this error,
{"error":"invalid_request","error_description":"The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Requested audience 'https://xxxxx.kinde.com/api' has not been whitelisted by the OAuth 2.0 Client."}
{"error":"invalid_request","error_description":"The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Requested audience 'https://xxxxx.kinde.com/api' has not been whitelisted by the OAuth 2.0 Client."}
Do you know what could be the problem?
10 replies
DTDrizzle Team
Created by TJ on 4/24/2024 in #help
Access MariaDB in Drizzle using node-mysql2?
Hi, Drizzle ORM does not support MariaDB officially (see https://github.com/drizzle-team/drizzle-orm/pull/1692). However, I have seen discussions of using Drizzle to access MariaDB (using node-mysql2 driver). Is this recommended? Is there any compatibility issue?
4 replies
KKinde
Created by TJ on 11/28/2023 in #💻┃support
Kinde TypeScript type in Next.js middleware
Hi, With Next.js 14 and TypeScript, may I know how can I specify the type for req so that it recognizes req.kindeAuth,
export default withAuth(async function middleware(req) {
console.log("look at me", req.kindeAuth);
});
export default withAuth(async function middleware(req) {
console.log("look at me", req.kindeAuth);
});
Is there a type provided by Kinde?
2 replies