Giter Site home page Giter Site logo

expressots / scylladb-driver-old Goto Github PK

View Code? Open in Web Editor NEW
16.0 5.0 0.0 204 KB

The ScyllaDB driver for Node.js written in C++ πŸš€

Home Page: https://www.scylladb.com/

License: MIT License

Dockerfile 2.74% C++ 42.12% Python 3.15% Shell 40.16% TypeScript 6.10% JavaScript 5.73%
scylladb scylladb-driver nodejs

scylladb-driver-old's Introduction

ScyllaDB Driver

The native ScyllaDB Driver wrapper made by @ExpressoTS Team for the Node.js community β€πŸš€.

Getting Started

First, make sure you have the driver properly installed.

Connecting to a Cluster

Before we can start executing any queries against a Cassandra cluster we need to setup an instance of Cluster. As the name suggests, you will typically have one instance of Cluster for each Cassandra cluster you want to interact with.

Connecting to Cassandra

The simplest way to create a Cluster is like this:

import { Cluster } from "scylladb-driver"

const cluster = new Cluster();

This will attempt to connection to a Cassandra instance on your local machine (127.0.0.1). You can also specify a list of IP addresses for nodes in your cluster:

import { Cluster } from "scylladb-driver"

const cluster = new Cluster({
  nodes: ["192.168.0.1", "192.168.0.2"]
});

The set of IP addresses we pass to the Cluster is simply an initial set of contact points. After the driver connects to one of these nodes it will automatically discover the rest of the nodes in the cluster and connect to them, so you don’t need to list every node in your cluster.

If you need to use a non-standard port, use SSL, or customize the driver’s behavior in some other way, this is the place to do it:

import { Cluster } from "scylladb-driver"

const cluster = new Cluster({
  nodes: ["192.168.0.1", "192.168.0.2"],
  port: 1234,
  sslContext: // TODO: Understand what would this be.
});

Instantiating a Cluster does not actually connect us to any nodes. To establish connections and begin executing queries we need a Session, which is created by calling the connect() method from the Cluster class.

import { Cluster } from "scylladb-driver"

const cluster = new Cluster();
const session = cluster.connect();

Session keyspace

The connect() method takes an optional keyspace argument which sets the default keyspace for all queries made through that Session:

import { Cluster } from "scylladb-driver"

const cluster = new Cluster();
const session = cluster.connect("keyspace");

You can always change a Session’s keyspace using setKeyspace() or by executing a USE <keyspace> query:

const keyspace = "keyspace"
session.setKeyspace(keyspace);
// Or you can do this instead
session.query(`USE ${keyspace}`);

Executing Queries

Now that we have a Session we can begin to execute queries. The simplest way to execute a query is to use execute():

type UserTable = {
  name: string;
  age: number;
  email: string;
};

const rows: UserTable = session.execute("SELECT name, age, email FROM users");
rows.forEach(({ name, age, email }) => {
  console.log(`${name}, ${age}, ${email}`);
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.