R2DBC Driver for Microsoft SQL Server using TDS (Tabular Data Stream) Protocol
Clone or download
nebhale Remove Recursive Generics
This change removes the recursive generics from this implementation to be
compliant with changes made to the SPI.  These changes were driven by the
observation that recursive generics made consumption of the API harder and no
longer provided us much value.

[r2dbc/r2dbc-spi#24]

Signed-off-by: Ben Hale <bhale@pivotal.io>
Latest commit ba8204f Jan 15, 2019

README.md

Reactive Relational Database Connectivity Microsoft SQL Server Implementation

This project contains the Microsoft SQL Server implementation of the R2DBC SPI. This implementation is not intended to be used directly, but rather to be used as the backing implementation for a humane client library to delegate to

This driver provides the following features:

  • Login with username/password with temporary SSL encryption
  • Full SSL encryption support (for e.g. Azure usage).
  • Transaction Control
  • Simple (un-cursored) execution of SQL batches
  • Execution of prepared statements
  • Execution of SQL cursored statements
  • Read support for all data types except binary types (BLOB)

Next steps:

  • Add encoding for remaining codecs (VARBINARY, XML, UDT)
  • Execution of stored procedures
  • Add support for TVP and UDTs

Maven

Both milestone and snapshot artifacts (library, source, and javadoc) can be found in Maven repositories.

<dependency>
  <groupId>io.r2dbc</groupId>
  <artifactId>r2dbc-mssql</artifactId>
  <version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>

Artifacts can bound found at the following repositories.

Repositories

<repository>
    <id>spring-snapshots</id>
    <name>Spring Snapshots</name>
    <url>https://repo.spring.io/snapshot</url>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>
<repository>
    <id>spring-milestones</id>
    <name>Spring Milestones</name>
    <url>https://repo.spring.io/milestone</url>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
</repository>

Usage

Connection Factory Discovery:

ConnectionFactoryOptions options = builder()
    .option(DRIVER, "mssql")
    .option(HOST, "")
    .option(PORT, …)  // optional, defaults to 1433
    .option(USER, "")
    .option(PASSWORD, "")
    .option(DATABASE, "") // optional
    .option(SSL, true) // optional, defaults to false
    .option(Option.valueOf("applicationName"), "") // optional
    .option(Option.valueOf("connectionId"), new UUID(…)) // optional
    .build();

ConnectionFactory connectionFactory = ConnectionFactories.get(options);

Mono<Connection> connectionMono = factory.create();

Programmatic:

MssqlConnectionConfiguration configuration = MssqlConnectionConfiguration.builder()
    .host("")
    .username("")
    .password("")
    .database("")
    .build();

MssqlConnectionFactory factory = new MssqlConnectionFactory(configuration);

Mono<MssqlConnection> connectionMono = factory.create();

Microsoft SQL Server uses named parameters that are prefixed with @. The following SQL statement makes use of parameters:

INSERT INTO person (id, first_name, last_name) VALUES(@id, @firstname, @lastname)

Parameters are referenced without the @ prefix when binding these:

connection.createStatement("INSERT INTO person (id, first_name, last_name) VALUES(@id, @firstname, @lastname)")
            .bind("id", 1)
            .bind("firstname", "Walter")
            .bind("lastname", "White")
            .execute()

Binding also allows positional index (zero-based) references. The parameter index is derived from the parameter discovery order when parsing the query.

Supported ConnectionFactory Discovery Options:

Core options:

  • driver: Must be mysql.
  • host: Server hostname to connect to.
  • port: Server port to connect to. Defaults to 1433.
  • username: Login username.
  • password: Login password.

Additional options:

  • applicationName: Name of the application. Defaults to driver name and version.
  • connectionId: Connection Id for tracing purposes. Defaults to a random Id.
  • connectTimeout: Connection Id for tracing purposes. Defaults to 30 seconds.
  • database: Initial database to select. Defaults to SQL Server user profile settings.
  • ssl: Whether to use transport-level encryption for the entire SQL server traffic, defaults to false.

License

This project is released under version 2.0 of the Apache License.