Titan
Titan
Explore posts from servers
DTDrizzle Team
Created by Titan on 11/4/2024 in #help
pgTable This overload is deprecated. Use the other method overload instead.
No description
4 replies
DTDrizzle Team
Created by Titan on 6/28/2024 in #help
Multiple FROM support (word_similarity) fuzzy search
I'm trying to create this SQL:
SELECT *, similarity
FROM "app-user", word_similarity('test query', "fullName" || "email") as similarity
WHERE similarity > 0.3
ORDER BY similarity DESC
SELECT *, similarity
FROM "app-user", word_similarity('test query', "fullName" || "email") as similarity
WHERE similarity > 0.3
ORDER BY similarity DESC
Here's what I have, but Drizzle doesn't like the sql${user}: Your "id" field references a column "app-user"."id", but the table "app-user" is not part of the query! Did you forget to join it?
const columnQuery = [user.fullName, user.email]
.map((column: string) => `${column}`)
.join(' || ')

const rows = await db
.select({ ...userReturnSensitiveColumns, similarity: true })
.from(sql`${user}, word_similarity(${searchQuery}, ${columnQuery}) as similarity`)
.where(
searchQuery ? sql`similarity > 0.3` : undefined)
)
.orderBy(
searchQuery ? desc('similarity') : undefined
)
const columnQuery = [user.fullName, user.email]
.map((column: string) => `${column}`)
.join(' || ')

const rows = await db
.select({ ...userReturnSensitiveColumns, similarity: true })
.from(sql`${user}, word_similarity(${searchQuery}, ${columnQuery}) as similarity`)
.where(
searchQuery ? sql`similarity > 0.3` : undefined)
)
.orderBy(
searchQuery ? desc('similarity') : undefined
)
1 replies
DTDrizzle Team
Created by Titan on 5/31/2024 in #help
Not possible to add a new column to schema with drizzle migrate push (pg)
I'm adding a new column to my schema and running drizzle-kit push connecting to a postgres db It never adds the new column. However if the new column contains a foreign key constraint it will attempt to add that, but will of course fail because the column hasn't been created. This has never worked in the few months I've been using drizzle kit, perhaps I'm missunderstanding the purpose of push? Does it not handle column level modificatons only new tables?
1 replies
DTDrizzle Team
Created by Titan on 4/26/2024 in #help
Return type is only "with" types, ignores "columns" types
Not sure if I'm using it wrong but the return type of a relational query is just the columns from the "with" clause, and doesn't merge with the "columns" object like I'd expect
3 replies
DTDrizzle Team
Created by Titan on 4/8/2024 in #help
Insert returning api to match select columns
No description
8 replies
DTDrizzle Team
Created by Titan on 2/28/2024 in #help
Type for schema when creating db client
import { BetterSQLite3Database, drizzle } from 'drizzle-orm/better-sqlite3'

import { drizzle as drizzleLibSQL, LibSQLDatabase } from 'drizzle-orm/libsql'

import * as schema from '~/server/database/schema'

let _db: BetterSQLite3Database | LibSQLDatabase | null = null

export const useDB = () => {
if (!_db) {
_db = drizzleLibSQL(
createLibSQLClient({
url: process.env.TURSO_DB_URL,
authToken: process.env.TURSO_DB_TOKEN
}),
{ schema }
)
import { BetterSQLite3Database, drizzle } from 'drizzle-orm/better-sqlite3'

import { drizzle as drizzleLibSQL, LibSQLDatabase } from 'drizzle-orm/libsql'

import * as schema from '~/server/database/schema'

let _db: BetterSQLite3Database | LibSQLDatabase | null = null

export const useDB = () => {
if (!_db) {
_db = drizzleLibSQL(
createLibSQLClient({
url: process.env.TURSO_DB_URL,
authToken: process.env.TURSO_DB_TOKEN
}),
{ schema }
)
I get the following typescript error whenever I try to include { schema } into my db creation: ``` Type 'LibSQLDatabase<typeof import("server/database/schema")>' is not assignable to type 'BetterSQLite3Database | LibSQLDatabase<Record<string, never>> | null'. Type 'LibSQLDatabase<typeof import("server/database/schema")>' is not assignable to type 'LibSQLDatabase<Record<string, never>>'. The types of '.schema' are incompatible between these types. Type 'ExtractTablesWithRelations<typeof import("server/database/schema")> | undefined' is not assignable to type 'ExtractTablesWithRelations<Record<string, never>> | undefined'. Type 'ExtractTablesWithRelations<typeof import("server/database/schema")>' is not assignable to type 'ExtractTablesWithRelations<Record<string, never>>'. Property 'todos' is incompatible with index signature. Type '{ tsName: "todos"; dbName: "todos"; columns: { id: SQLiteColumn<{ name: "id"; tableName: "todos"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>; userId: SQLiteColumn<...>; title: SQLiteColumn<....' is not assignable to type '{ tsName: string; dbName: never; columns: never; relations: Record<string, Relation<string>>; primaryKey: AnyColumn[]; }'. Types of property 'dbName' are incompatible. Type 'string' is not assignable to type 'never'.```
10 replies