suchcodemuchwow
suchcodemuchwow
Explore posts from servers
KKysely
Created by suchcodemuchwow on 7/28/2023 in #help
Wrong return type in raw sql
Greetings I have simple aggregations on mysql:
select([
sql`COUNT(DISTINCT r.review_id)`.as("reviewCount"),
sql`COUNT(DISTINCT i.interaction_id)`.as("interactionCount"),
sql<number>`COUNT(DISTINCT r.review_id) * 4 + COUNT(DISTINCT i.interaction_id)`.as("score")
])
select([
sql`COUNT(DISTINCT r.review_id)`.as("reviewCount"),
sql`COUNT(DISTINCT i.interaction_id)`.as("interactionCount"),
sql<number>`COUNT(DISTINCT r.review_id) * 4 + COUNT(DISTINCT i.interaction_id)`.as("score")
])
Even if I specify <number> the return type is coming back as string when I check with typeof reviewCount and in other. Is there a way to typecast raw sql queries, rather than modifying the executed query results or not 🤔
7 replies
PD🧩 Plasmo Developers
Created by suchcodemuchwow on 7/16/2023 in #👾extension
Local Storage Item does not show up in service worker dev tools ?
I am saving simple key value string (id: "123") in my background script which I'm able to read it (and can console) every time but it doesn't appear on service workers Application/Local Storage I'm not sure if it's expected behaviour or not. I have checked host websites Local storage as well it doesn't show up there as well. Interesting part is that plasmo can read it magically from somewhere
23 replies
KKysely
Created by suchcodemuchwow on 7/8/2023 in #help
Does kysely convert Table names lowercase when it's building a query ?
When I try to run this code it tries to insert into "profile" table not "Profile": Note: I have only extracted important parts
// Kysely codegen output
export interface Profile {
profile_id: Generated<number>;
username: string | null;
created_at: Generated<Date | null>;
updated_at: Generated<Date | null>;
user_id: string | null;
}

// types
type ProfileTable = KeysToCamelCase<Profile>

export type SelectableProfile = Selectable<ProfileTable>
export type InsertableProfile = Insertable<ProfileTable>
export type UpdateableProfile = Updateable<ProfileTable>

export type DB = {
Profile: ProfileTable
}

// connection
export const db = new Kysely<DB>({
dialect: new PlanetScaleDialect({
host: DATABASE_HOST,
username: DATABASE_USERNAME,
password: DATABASE_PASSWORD
}),
plugins: [new CamelCasePlugin()]
})


// repo
export async function createProfile(data: InsertableProfile) {
try {
const response = await db
.insertInto("Profile")
.values(data)
.executeTakeFirst()
return response
} catch (e) {
log.error(e, "Couldn't create profile")
return null
}
}
// Kysely codegen output
export interface Profile {
profile_id: Generated<number>;
username: string | null;
created_at: Generated<Date | null>;
updated_at: Generated<Date | null>;
user_id: string | null;
}

// types
type ProfileTable = KeysToCamelCase<Profile>

export type SelectableProfile = Selectable<ProfileTable>
export type InsertableProfile = Insertable<ProfileTable>
export type UpdateableProfile = Updateable<ProfileTable>

export type DB = {
Profile: ProfileTable
}

// connection
export const db = new Kysely<DB>({
dialect: new PlanetScaleDialect({
host: DATABASE_HOST,
username: DATABASE_USERNAME,
password: DATABASE_PASSWORD
}),
plugins: [new CamelCasePlugin()]
})


// repo
export async function createProfile(data: InsertableProfile) {
try {
const response = await db
.insertInto("Profile")
.values(data)
.executeTakeFirst()
return response
} catch (e) {
log.error(e, "Couldn't create profile")
return null
}
}
4 replies