forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ledger-on-sql: PostgreSQL support. (digital-asset#4204)
* ledger-on-sql: Don't bother cleaning up after integration tests. Turns out Bazel cleans up before each test run, so we only have one set of outputs at a time. This is far more useful for debugging anyway. * ledger-on-sql: Pull out a test-lib to simplify the conformance tests. * ledger-on-sql: Turn `Database` from a sealed trait into a case class. * ledger-on-sql: Support for PostgreSQL! CHANGELOG_BEGIN CHANGELOG_END * ledger-on-sql: Run the conformance tests against PostgreSQL. * ledger-on-sql: Run the LotsOfParties conformance tests. * ledger-on-sql: Use PostgreSQL's `RETURNING` keyword to save a query. * ledger-on-sql: Ensure the reader connection pool is read-only. * ledger-on-sql: Avoid cloning ByteStrings as byte arrays where possible. Instead, use `ByteString#newInput()`, which returns an `InputStream`. This is supported by H2 and PostgreSQL, but unfortunately not SQLite. * ledger-on-sql: Run integration tests in parallel. * Update the PostgreSQL and SQLite JDBC drivers.
- Loading branch information
1 parent
020f694
commit 0be3e72
Showing
14 changed files
with
256 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
ledger/ledger-on-sql/src/main/scala/com/daml/ledger/on/sql/queries/PostgresqlQueries.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2020 The DAML Authors. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.on.sql.queries | ||
|
||
import java.sql.Connection | ||
|
||
import anorm.SqlParser._ | ||
import anorm._ | ||
import com.daml.ledger.on.sql.queries.Queries.Index | ||
import com.daml.ledger.participant.state.kvutils.DamlKvutils.DamlLogEntryId | ||
import com.google.protobuf.ByteString | ||
|
||
class PostgresqlQueries extends Queries with CommonQueries { | ||
override def createLogTable()(implicit connection: Connection): Unit = { | ||
SQL"CREATE TABLE IF NOT EXISTS log (sequence_no SERIAL PRIMARY KEY, entry_id BYTEA NOT NULL, envelope BYTEA NOT NULL)" | ||
.execute() | ||
() | ||
} | ||
|
||
override def createStateTable()(implicit connection: Connection): Unit = { | ||
SQL"CREATE TABLE IF NOT EXISTS state (key BYTEA PRIMARY KEY NOT NULL, value BYTEA NOT NULL)" | ||
.execute() | ||
() | ||
} | ||
|
||
override def insertIntoLog( | ||
entry: DamlLogEntryId, | ||
envelope: ByteString, | ||
)(implicit connection: Connection): Index = { | ||
SQL"INSERT INTO log (entry_id, envelope) VALUES (${entry.getEntryId.newInput()}, ${envelope.newInput()}) RETURNING sequence_no" | ||
.as(long("sequence_no").single) | ||
} | ||
|
||
override protected val updateStateQuery: String = | ||
"INSERT INTO state VALUES ({key}, {value}) ON CONFLICT(key) DO UPDATE SET value = {value}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.