1 unstable release

new 0.1.0 Oct 21, 2024

#817 in Database interfaces

Apache-2.0 OR MIT

115KB
2.5K SLoC

dbcrossbar_trino: A lightweight Trino interface for dbcrossbar and related tools

Documentation

This crate is a support crate shared by dbcrossbar and related tools. It provides:

  • Tools for working around limitations of various Trino connectors
    • Tools for listing which features are supported by a given Trino connector.
    • Tools for translating common Trino data types to "storage" types that are supported by a given connector.
  • A simple Trino client, intended for testing.
  • A dynamic representation of Trino values, and the ability to format them as SQL.
  • Other miscellaneous utilities that are useful for working with Trino.

You are welcome to use this crate outside of dbcrossbar if you find it useful. We plan to obey semver. But the features supported by this crate will be driven largely by dbcrossbar and related tools.

For more information, see the documentation.


lib.rs:

This is an interface for working with the Trino database, written for use by dbcrossbar and related tools.

Features

These may be selected at compile-time, using features = ["feature-name"] in your Cargo.toml. If you don't specify any features, this library is extremely lightweight.

  • values: Provides a Value enum that can represent a subset of Trino's values. This pulls in dependencies for lots of things, including geodata, decimals, JSON and UUIDs.
  • proptest: Support for testing using the proptest crate. This pulls in proptest and related libraries.
  • client: A basic Trino REST client. This is mostly intended for testing, and does not currently attempt to be a production-quality client. It currently has no HTTPS or password support. This pulls in a full-fledged async HTTP stack.

What this library provides

This is a bit of a grab-bag of types and utilities, driven by the common needs of several related tools.

Storage transforms

This is the heart of the library. This library exists because Trino doesn't store any data itself. Instead, it delegates storage to connectors. And these connectors expose nearly all the limitations of the underlying storage system. They're often missing key data types, or don't support NOT NULL, or don't support transactions. The following types help generate code that works around these limitations:

  • ConnectorType is the main entry point to this part of the library, providing an API to describe a connector's limitations. See this section for example code!
  • StorageTransform describes how to transform data when storing it using a specific connector, and when reading it back.

Basic utility types

These are included mostly because they're needed by other parts of the library.

  • DataType and Field, which describe a subset of available data types in Trino.
  • Ident, which represents and prints a simple Trino identifier.
  • QuotedString, which formats a quoted and escaped string.
  • TableOptions, which represents the WITH clause of a CREATE TABLE statement.

Values (requires the values feature)

  • Value represents a subset of Trino's values.
  • IsCloseEnoughTo is a trait for comparing values that knows about the limitations of Trino's connectors.

Other features

  • crate::proptest (requires the proptest feature) provides tools for generating random values for testing.
  • crate::client (requires the client feature) provides a basic Trino client.

Dependencies

~0.1–13MB
~168K SLoC