Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sgammon committed Nov 8, 2023
0 parents commit 5d4b389
Show file tree
Hide file tree
Showing 81 changed files with 7,748 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.* @sgammon
Empty file.
Empty file added .github/workflows/on.pr.yml
Empty file.
Empty file added .github/workflows/on.push.yml
Empty file.
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0-alpha1
178 changes: 178 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@

# Planetscale Connector/J

> **Note**
> Under construction; use at your own risk
This library implements a [JDBC adapter](https://www.oracle.com/database/technologies/appdev/jdbc.html) for
[Planetscale][1].

Planetscale uses [Vitess][2] as a backend, which is wire-compatible with MySQL; thus, this library is a wrapper around
the [MySQL Connector/J][3] library, which is used for the actual work of connecting and running queries.

This library adds several features, using the MySQL/J connector, to make it easier to work with Planetscale:

## Usage

> **Warning**
> This is *not* endorsed by Planetscale, and is not yet published to Maven Central.
| Coordinates | Driver |
|---------------------------------------|------------------------------|
| ```com.planetscale:planetscale-jvm``` | ```com.planetscale.Driver``` |

**Gradle (Kotlin DSL, via Version Catalogs):**
```kotlin
// in settings.gradle.kts

dependencyResolutionManagement {
versionCatalogs {
create("planetscale") {
from("com.planetscale:planetscale-catalog:(latest version)")
}
}
}
```
```kotlin
// in build.gradle.kts

dependencies {
implementation(planetscale.driver)
}
```

**Gradle (Kotlin DSL, one library at a time):**
```kotlin
dependencies {
implementation("com.planetscale:planetscale-jvm:<version>")
}
```

**Maven:**
```xml
<dependency>
<groupId>com.planetscale</groupId>
<artifactId>planetscale-jvm</artifactId>
<version><!-- use the latest version --></version>
</dependency>
```


## Features

- **Easy Planetscale connection strings.**

Use `jdbc:planetscale://aws` or `jdbc:planetscale://gcp` or connect to a specific region with something like
`jdbc:planetscale://us-east-1.aws`. The adapter builds the right URL for you. These examples become:

```
jdbc:mysql://aws.connect.psdb.cloud:3306/dbname?...
jdbc:mysql://gcp.connect.psdb.cloud:3306/dbname?...
jdbc:mysql://us-east-1.aws.connect.psdb.cloud:3306/dbname?...
```


- **Load balanced reads.**

Use more than one endpoint with URLs like: `jdbc:planetscale://us-west-1.aws..aws`. In this case, the MySQL/J driver
is configured with:

```
jdbc:mysql:replication://us-west-1.aws.connect.psdb.cloud:3306,aws.connect.psdb.cloud:3306/dbname?roundRobinLoadBalance=true&...
```


- **Eager driver cache and solid defaults.**

The Planetscale driver configures the MySQL/J driver for client-side caching of server configuration, result set
metadata, and so on. SSL verification is turned on, as is auto-reconnection. Equivalent driver options:

```
autoReconnect=true
cacheServerConfiguration=true
cacheResultSetMetadata=true
sslMode=VERIFY_IDENTITY
roundRobinLoadBalance=true
```


- **Support for Planetscale's options.**

Planetscale options like `enableBoost` can be applied to configure the underlying URL properly. For example, adding
`enableBoost=true` to the AWS sample URL above, like so: `jdbc:planetscale://aws?enableBoost=true`, becomes:

```
jdbc:mysql://aws.connect.psdb.cloud:3306/dbname?sessionVariables=boost_cached_queries=true&...
```


- **Configure credentials via env vars, properties, or connection URL.**

`PLANETSCALE_USERNAME`, `-Dplanetscale.username`, and `jdbc:planetscale://user:pass@...` are all supported, as are the
same variables for the connection password. These are consulted if no user/pass are found in the connection string.


## Integration Libraries

There are a few libraries shipped with this repo which make integration easier with various frameworks or systems:

### Micronaut Integration

Adds Micronaut Data property source support for Planetscale configuration. Effectively, the module configures itself as
a driver (when enabled), and provides connection parameters as configuration. Otherwise the driver is identical to using
the MySQL/J driver library directly.

#### Usage

**Coordinates:**
```
com.planetscale:planetscale-micronaut
```

**Maven:**
```xml
<dependency>
<groupId>com.planetscale</groupId>
<artifactId>planetscale-micronaut</artifactId>
<version><!-- use the latest version --></version>
</dependency>
```

**Gradle (Version Catalog):**
```kotlin
dependencies {
implementation(planetscale.integration.micronaut)
}
```

### GraalVM Integration

Adds metadata and a supporting feature configuration for [GraalVM][4] native image compilation. Reflection configuration
is embedded which supports both this adapter and MySQL/J.

#### Usage

**Coordinates:**
```
com.planetscale:planetscale-graalvm
```

**Maven:**
```xml
<dependency>
<groupId>com.planetscale</groupId>
<artifactId>planetscale-graalvm</artifactId>
<version><!-- use the latest version --></version>
</dependency>
```

**Gradle (Version Catalog):**
```kotlin
dependencies {
implementation(planetscale.integration.graalvm)
}
```

[1]: https://planetscale.com/
[2]: https://vitess.io/
[3]: https://dev.mysql.com/downloads/connector/j/
20 changes: 20 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.nio.charset.StandardCharsets

plugins {
alias(libs.plugins.sbom)
alias(libs.plugins.sigstore)
alias(libs.plugins.sonar)
alias(libs.plugins.nexus.publish)
alias(libs.plugins.version.check)
alias(libs.plugins.version.catalogUpdate)
}

val stamp: String by properties

group = "com.planetscale.jvm"
version = if (stamp == "true") {
// if instructed to "stamp" the output libs, include the output from `.version`
layout.projectDirectory.file(".version").asFile.readText(StandardCharsets.UTF_8).trim()
} else {
"1.0-SNAPSHOT"
}
9 changes: 9 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
`kotlin-dsl`
}

val kotlinVersion = "1.9.20"

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
38 changes: 38 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@file:Suppress(
"UnstableApiUsage",
"DSL_SCOPE_VIOLATION",
)

import build.less.plugin.settings.buildless

pluginManagement {
repositories {
maven("https://gradle.pkg.st/")
maven("https://maven.pkg.st/")
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id("build.less")
id("org.gradle.toolchains.foojay-resolver-convention")
}

buildless {
// nothing at this time
}

dependencyResolutionManagement {
repositoriesMode.set(
RepositoriesMode.FAIL_ON_PROJECT_REPOS
)
repositories {
maven("https://gradle.pkg.st/")
maven("https://maven.pkg.st/")
mavenCentral()
gradlePluginPortal()
}
}

rootProject.name = "planetscale-buildsrc"
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/PlanetscaleBuild.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.gradle.api.Project

object PlanetscaleBuild {
fun Project.publishable(name: String, description: String) {
// nothing yet
}
}
Loading

0 comments on commit 5d4b389

Please sign in to comment.