feat: Working channel enumeration
This commit is contained in:
parent
abecae1fee
commit
8d5e00e64a
@ -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 };
|
||||
|
15
src/routes/+layout.server.ts
Normal file
15
src/routes/+layout.server.ts
Normal 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,
|
||||
};
|
||||
};
|
@ -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}>
|
||||
|
Loading…
Reference in New Issue
Block a user