liveBook · Manning

Database driver

As explained in ScyllaDB in Action

A database driver is client software that implements the protocol and programming interface an application uses to communicate with a database.

A database driver is a software library that lets an application connect to a database and run queries. Drivers are language-specific: ScyllaDB supports Python, Java, Go, C/C++, and Rust. A Python API can use the Scylla driver to expose database-backed HTTP endpoints without requiring API users to know the schema or write queries. section 10.0 section 10.2

A connection starts by installing the driver, creating a Cluster with a node hostname and port, and connecting to a keyspace. The resulting session executes queries and returns rows. An ExecutionProfile controls behaviors such as row formatting and query routing. section 10.2 section 10.7

(scylladbia-env) $ pip3 install scylla-driver==3.26.4
...
Successfully installed geomet-0.2.1.post1 pyyaml-6.0.1 scylla-driver-3.26.4
    six-1.16.0

Install the pinned Python Scylla driver dependency before creating the application connection. section 10.2

Use prepared statements for queries that receive application data. Prepare the query once, bind values when executing it, and reuse it across requests. This keeps query values separate from the query text and helps prevent injection attacks. BatchStatement supports a batch query when writing related article data to several tables. section 10.4.2 section 10.7

Returning a restaurant review

An article endpoint obtains a session, executes a prepared SELECT for an article ID, and formats returned values for the HTTP response. Dates become strings, while image sets become lists because Flask cannot automatically serialize the set returned by the driver. section 10.4.2 section 10.4.4

The driver also translates between database and application types. Basic values such as strings, integers, and lists are handled by default. For a user-defined type such as an image, register a matching Python dataclass so the driver can serialize it for writes and deserialize it for reads. section 10.4.4

Driver configuration affects production behavior. Token-aware routing directs a query toward the shard owning its partition; a datacenter-aware round-robin policy then selects among nodes. Speculative retries can issue another attempt for a slow query, but only when that query is explicitly marked idempotent; extra retries trade more load for potentially faster responses. section 10.5.2 section 10.5.3

Figure 10.6 Round-robin routing rotates through the nodes in the cluster, whereas token-aware routing can send requests directly to the shard that owns the partition.
figure

Compare round-robin routing across nodes with token-aware routing toward the shard that owns a partition. section 10.5.2

When the cluster requires authentication, give the driver credentials through an authentication provider. A missing or invalid credential prevents the application from connecting. Keep production credentials in a secure secret provider rather than hard-coding them in application code. section 10.6.3

How ScyllaDB in Action covers it

How deep it goes
Explains installation, Cluster and session setup, prepared queries, type mapping, routing, retries, and authentication through runnable Python patterns.
Examples
Uses a Flask restaurant-review API, article queries and writes, an Image dataclass, routing policies, and credentialed cluster setup.
What it assumes
Assumes a Python Flask application and a ScyllaDB cluster while introducing driver installation and connection setup from zero.
What you can do after
Apply it via the Python Scylla driver to connect an API, execute prepared queries, map types, and configure routing or authentication.
How it connects
Connects prepared statements, batch statements, user-defined types, consistency, load balancing, speculative retries, authentication, and authorization.

Also explained in

Compare how 4 books explain database driver →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.