Michael Francis
Michael Francis
Explore posts from servers
DTDrizzle Team
Created by Michael Francis on 11/19/2024 in #help
Query API Returned Structure
Is there a way to change the structure of the result of the query API. Here's an example showing what it currently does, and what I'd like to do.
const result = await db.query.tableGame.findFirst({
with: {
gameCategories: true,
},
});
console.log();

// The current result type is
const result: {
userId: string | null;
createdAt: number;
updatedAt: number;
deletedAt: number | null;
gameId: string;
title: string;
publisher: string;
numberOfPlayers: number;
playtime: number;
coverImageUrl: string | null;
gameCategories: {
createdAt: number;
updatedAt: number;
deletedAt: number | null;
gameId: string | null;
categoryId: string | null;
gameCategoryId: string;
}[];
} | undefined

// is there an easy way to make it do this
const result: {
game: {
userId: string | null;
createdAt: number;
updatedAt: number;
deletedAt: number | null;
gameId: string;
title: string;
publisher: string;
numberOfPlayers: number;
playtime: number;
coverImageUrl: string | null;
}
gameCategories: {
createdAt: number;
updatedAt: number;
deletedAt: number | null;
gameId: string | null;
categoryId: string | null;
gameCategoryId: string;
}[];
} | undefined
const result = await db.query.tableGame.findFirst({
with: {
gameCategories: true,
},
});
console.log();

// The current result type is
const result: {
userId: string | null;
createdAt: number;
updatedAt: number;
deletedAt: number | null;
gameId: string;
title: string;
publisher: string;
numberOfPlayers: number;
playtime: number;
coverImageUrl: string | null;
gameCategories: {
createdAt: number;
updatedAt: number;
deletedAt: number | null;
gameId: string | null;
categoryId: string | null;
gameCategoryId: string;
}[];
} | undefined

// is there an easy way to make it do this
const result: {
game: {
userId: string | null;
createdAt: number;
updatedAt: number;
deletedAt: number | null;
gameId: string;
title: string;
publisher: string;
numberOfPlayers: number;
playtime: number;
coverImageUrl: string | null;
}
gameCategories: {
createdAt: number;
updatedAt: number;
deletedAt: number | null;
gameId: string | null;
categoryId: string | null;
gameCategoryId: string;
}[];
} | undefined
2 replies
DDeno
Created by Michael Francis on 10/4/2024 in #help
VSCode JavaScript Debug Terminal
In some projects we have lots of cli scripts we run. Setting up vscode tasks for each one is a bit annoying. Is there anyway to take advantage of the JavaScript Debug Terminal in VS Code?
1 replies
DDeno
Created by Michael Francis on 5/1/2024 in #help
KV watch prefix?
Is there a way to watch a prefix. I would like to be able to watch for any record added to a specific key prefix.
export async function logData(jsonObject: Object) {
const timestamp = Date.now();
const id = nanoid();
try {
console.log("set", timestamp, id);
await kv.set(["dev-logs", timestamp, id], jsonObject);
console.log("done set");
} catch (error) {
console.error(error);
}
}
export async function logData(jsonObject: Object) {
const timestamp = Date.now();
const id = nanoid();
try {
console.log("set", timestamp, id);
await kv.set(["dev-logs", timestamp, id], jsonObject);
console.log("done set");
} catch (error) {
console.error(error);
}
}
I want to be able to
const newLogs = kv.watch([["dev-logs]])
const newLogs = kv.watch([["dev-logs]])
And now I have an iterator that I can watch any new logs added.
1 replies