HotBBQSauce
HotBBQSauce
DTDrizzle Team
Created by HotBBQSauce on 5/8/2024 in #help
Cant insert integer into column of type json number array
export const platform = pgTable("platform", {
id: integer("id").unique().primaryKey(),
name: text("name"),
slug: text("slug"),
symbol: text("symbol"),
tokens: json("tokens").$type<number[]>(),
});
export const platform = pgTable("platform", {
id: integer("id").unique().primaryKey(),
name: text("name"),
slug: text("slug"),
symbol: text("symbol"),
tokens: json("tokens").$type<number[]>(),
});
const platformUpdateResult = await db
.update(platformSchema)
.set({ tokens: sql`${platform.tokens} || ${token.id}` })
.where(eq(platformSchema.id, token.platform))
.returning();
const platformUpdateResult = await db
.update(platformSchema)
.set({ tokens: sql`${platform.tokens} || ${token.id}` })
.where(eq(platformSchema.id, token.platform))
.returning();
this is not working
1 replies
DTDrizzle Team
Created by HotBBQSauce on 5/8/2024 in #help
I cant append new integers in a integer array
platforms: sql`ARRAY_CAT(${cryptoToken.platforms}, ARRAY['${coin.platform.id}'])`,
platforms: sql`ARRAY_CAT(${cryptoToken.platforms}, ARRAY['${coin.platform.id}'])`,
i have tried 1000000 ways but i want to append it if possible?! here is the schema:
export const cryptoToken = pgTable("crypto_token", {
id: integer("id").primaryKey(),
rank: integer("rank"),
name: text("name").notNull(),
symbol: text("symbol").notNull(),
slug: text("slug").notNull(),
is_active: integer("is_active").notNull(),
first_historical_data: text("first_historical_data"),
last_historical_data: text("last_historical_data"),
platforms: integer("platforms")
.array()
.notNull()
.default(sql`ARRAY[]::integer[]`),
});
export const cryptoToken = pgTable("crypto_token", {
id: integer("id").primaryKey(),
rank: integer("rank"),
name: text("name").notNull(),
symbol: text("symbol").notNull(),
slug: text("slug").notNull(),
is_active: integer("is_active").notNull(),
first_historical_data: text("first_historical_data"),
last_historical_data: text("last_historical_data"),
platforms: integer("platforms")
.array()
.notNull()
.default(sql`ARRAY[]::integer[]`),
});
i just want to append integers to the array when available, this errors:
const insertResult = await db
.insert(cryptoToken)
.values({
name: coin.name,
symbol: coin.symbol,
slug: coin.slug,
is_active: 1,
first_historical_data: coin.first_historical_data,
last_historical_data: coin.last_historical_data,
id: coin.id,
platforms: sql`ARRAY_CAT(${cryptoToken.platforms}, ARRAY['${coin.platform.id}'])`,
rank: coin.rank,
})
.onConflictDoUpdate({
target: cryptoToken.id,
set: {
name: coin.name,
symbol: coin.symbol,
slug: coin.slug,
is_active: 1,
first_historical_data: coin.first_historical_data,
last_historical_data: coin.last_historical_data,
platforms: sql`ARRAY_CAT(${cryptoToken.platforms}, ARRAY['${coin.platform.id}'])`,
rank: coin.rank,
},
});
const insertResult = await db
.insert(cryptoToken)
.values({
name: coin.name,
symbol: coin.symbol,
slug: coin.slug,
is_active: 1,
first_historical_data: coin.first_historical_data,
last_historical_data: coin.last_historical_data,
id: coin.id,
platforms: sql`ARRAY_CAT(${cryptoToken.platforms}, ARRAY['${coin.platform.id}'])`,
rank: coin.rank,
})
.onConflictDoUpdate({
target: cryptoToken.id,
set: {
name: coin.name,
symbol: coin.symbol,
slug: coin.slug,
is_active: 1,
first_historical_data: coin.first_historical_data,
last_historical_data: coin.last_historical_data,
platforms: sql`ARRAY_CAT(${cryptoToken.platforms}, ARRAY['${coin.platform.id}'])`,
rank: coin.rank,
},
});
4 replies
DTDrizzle Team
Created by HotBBQSauce on 4/1/2024 in #help
string array
How are string arrays defined in drizzle? It always seems to revert back to json/jsonb when defining the custom types as string[]
3 replies
DTDrizzle Team
Created by HotBBQSauce on 2/18/2024 in #help
ilike drizzle postgress
how can i disregard the order of the searchterm? im already replacing whitespaces with % with a regex but the order seems to somewhat matter for ilike? i am wondering if there is any way to have the order of each word disregarded in the queried column, it just looks if its present or not
const result = await db.query.productsInformation.findMany({
where: ilike(productsInformation.name, "%" + searchTerm + "%"),
limit: 50,
});
const result = await db.query.productsInformation.findMany({
where: ilike(productsInformation.name, "%" + searchTerm + "%"),
limit: 50,
});
30 replies
DTDrizzle Team
Created by HotBBQSauce on 1/30/2024 in #help
Enforce property requirements on drizzle-zod
export const users = pgTable("user", {
id: text("id").notNull().primaryKey(),
name: text("name"),
email: text("email").notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image"),
password: text("password"),
})
export const users = pgTable("user", {
id: text("id").notNull().primaryKey(),
name: text("name"),
email: text("email").notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image"),
password: text("password"),
})
password is an optional field,
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
import { users } from "@/drizzle/authjs_schema";

// this refers to the entire schema
const insertUserSchema = createInsertSchema(users)


const partial = insertUserSchema.pick({
email: true,
password: true,
}).required()
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
import { users } from "@/drizzle/authjs_schema";

// this refers to the entire schema
const insertUserSchema = createInsertSchema(users)


const partial = insertUserSchema.pick({
email: true,
password: true,
}).required()
shouldnt this make email and password required? in the partial schema? I have tried a couple of order different syntaxes with built in methods but nothing seem to work
11 replies