feat: Working channel enumeration

This commit is contained in:
April Hall 2025-02-05 18:18:39 -05:00
parent abecae1fee
commit 8d5e00e64a
Signed by: arithefirst
GPG Key ID: 4508A15C4DB91C5B
3 changed files with 31 additions and 3 deletions

View File

@ -28,6 +28,17 @@ async function storeMessage(client: cassandra.Client, channelName: string, conte
}
}
async function getChannels(client: cassandra.Client): Promise<cassandra.types.Row[] | undefined> {
try {
const res = await client.execute(`SELECT table_name FROM system_schema.tables WHERE keyspace_name = 'channels'`);
return res.rows;
} catch (e) {
// @ts-expect-error I don't like this thing yelling at me
console.log(`Error fetching channels: ${e.message}`);
return;
}
}
async function getMessages(client: cassandra.Client, channelName: string, limit: number): Promise<cassandra.types.Row[] | undefined> {
try {
const res = await client.execute(
@ -65,4 +76,4 @@ try {
process.exit(1);
}
export { client, createChannel, getMessages, storeMessage };
export { client, createChannel, getChannels, getMessages, storeMessage };

View File

@ -0,0 +1,15 @@
import { getChannels, client } from '$lib/server/db';
import type { LayoutServerLoad } from './$types';
export const load: LayoutServerLoad = async () => {
const rows = await getChannels(client);
const channels: string[] = rows
? rows.map((value) => {
return value.table_name;
})
: [];
return {
channels,
};
};

View File

@ -1,9 +1,11 @@
<script lang="ts">
import '../app.css';
import type { LayoutProps } from './$types';
import MainLayout from '$lib/components/mainLayout.svelte';
let { children } = $props();
let { data, children }: LayoutProps = $props();
const channels: string[] = [];
console.log(data.channels);
const channels = data.channels;
</script>
<MainLayout {channels}>