copypaper
copypaper
DTDrizzle Team
Created by vapor on 9/12/2024 in #help
Alias join doesn't seem to work
5 replies
DTDrizzle Team
Created by vapor on 9/12/2024 in #help
Alias join doesn't seem to work
turns out the docs were wrong, just use alias instead
5 replies
DTDrizzle Team
Created by vapor on 9/12/2024 in #help
Alias join doesn't seem to work
did you figure this out? havging the same issue
5 replies
DTDrizzle Team
Created by Booboo v(=∩_∩=)フ on 4/9/2024 in #help
Wipe Neon Database
personally, i use DBeaver (an open source SQL database tool) to view and manage my tables. From there you can right click your table and click DELETE to drop it. It also is able to cascade delete if there are other tables with a foreign key to that table. Very useful and worth learning to use If you want to quickly do it though, just go on neon, select your project, then on the left click SQL editor. From there you can run sql queries. For ex, if your table is
item
item
, just type
DROP TABLE item;
DROP TABLE item;
9 replies
DTDrizzle Team
Created by Booboo v(=∩_∩=)フ on 4/9/2024 in #help
Wipe Neon Database
if you want to keep your data, check this out https://cleanspeak.com/blog/2015/09/23/postgresql-int-to-uuid
9 replies
DTDrizzle Team
Created by Booboo v(=∩_∩=)フ on 4/9/2024 in #help
Wipe Neon Database
The easiest way is to just drop the table and push again. Normally you'd manage this with migrations, but since you're prototyping, it's easier to just drop the tables and push them again
9 replies
DTDrizzle Team
Created by Marcin.B on 1/2/2024 in #help
Dynamic orderBy
jsdoc was formatting wierd with discord, but that sshould explain it hopefully
4 replies
DTDrizzle Team
Created by Marcin.B on 1/2/2024 in #help
Dynamic orderBy
/**
*
* @param qb Query builder. Must have $dynamic method.
* @param p a string that represents the column name. If it starts with a "-" it will sort in descending order. Otherwise, it will sort in ascending order.
* @param colMap A map of column names to column objects. Should be a record of string to PgColumn from your schema.
* @returns
*
* Example usage:
*
* const query = db.select().from(users).$dynamic;
* const sort = "-lastFirst"
* const columnMap: ColumnMap = {
* lastFirst: users.lastFirst, // users is a table from your schema.
* firstLast: users.firstLast,
* }
* function query = withParam(query, sort, columnMap);
* // query will order by users.lastFirst in descending order.
*
*/
/**
*
* @param qb Query builder. Must have $dynamic method.
* @param p a string that represents the column name. If it starts with a "-" it will sort in descending order. Otherwise, it will sort in ascending order.
* @param colMap A map of column names to column objects. Should be a record of string to PgColumn from your schema.
* @returns
*
* Example usage:
*
* const query = db.select().from(users).$dynamic;
* const sort = "-lastFirst"
* const columnMap: ColumnMap = {
* lastFirst: users.lastFirst, // users is a table from your schema.
* firstLast: users.firstLast,
* }
* function query = withParam(query, sort, columnMap);
* // query will order by users.lastFirst in descending order.
*
*/
4 replies
DTDrizzle Team
Created by Marcin.B on 1/2/2024 in #help
Dynamic orderBy
Hey I know this is late, but here's my solution that's working. I'm grabbing the column name off the search params
import { desc, asc } from "drizzle-orm";
import { type PgColumn, type PgSelect } from "drizzle-orm/pg-core";

type ColumnMap = Record<string, PgColumn>;

export function withParam<T extends PgSelect>(
qb: T,
p: string,
colMap: ColumnMap,
) {
const direction = p.startsWith("-") ? "desc" : "asc";
// Remove the "-" from the column name.
p = p.replace("-", "");
const col = colMap[p];
// If the column is not found, return the query builder as is.
if (!col) {
return qb;
}
if (direction === "desc") {
return qb.orderBy(desc(col));
}
return qb.orderBy(asc(col));
}
import { desc, asc } from "drizzle-orm";
import { type PgColumn, type PgSelect } from "drizzle-orm/pg-core";

type ColumnMap = Record<string, PgColumn>;

export function withParam<T extends PgSelect>(
qb: T,
p: string,
colMap: ColumnMap,
) {
const direction = p.startsWith("-") ? "desc" : "asc";
// Remove the "-" from the column name.
p = p.replace("-", "");
const col = colMap[p];
// If the column is not found, return the query builder as is.
if (!col) {
return qb;
}
if (direction === "desc") {
return qb.orderBy(desc(col));
}
return qb.orderBy(asc(col));
}
4 replies