feat: Setup Apache Cassandra

This commit is contained in:
April Hall 2025-01-08 17:44:20 -05:00
parent 3754648362
commit 881ddd1648
No known key found for this signature in database
GPG Key ID: A49AC35CB186266C
4 changed files with 18 additions and 13 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -11,9 +11,7 @@
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"format": "prettier --write .", "format": "prettier --write .",
"lint": "prettier --check . && eslint .", "lint": "prettier --check . && eslint ."
"db:migrate": "drizzle-kit generate --config drizzle.config.ts && drizzle-kit push --config drizzle.config.ts",
"db:studio": "drizzle-kit studio"
}, },
"devDependencies": { "devDependencies": {
"@eslint/compat": "^1.2.3", "@eslint/compat": "^1.2.3",
@ -21,7 +19,6 @@
"@sveltejs/kit": "^2.0.0", "@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0", "@sveltejs/vite-plugin-svelte": "^4.0.0",
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.20",
"drizzle-kit": "^0.22.0",
"eslint": "^9.7.0", "eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0", "eslint-plugin-svelte": "^2.36.0",
@ -38,10 +35,9 @@
}, },
"dependencies": { "dependencies": {
"@types/express": "^5.0.0", "@types/express": "^5.0.0",
"cassandra-driver": "^4.7.2",
"daisyui": "^4.12.23", "daisyui": "^4.12.23",
"drizzle-orm": "^0.33.0",
"express": "^4.21.2", "express": "^4.21.2",
"postgres": "^3.4.4",
"socket.io": "^4.8.1", "socket.io": "^4.8.1",
"socket.io-client": "^4.8.1", "socket.io-client": "^4.8.1",
"tsm": "^2.3.0" "tsm": "^2.3.0"

View File

@ -1,6 +1,15 @@
import { drizzle } from 'drizzle-orm/postgres-js'; import cassandra from 'cassandra-driver';
import postgres from 'postgres';
import { env } from '$env/dynamic/private'; const client = new cassandra.Client({
if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set'); contactPoints: ['localhost'],
const client = postgres(env.DATABASE_URL); localDataCenter: 'datacenter1',
export const db = drizzle(client); keyspace: 'users',
});
// Connect to Cassandra/ScyllaDB and create
// necessary tables, keyspaces, etc
await client.connect();
await client.execute(`CREATE KEYSPACE IF NOT EXISTS users WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};`);
await client.execute(`CREATE KEYSPACE IF NOT EXISTS channels WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};`);
export default client;

View File

@ -1,6 +1,6 @@
import { Server as SocketIOServer } from 'socket.io'; import { Server as SocketIOServer } from 'socket.io';
import type { HttpServer } from 'vite'; import type { HttpServer } from 'vite';
import { type TypeMessage } from './'; import client from './server/db/';
let io: SocketIOServer | undefined; let io: SocketIOServer | undefined;