Blåhaj
Blåhaj
Explore posts from servers
KKysely
Created by Blåhaj on 8/7/2023 in #help
Migrate beyond 9 (to `10-...`)
No description
5 replies
KKysely
Created by Blåhaj on 7/28/2023 in #help
Using `.orderBy` in JSON
Hey, I have a schema that roughly looks like this
export interface Member {
id: string;

activity: {
messages: number;
};
}
export interface Member {
id: string;

activity: {
messages: number;
};
}
and I want to query the db like that it gives me the top 10 Members with the highest activity.messages count. I figured out how I can orderBy but not inside of a json.
31 replies
KKysely
Created by Blåhaj on 7/13/2023 in #help
Deleting multiple rows at once
I have a question, if I have like
await db
.deleteFrom('person')
.where('groupId', '=', id)
.execute();
await db
.deleteFrom('person')
.where('groupId', '=', id)
.execute();
would that delete ALL persons that have that groupId, or just one of them?
5 replies
KKysely
Created by Blåhaj on 6/25/2023 in #help
JSON in columns (postgresql)
Hey <a:YA_Wave:743393941369651201> I am completely new to using SQL databases and have a (hopefully) simple question. I want to store JSON inside a column and want to make certain keys not null and/or set a default value, how would I do that? In this case, I have a language column and want to set a default value for the locale key This is my UserTable type:
export interface UserTable {
_id: Generated<Buffer>
userId: string;

language: {
locale: string;
// other things
};

created_at: ColumnType<Date, string, never>
}
export interface UserTable {
_id: Generated<Buffer>
userId: string;

language: {
locale: string;
// other things
};

created_at: ColumnType<Date, string, never>
}
This is the current state of my migrations/0-initials.ts
import { ColumnDefinitionBuilder, Kysely, sql } from "kysely";

export async function up(db: Kysely<any>): Promise<void> {

await db.schema
.createTable("users")
.addColumn("_id", sql`binary(16)`, (col: ColumnDefinitionBuilder) => col.primaryKey().defaultTo(sql`(uuid_to_bin(uuid()))`))
.addColumn("userId", "varchar(40)", (col) => col.notNull().unique())

// how would I add a default value to 'language.locale' ?
.addColumn("language", "json", (col) => col)

.execute();

}
import { ColumnDefinitionBuilder, Kysely, sql } from "kysely";

export async function up(db: Kysely<any>): Promise<void> {

await db.schema
.createTable("users")
.addColumn("_id", sql`binary(16)`, (col: ColumnDefinitionBuilder) => col.primaryKey().defaultTo(sql`(uuid_to_bin(uuid()))`))
.addColumn("userId", "varchar(40)", (col) => col.notNull().unique())

// how would I add a default value to 'language.locale' ?
.addColumn("language", "json", (col) => col)

.execute();

}
(stripped things away that are not needed for this post) Thanks love
10 replies