Develop a TypeScript application that connects to a Cassandra database, creates a table for storing user information (name, email, and age), and provides functions for adding, updating, and deleting users.
PLAINFORMAT
import { Client } from 'cassandra-driver';

const client = new Client({
  contactPoints: ['127.0.0.1'],
  localDataCenter: 'datacenter1',
  keyspace: 'test_keyspace'
});

async function main() {
  await client.connect();

  // Create table
  await client.execute(`
    CREATE TABLE IF NOT EXISTS users (
      name text PRIMARY KEY,
      email text,
      age int
    )
  `);

  // Add user
  await addUser('John Doe', 'john.doe@example.com', 30);

  // Update user
  await updateUser('John Doe', 'john.doe@example.com', 31);

  // Delete user
  await deleteUser('John Doe');

  await client.shutdown();
}

async function addUser(name: string, email: string, age: number) {
  const query = 'INSERT INTO users (name, email, age) VALUES (?, ?, ?)';
  await client.execute(query, [name, email, age], { prepare: true });
  console.log(`User added: ${name}`);
}

async function updateUser(name: string, email: string, age: number) {
  const query = 'UPDATE users SET email = ?, age = ? WHERE name = ?';
  await client.execute(query, [email, age, name], { prepare: true });
  console.log(`User updated: ${name}`);
}

async function deleteUser(name: string) {
  const query = 'DELETE FROM users WHERE name = ?';
  await client.execute(query, [name], { prepare: true });
  console.log(`User deleted: ${name}`);
}

main().catch((err) => console.error(err));