Jackson Kasi
Jackson Kasi
Explore posts from servers
DTDrizzle Team
Created by Jackson Kasi on 10/22/2024 in #help
Issue: Error during `db:push` - TypeError in Drizzle Kit with PostgreSQL
#### What I've Tried: 1. Schema Inspection for CHECK Constraints: - I ran a query to check for any CHECK constraints in my PostgreSQL schema, as I suspected the error might be related to them. Here's what I found:
SELECT conname, pg_get_constraintdef(oid) as constraint_definition
FROM pg_constraint
WHERE contype = 'c';

SELECT conname, pg_get_constraintdef(oid) as constraint_definition
FROM pg_constraint
WHERE contype = 'c';

Sample results:
{
"constraint_name": "pgsodium_raw",
"schema_name": "pgsodium",
"table_name": "key",
"constraint_definition": "CHECK (CASE WHEN (raw_key IS NOT NULL) THEN ((key_id IS NULL) AND (key_context IS NULL) AND (parent_key IS NOT NULL)) ELSE ((key_id IS NOT NULL) AND (key_context IS NOT NULL) AND (parent_key IS NULL)) END)"
}

{
"constraint_name": "pgsodium_raw",
"schema_name": "pgsodium",
"table_name": "key",
"constraint_definition": "CHECK (CASE WHEN (raw_key IS NOT NULL) THEN ((key_id IS NULL) AND (key_context IS NULL) AND (parent_key IS NOT NULL)) ELSE ((key_id IS NOT NULL) AND (key_context IS NOT NULL) AND (parent_key IS NULL)) END)"
}

I suspect this (or a similar CHECK) constraint might be causing the issue. 2. Tried Downgrading/Upgrading drizzle-kit: I tried downgrading and upgrading drizzle-kit but the issue persists with the same error. 3. Checked Permissions: I also ensured that my PostgreSQL user has sufficient permissions to modify the schema and drop constraints. #### Next Steps: - Is there a known issue with drizzle-kit handling complex CHECK constraints like the one in pgsodium.key? - Should I manually drop these constraints before running db:push, or is there a workaround to handle this within Drizzle ORM? - Any insights or potential fixes from the community would be greatly appreciated! Thanks in advance for your help!
3 replies
DTDrizzle Team
Created by Jackson Kasi on 8/17/2024 in #help
Issue with drizzle-graphql Entities Not Working Well with GraphQL
3 replies
DTDrizzle Team
Created by Jackson Kasi on 8/17/2024 in #help
Issue with drizzle-graphql Entities Not Working Well with GraphQL
Please check this to reproduce the issue: https://github.com/jacksonkasi1/drizzle-graphql-lambda
3 replies
DTDrizzle Team
Created by Jackson Kasi on 8/17/2024 in #help
Help Needed: Error with Arguments in GraphQL Resolver Using Drizzle ORM, Serverless, and TypeScript
Please check this to reproduce the issue: https://github.com/jacksonkasi1/drizzle-graphql-lambda
5 replies
DTDrizzle Team
Created by Jackson Kasi on 8/17/2024 in #help
Help Needed: Error with Arguments in GraphQL Resolver Using Drizzle ORM, Serverless, and TypeScript
Hey guys, has anyone tried drizzle-graphql with custom queries? I need help or suggestions.
5 replies
DTDrizzle Team
Created by Jackson Kasi on 8/17/2024 in #help
Help Needed: Error with Arguments in GraphQL Resolver Using Drizzle ORM, Serverless, and TypeScript
Guys if need i will share code repo, i need help plz 🙏
5 replies
DTDrizzle Team
Created by Jackson Kasi on 8/17/2024 in #help
Help Needed: Error with Arguments in GraphQL Resolver Using Drizzle ORM, Serverless, and TypeScript
schema.ts:
import { GraphQLSchema, GraphQLObjectType } from "graphql";
import { userQuery } from "./modules/user/user.schema";
import { drizzleEntities } from "./db";

const query = new GraphQLObjectType({
name: "Query",
fields: {
...drizzleEntities.queries,
...userQuery.getFields(),
},
});

const mutation = new GraphQLObjectType({
name: "Mutation",
fields: {
...drizzleEntities.mutations,
},
});

export const schema = new GraphQLSchema({
query,
mutation,
types: [
...Object.values(drizzleEntities.types),
...Object.values(drizzleEntities.inputs),
],
});
import { GraphQLSchema, GraphQLObjectType } from "graphql";
import { userQuery } from "./modules/user/user.schema";
import { drizzleEntities } from "./db";

const query = new GraphQLObjectType({
name: "Query",
fields: {
...drizzleEntities.queries,
...userQuery.getFields(),
},
});

const mutation = new GraphQLObjectType({
name: "Mutation",
fields: {
...drizzleEntities.mutations,
},
});

export const schema = new GraphQLSchema({
query,
mutation,
types: [
...Object.values(drizzleEntities.types),
...Object.values(drizzleEntities.inputs),
],
});
What I’ve Tried - Logging args: I added console.log(args) inside the resolver, but it doesn’t seem to be logging anything before the error occurs. - Hardcoding authUserId: Even when I hardcode authUserId, I still receive the same error about arguments. tsconfig.json Here is my tsconfig.json for context:
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"target": "ES6",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/db/*": ["./src/db/*"],
"@/lib/*": ["./src/lib/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "src/**/*.spec.ts", "src/**/*.spec.js"]
}
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"target": "ES6",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/db/*": ["./src/db/*"],
"@/lib/*": ["./src/lib/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "src/**/*.spec.ts", "src/**/*.spec.js"]
}
Request Has anyone encountered this issue before or knows what might be causing it? Any help would be greatly appreciated! Thank you!
5 replies
KKinde
Created by Jackson Kasi on 7/16/2024 in #💻┃support
Are there guidelines for integrating Kind Auth with a React.js-based Figma plugin?
3 replies
DTDrizzle Team
Created by Jackson Kasi on 6/30/2024 in #help
Issue with Drizzle ORM and drizzle-kit push with Tembo Cloud PostgreSQL
No description
3 replies
DTDrizzle Team
Created by Jackson Kasi on 6/30/2024 in #help
Issue with Drizzle ORM and drizzle-kit push with Tembo Cloud PostgreSQL
Details: - Database: PostgreSQL on Tembo Cloud (OLTP stack) - Extension Installed: pg_stat_statements Schema Definition:
// db/user.ts
import { integer, pgTable, text, timestamp } from "drizzle-orm/pg-core";

export const tbl_users = pgTable("tbl_users", {
id: integer("id").notNull().primaryKey().unique(),
name: text("name").notNull(),
email: text("email").notNull(),
profile: text("profile"), // profile image link
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
// db/user.ts
import { integer, pgTable, text, timestamp } from "drizzle-orm/pg-core";

export const tbl_users = pgTable("tbl_users", {
id: integer("id").notNull().primaryKey().unique(),
name: text("name").notNull(),
email: text("email").notNull(),
profile: text("profile"), // profile image link
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
Drizzle Configuration:
// drizzle.config.ts
import { defineConfig } from "drizzle-kit";
import { env } from "@/config";

export default defineConfig({
schema: "./src/db",
dialect: "postgresql",
dbCredentials: {
url: env.DATABASE_URL!,
},
verbose: true,
strict: true,
out: "./drizzle",
migrations: {
table: 'drizzle_migrations',
schema: 'public',
},
tablesFilter: ['pg_stat_*'],
extensionsFilters: ["postgis"],
schemaFilter: ["public"],
});
// drizzle.config.ts
import { defineConfig } from "drizzle-kit";
import { env } from "@/config";

export default defineConfig({
schema: "./src/db",
dialect: "postgresql",
dbCredentials: {
url: env.DATABASE_URL!,
},
verbose: true,
strict: true,
out: "./drizzle",
migrations: {
table: 'drizzle_migrations',
schema: 'public',
},
tablesFilter: ['pg_stat_*'],
extensionsFilters: ["postgis"],
schemaFilter: ["public"],
});
3 replies
DTDrizzle Team
Created by Jackson Kasi on 5/11/2024 in #help
Handling Aggregated Counts with GroupBy in Drizzle ORM: Requesting Community Insights
lapsed_users_ops.ts
// ** Import DB **
import { countDistinct, db, sql } from "@/db";
import { tbl_users, tbl_usage_metrics } from "@/db/schema";

// Function to get the count of Lapsed Users (users who haven't interacted in a significant period)
export async function getLapsedUserCount() {
const lapsedThreshold = Math.floor(
(Date.now() - 30 * 24 * 60 * 60 * 1000) / 1000,
); // 30 days ago
return db
.select({ count: countDistinct(tbl_users.external_id) })
.from(tbl_users)
.leftJoin(
tbl_usage_metrics,
sql`${tbl_users.external_id} = ${tbl_usage_metrics.external_id}`,
)
.groupBy(tbl_users.external_id) // Ensuring that groupBy is used with having
.having(sql`MAX(${tbl_usage_metrics.updatedAt}) <= ${lapsedThreshold} OR MAX(${tbl_usage_metrics.updatedAt}) IS NULL`);
}

// Function to get the details of Lapsed Users (first name, last name, email)
export async function getLapsedUserDetails() {
const lapsedThreshold = Math.floor(
(Date.now() - 30 * 24 * 60 * 60 * 1000) / 1000,
); // 30 days ago
return db
.selectDistinct({
first_name: tbl_users.first_name,
last_name: tbl_users.last_name,
email: tbl_users.email,
})
.from(tbl_users)
.leftJoin(
tbl_usage_metrics,
sql`${tbl_users.external_id} = ${tbl_usage_metrics.external_id}`,
)
.groupBy(tbl_users.external_id)
.having(sql`MAX(${tbl_usage_metrics.updatedAt}) <= ${lapsedThreshold} OR MAX(${tbl_usage_metrics.updatedAt}) IS NULL`)
}
// ** Import DB **
import { countDistinct, db, sql } from "@/db";
import { tbl_users, tbl_usage_metrics } from "@/db/schema";

// Function to get the count of Lapsed Users (users who haven't interacted in a significant period)
export async function getLapsedUserCount() {
const lapsedThreshold = Math.floor(
(Date.now() - 30 * 24 * 60 * 60 * 1000) / 1000,
); // 30 days ago
return db
.select({ count: countDistinct(tbl_users.external_id) })
.from(tbl_users)
.leftJoin(
tbl_usage_metrics,
sql`${tbl_users.external_id} = ${tbl_usage_metrics.external_id}`,
)
.groupBy(tbl_users.external_id) // Ensuring that groupBy is used with having
.having(sql`MAX(${tbl_usage_metrics.updatedAt}) <= ${lapsedThreshold} OR MAX(${tbl_usage_metrics.updatedAt}) IS NULL`);
}

// Function to get the details of Lapsed Users (first name, last name, email)
export async function getLapsedUserDetails() {
const lapsedThreshold = Math.floor(
(Date.now() - 30 * 24 * 60 * 60 * 1000) / 1000,
); // 30 days ago
return db
.selectDistinct({
first_name: tbl_users.first_name,
last_name: tbl_users.last_name,
email: tbl_users.email,
})
.from(tbl_users)
.leftJoin(
tbl_usage_metrics,
sql`${tbl_users.external_id} = ${tbl_usage_metrics.external_id}`,
)
.groupBy(tbl_users.external_id)
.having(sql`MAX(${tbl_usage_metrics.updatedAt}) <= ${lapsedThreshold} OR MAX(${tbl_usage_metrics.updatedAt}) IS NULL`)
}
2 replies
DTDrizzle Team
Created by Jackson Kasi on 4/20/2024 in #help
Need Help: `ilike` Function Not Returning Expected Results in Drizzle ORM
Key Changes 1. Wildcard Usage: I added % symbols around the input.query to create searchQuery. This modification tells PostgreSQL to look for any records where the full_name contains the provided string, regardless of its position. 2. Tested Query: I tested this by passing 'jack' as the query parameter and successfully retrieved users with names like 'Jackson Kasi', confirming that the partial and case-insensitive search was working as expected. This solution adheres to the ilike function usage as described in the Drizzle ORM documentation but applies it within the context of the findMany method, ensuring that it correctly interprets the partial search strings. Thanks to everyone who took the time to look into this, and I hope this solution helps anyone else facing a similar issue!
3 replies
DTDrizzle Team
Created by Jackson Kasi on 4/20/2024 in #help
Need Help: `ilike` Function Not Returning Expected Results in Drizzle ORM
Hello Drizzle ORM Community! I’ve managed to resolve the issue with the ilike function not returning the expected results when querying user data in a TypeScript environment with PostgreSQL. The problem was that I needed to include wildcard characters % around the input string to correctly perform the case-insensitive partial search. Here's the updated code snippet that fixed the issue:
import { db, ilike } from "@repo/db";
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "../trpc";
import { tbl_users } from "@repo/db/src/schema";

export const userEmailRouter = createTRPCRouter({
getAll: protectedProcedure
.input(z.object({ query: z.string().optional().default("") }))
.query(async ({ ctx, input }) => {
// Wrap the input query with '%' for partial matching
const searchQuery = `%${input.query}%`;

const usersList = await db.query.tbl_users.findMany({
where: ilike(tbl_users.full_name, searchQuery), // Correctly format the query
columns: {
full_name: true,
email: true,
},
});

console.log({ usersList: usersList || [] });

return {
success: true,
message: "Successfully fetched users",
data: { usersList: usersList || [] },
};
}),
});
import { db, ilike } from "@repo/db";
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "../trpc";
import { tbl_users } from "@repo/db/src/schema";

export const userEmailRouter = createTRPCRouter({
getAll: protectedProcedure
.input(z.object({ query: z.string().optional().default("") }))
.query(async ({ ctx, input }) => {
// Wrap the input query with '%' for partial matching
const searchQuery = `%${input.query}%`;

const usersList = await db.query.tbl_users.findMany({
where: ilike(tbl_users.full_name, searchQuery), // Correctly format the query
columns: {
full_name: true,
email: true,
},
});

console.log({ usersList: usersList || [] });

return {
success: true,
message: "Successfully fetched users",
data: { usersList: usersList || [] },
};
}),
});
3 replies
DTDrizzle Team
Created by Jackson Kasi on 4/10/2024 in #help
Issue Querying Table via Drizzle ORM with SQLite
15 replies
DTDrizzle Team
Created by Jackson Kasi on 4/10/2024 in #help
Issue Querying Table via Drizzle ORM with SQLite
No description
15 replies
DTDrizzle Team
Created by Jackson Kasi on 4/10/2024 in #help
Issue Querying Table via Drizzle ORM with SQLite
okay then i will share the code soon!
15 replies
DTDrizzle Team
Created by Jackson Kasi on 4/10/2024 in #help
Issue Querying Table via Drizzle ORM with SQLite
Yes, those are the correct steps to reproduce the issue.
15 replies
DTDrizzle Team
Created by Jackson Kasi on 4/10/2024 in #help
Issue Querying Table via Drizzle ORM with SQLite
Even the database key, I will add it in the code! Later, I will remove the Turso DB from my account.
15 replies
DTDrizzle Team
Created by Jackson Kasi on 4/10/2024 in #help
Issue Querying Table via Drizzle ORM with SQLite
yes
15 replies