• Stars
    star
    291
  • Rank 137,386 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TDS 7.2+ (Microsoft SQL Server) driver for Rust

Tiberius

crates.io docs.rs Cargo tests Chat

A native Microsoft SQL Server (TDS) client for Rust.

Goals

  • A perfect implementation of the TDS protocol.
  • Asynchronous network IO.
  • Independent of the network protocol.
  • Support for latest versions of Linux, Windows and macOS.

Non-goals

  • Connection pooling (use bb8, mobc, deadpool or any of the other asynchronous connection pools)
  • Query building
  • Object-relational mapping

Supported SQL Server versions

Version Support level Notes
2022 Tested on CI
2019 Tested on CI
2017 Tested on CI
2016 Should work
2014 Should work
2012 Should work
2008 Should work
2005 Should work With feature flag tds73 disabled.

Feature flags

Flag Description Default
tds73 Support for new date and time types in TDS version 7.3. Disable if using version 7.2. enabled
native-tls Use operating system's TLS libraries for traffic encryption. enabled
rustls Use the builtin TLS implementation from rustls instead of linking to the operating system implementation for traffic encryption. disabled
vendored-openssl Statically link against OpenSSL instead of dynamically linking to the operating system implementation for traffic encryption. disabled
chrono Read and write date and time values using chrono's types. (for greenfield, using time instead of chrono is recommended) disabled
time Read and write date and time values using time crate types. disabled
rust_decimal Read and write numeric/decimal values using rust_decimal's Decimal. disabled
bigdecimal Read and write numeric/decimal values using bigdecimal's BigDecimal. disabled
sql-browser-async-std SQL Browser implementation for the TcpStream of async-std. disabled
sql-browser-tokio SQL Browser implementation for the TcpStream of Tokio. disabled
sql-browser-smol SQL Browser implementation for the TcpStream of smol. disabled
integrated-auth-gssapi Support for using Integrated Auth via GSSAPI disabled

Supported protocols

Tiberius does not rely on any protocol when connecting to an SQL Server instance. Instead the Client takes a socket that implements the AsyncRead and AsyncWrite traits from the futures-rs crate.

Currently there are good async implementations for TCP in the async-std, Tokio and Smol projects.

To be able to use them together with Tiberius on Windows platforms with SQL Server, you should make sure that the TCP protocol is enabled, as depending on the edition, this may not be the case. Standard and Enterprise editions will have the setting enabled by default, whereas Developer, Express editions and the Windows Internal Database feature of the Windows Server OS don't. To enable the TCP/IP protocol you may want to use the server settings the command line. In the official Docker image TCP is is enabled by default.

Named pipes should work by using the NamedPipeClient from the latest Tokio versions.

The shared memory protocol is not documented and seems there are no Rust crates implementing it.

Encryption (TLS/SSL)

Tiberius can be set to use two different implementations of TLS connection encryption. By default it uses native-tls, linking to the TLS library provided by the operating system. This is a good practice and in case of security vulnerabilities, upgrading the system libraries fixes the vulnerability in Tiberius without a recompilation. On Linux we link against OpenSSL, on Windows against schannel and on macOS against Security Framework.

Alternatively one can use the rustls feature flag to use the Rust native TLS implementation. This way there are no dynamic dependencies to the system. This might be useful in certain installations, but requires a rebuild to update to a new TLS version. For some reasons the Security Framework on macOS does not work with SQL Server TLS settings, and on Apple platforms if needing TLS it is recommended to use rustls instead of native-tls. The other option is to use the vendored-openssl feature flag, that statically links against the latest OpenSSL implementation.

The crate can also be compiled without TLS support, but not with both features enabled at the same time.

Tiberius has three runtime encryption settings:

Encryption level Description
Required All traffic is encrypted. (default)
Off Only the login procedure is encrypted.
NotSupported None of the traffic is encrypted.

The encryption levels can be set when connecting to the database.

Integrated Authentication (TrustedConnection) on *nix

With the integrated-auth-gssapi feature enabled, the crate requires the GSSAPI/Kerberos libraries/headers installed:

  • CentOS
  • Arch
  • Debian (you need the -dev packages to build)
  • Ubuntu
  • NixOS: Run nix-shell shell.nix on the repository root.
  • Mac: as of version 0.4.2 the libgssapi crate used for this feature now uses Apple's GSS Framework which ships with MacOS 10.14+.

Additionally, your runtime system will need to be trusted by and configured for the Active Directory domain your SQL Server is part of. In particular, you'll need to be able to get a valid TGT for your identity, via kinit or a keytab. This setup varies by environment and OS, but your friendly network/system administrator should be able to help figure out the specifics.

Redirects

With certain Azure firewall settings, a login might return Error::Routing { host, port }. This means the user must create a new TcpStream to the given address, and connect again.

A simple connection procedure would then be:

use tiberius::{Client, Config, AuthMethod, error::Error};
use tokio_util::compat::TokioAsyncWriteCompatExt;
use tokio::net::TcpStream;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut config = Config::new();

    config.host("0.0.0.0");
    config.port(1433);
    config.authentication(AuthMethod::sql_server("SA", "<Mys3cureP4ssW0rD>"));

    let tcp = TcpStream::connect(config.get_addr()).await?;
    tcp.set_nodelay(true)?;

    let client = match Client::connect(config, tcp.compat_write()).await {
        // Connection successful.
        Ok(client) => client,
        // The server wants us to redirect to a different address
        Err(Error::Routing { host, port }) => {
            let mut config = Config::new();

            config.host(&host);
            config.port(port);
            config.authentication(AuthMethod::sql_server("SA", "<Mys3cureP4ssW0rD>"));

            let tcp = TcpStream::connect(config.get_addr()).await?;
            tcp.set_nodelay(true)?;

            // we should not have more than one redirect, so we'll short-circuit here.
            Client::connect(config, tcp.compat_write()).await?
        }
        Err(e) => Err(e)?,
    };

    Ok(())
}

Security

If you have a security issue to report, please contact us at [email protected]

More Repositories

1

prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
TypeScript
36,195
star
2

prisma1

πŸ’Ύ Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB) [deprecated]
Scala
16,608
star
3

prisma-examples

πŸš€ Ready-to-run Prisma example projects
TypeScript
5,760
star
4

studio

πŸŽ™οΈ The easiest way to explore and manipulate your data in all of your Prisma projects.
1,722
star
5

prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
TypeScript
1,466
star
6

prisma-engines

πŸš‚ Engine components of Prisma ORM
Rust
1,095
star
7

docs

πŸ“š Prisma Documentation
MDX
940
star
8

migrate

Issues for Prisma Migrate are now tracked at prisma/prisma. This repo was used to track issues for Prisma Migrate Experimental and is now deprecated.
TypeScript
766
star
9

quaint

SQL Query AST and Visitor for Rust
Rust
583
star
10

lens

πŸ”¬ Prisma design system
TypeScript
287
star
11

language-tools

🌐 Prisma Language Tools = Language Server and Prisma's VS Code extension.
TypeScript
243
star
12

awesome-links

Users browse through a list of curated links and bookmark their favorite ones. Code for prisma.io course.
TypeScript
199
star
13

ecosystem-tests

πŸ₯ΌπŸ§¬πŸ§ͺπŸ”¬πŸ§«πŸ¦  - Continuously tests Prisma Client with various operating systems, frameworks, platforms, databases and more.
JavaScript
180
star
14

database-schema-examples

Database Schema Examples we strive to support in Prisma
TSQL
171
star
15

dataguide

πŸ—„οΈ Prisma's Data Guide - A growing library of articles focused on making databases more approachable.
MDX
142
star
16

prisma-client-extensions

Examples of Prisma Client extensions.
TypeScript
130
star
17

blog-backend-rest-api-nestjs-prisma

A simple backend REST API for a blog built using NestJS, Prisma, PostgreSQL and Swagger.
TypeScript
130
star
18

prisma-test-utils

A collection of data model agnostic test utils.
TypeScript
111
star
19

blogr-nextjs-prisma

TypeScript
107
star
20

specs

⚠ This repository is not actively used any more, please check out the Prisma Documentation for updated information on Prisma. ⚠
Go
87
star
21

fullstack-prisma-nextjs-blog

Fullstack Blog with Next.js and Prisma
TypeScript
85
star
22

extension-read-replicas

Prisma Client Extension to add read replica support to your Prisma Client
TypeScript
84
star
23

deployment-example-vercel

Prisma deployment to Vercel example
JavaScript
74
star
24

text-editors

TypeScript
73
star
25

faunadb-rust

FaundaDB client for Rust
Rust
62
star
26

prisma-templates

Prisma templates for major cloud providers
52
star
27

prisma1-upgrade

Prisma 1 Upgrade is a CLI tool to help Prisma 1 users upgrade to Prisma 2.x or newer.
TypeScript
51
star
28

try-prisma

TypeScript
45
star
29

women-world-wide

JavaScript
41
star
30

codemods

A Collection of Codemods for Prisma 2
JavaScript
34
star
31

vim-prisma

Prisma support for Vim
Vim Script
32
star
32

nestjs-workshop-prisma-day-22

REST API for a rudimentary blog - from Prisma Day 22 NestJS workshop
TypeScript
25
star
33

prisma-nuxt

Prisma example showing how to use Prisma in a Nuxt application.
Vue
25
star
34

engines-wrapper

🌯 @prisma/engines-version npm package
TypeScript
20
star
35

accelerate-speed-test

TypeScript
18
star
36

deployment-example-netlify

Prisma deployment to Netlify example
JavaScript
16
star
37

quickstart

🏁 Starter templates for the 5min Quickstart in the Prisma docs.
JavaScript
16
star
38

prisma-edge-functions

TypeScript
15
star
39

studio-vercel-guide

A guide to deploying Studio alongside your app on Vercel
JavaScript
13
star
40

prisma-fmt-wasm

πŸ’Ύ Build and release automation for @prisma/prisma-fmt-wasm
Shell
12
star
41

ent

An entity layer for Prisma 1 that uses the DataMapper pattern.
TypeScript
12
star
42

connection-string

connection-string + @pimeys/connection-string
Rust
12
star
43

reflector

πŸͺž Utilities for meta-level interactions with the Prisma toolkit in Node.js.
TypeScript
12
star
44

engine-images

πŸ–ΌοΈ Build & test images for Prisma engines.
Shell
11
star
45

prisma-client-extension-starter

Starter template repository for building publishable Prisma Client extensions
TypeScript
10
star
46

prisma1-json-schema

JSON schema of prisma.yml files
TypeScript
10
star
47

eslint-config-prisma

🧹 Prisma's .eslintrc as an extensible shared config.
JavaScript
10
star
48

templates

Prisma templates packaged up for programatic consumption.
TypeScript
10
star
49

styles

Shared style resources between Graphcool projects
CSS
9
star
50

demo-sveltekit

Demo app for Sveltekit article
Svelte
8
star
51

pris.ly

Prisma shortlink service (hosted on Vercel)
7
star
52

prisma1-examples

TypeScript
7
star
53

prisma2-development-environment

This project combines prisma2, lift and photonjs into one workspace, builds and installs all dependencies for you.
TypeScript
7
star
54

sublimeText3

Sublime Text 3 package supporting syntax highlighting.
6
star
55

migrate-from-sequelize-to-prisma

A migration guide from Sequelize to Prisma example
JavaScript
6
star
56

pulse-starter

A Pulse starter project. To be used inside of a railway.app template, locally, or with another Pulse-ready database.
TypeScript
6
star
57

opentls

TLS connections for Rust using OpenSSL
Rust
6
star
58

prisma-admin-custom-components

Examples of custom components for Prisma Admin
JavaScript
6
star
59

prisma-content-feedback

Feedback for documentation, articles, tutorials, examples, ...
6
star
60

prisma-admin-feedback

Feedback for Prisma Admin (currently in invite-only preview)
6
star
61

prisma-1-cloud-feedback

Feedback for Prisma Cloud
5
star
62

migrate-from-typeorm-to-prisma

TypeScript
5
star
63

binding-argument-transform

A library to make Prisma 1 arguments compatible with Prisma 2.
TypeScript
5
star
64

pulse-starter-old

A starter project to get you up and running with pulse.
TypeScript
4
star
65

nextjs-edge-functions

Demo of using Next.js with Prisma ORM deployed to Vercel Edge Functions
TypeScript
4
star
66

prisma-day

Prisma Day Code of Conduct
4
star
67

prisma-read-replica-middleware

TypeScript
4
star
68

prisma-platformatic

Prisma πŸ’š Platformatic exploration
JavaScript
4
star
69

p1-to-p2-upgrade-path-feedback

4
star
70

presskit

Presskit for Prisma
3
star
71

deployment-example-cloudflare-workers

Cloudflare workers deployment example
TypeScript
3
star
72

prisma-example-starter-template

3
star
73

metrics-tutorial-prisma

Database Metrics with Prisma, Prometheus & Grafana
TypeScript
3
star
74

tech-writer-task-template

This repository is a template for Technical Writer candidates to use.
JavaScript
3
star
75

read-replicas-demo

TypeScript
2
star
76

pulse-railway-pg-config

A railway.app project template. Contains a Pulse ready postgres database and set up service. Read more about pulse
TypeScript
2
star
77

db-push-non-idempotent-schemas

Collection of schemas that don't roundtrip if you db pull, then db push
Nix
2
star
78

prisma-indexes

TypeScript
2
star
79

prisma-fundamentals

An Instruqt lab to introduce students to the Prisma Schema
Shell
2
star
80

.github

Org level configuration for installed GitHub apps
2
star
81

benching_setup

TypeScript
2
star
82

migrate-from-mongoose-to-prisma

JavaScript
1
star
83

prisma-client-lib-go

Runtime of Prisma (v1) Go Client.
Go
1
star
84

fivetran-npm-downloads

Python
1
star
85

fullstack-prisma-turso

TypeScript
1
star
86

accelerate-nextjs-starter

TypeScript
1
star
87

fullstack-prisma-turso-embedded-db

TypeScript
1
star
88

ci-reports

Repository for various reports from pull requests
HTML
1
star
89

pulse-resend-demo

TypeScript
1
star
90

deployment-example-lambda-serverless-framework

TypeScript
1
star
91

language-tools-gitpod

Shell
1
star
92

test-vercel-access

HTML
1
star
93

client-planning

Placeholder repository for client planning tickets
1
star
94

action-node-cache-dependencies

Install and cache node modules.
1
star
95

docs-tools

Python
1
star
96

orm-cloudflare-worker-list-binaries

A cloudflare worker to list the contents of the `prisma-builds` bucket
TypeScript
1
star
97

tracing-tutorial-prisma

Reference code for "Get Started With Tracing Using OpenTelemetry and Prisma Tracing".
TypeScript
1
star
98

react-native-prisma

TypeScript
1
star
99

pdp-spike-nextjs-opentelemetry

TypeScript
1
star