-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for duplicate column names (#21)
* add support for duplicate column names * add more sqlite data conversions * improve ci * improve ci * typo fix
- Loading branch information
1 parent
4b6bcf4
commit 2b7b24c
Showing
6 changed files
with
175 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,92 @@ | ||
name: test | ||
on: | ||
- pull_request | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
defaults: | ||
run: | ||
shell: bash | ||
jobs: | ||
sqlite-nio_bionic: | ||
container: | ||
image: vapor/swift:5.2-bionic | ||
dependents: | ||
runs-on: ubuntu-latest | ||
container: swift:5.2-bionic | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
dependent: | ||
- sqlite-kit | ||
- fluent-sqlite-driver | ||
steps: | ||
- run: apt update -y; apt install -y libsqlite3-dev | ||
- uses: actions/checkout@v1 | ||
- run: swift test --enable-test-discovery --sanitize=thread | ||
sqlite-nio_xenial: | ||
container: | ||
image: vapor/swift:5.2-xenial | ||
- name: Install dependencies | ||
run: apt-get -q update && apt-get -q install -y libsqlite3-dev | ||
- name: Check out SQLiteNIO | ||
uses: actions/checkout@v2 | ||
with: | ||
path: sqlite-nio | ||
- name: Check out dependent | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: vapor/${{ matrix.dependent }} | ||
path: dependent | ||
- name: Use local SQLiteNIO | ||
run: swift package edit sqlite-nio --path sqlite-nio | ||
working-directory: dependent | ||
- name: Run tests with Thread Sanitizer | ||
run: swift test --enable-test-discovery --sanitize=thread | ||
working-directory: dependent | ||
linux: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
image: | ||
# 5.2 Stable | ||
- swift:5.2-xenial | ||
- swift:5.2-bionic | ||
# 5.2 Unstable | ||
- swiftlang/swift:nightly-5.2-xenial | ||
- swiftlang/swift:nightly-5.2-bionic | ||
# 5.3 Unstable | ||
- swiftlang/swift:nightly-5.3-xenial | ||
- swiftlang/swift:nightly-5.3-bionic | ||
# Master Unsable | ||
- swiftlang/swift:nightly-master-xenial | ||
- swiftlang/swift:nightly-master-bionic | ||
- swiftlang/swift:nightly-master-focal | ||
- swiftlang/swift:nightly-master-centos8 | ||
- swiftlang/swift:nightly-master-amazonlinux2 | ||
container: ${{ matrix.image }} | ||
steps: | ||
- run: apt update -y; apt install -y libsqlite3-dev | ||
- uses: actions/checkout@v1 | ||
- run: swift test --enable-test-discovery --sanitize=thread | ||
# sqlite-nio_catalina: | ||
# runs-on: macOS-10.15 | ||
# steps: | ||
# - uses: actions/checkout@v1 | ||
# - run: swift test --sanitize=thread | ||
# sqlite-nio_ios13: | ||
# runs-on: macOS-10.15 | ||
# steps: | ||
# - uses: actions/checkout@v1 | ||
# - run: xcodebuild test -destination 'name=iPhone 11' -scheme 'sqlite-nio' | ||
sqlite-kit: | ||
container: | ||
image: vapor/swift:5.2 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: apt update -y; apt install -y libsqlite3-dev | ||
- run: git clone -b master https://github.com/vapor/sqlite-kit.git | ||
working-directory: ./ | ||
- run: swift package edit sqlite-nio --revision ${{ github.sha }} | ||
working-directory: ./sqlite-kit | ||
- run: swift test --enable-test-discovery --sanitize=thread | ||
working-directory: ./sqlite-kit | ||
fluent-sqlite-driver: | ||
container: | ||
image: vapor/swift:5.2 | ||
runs-on: ubuntu-latest | ||
- name: Install Ubuntu dependencies | ||
run: apt-get -q update && apt-get -q install -y libsqlite3-dev | ||
if: ${{ endsWith(matrix.image, 'xenial') || endsWith(matrix.image, 'bionic') || endsWith(matrix.image, 'focal') }} | ||
- name: Install CentOS deps | ||
run: dnf install -y sqlite-devel | ||
if: ${{ endsWith(matrix.image, 'centos8') }} | ||
- name: Update AmazonLinux2's too-old SQLite and compensate for its Postgres | ||
if: ${{ endsWith(matrix.image, 'amazonlinux2') }} | ||
working-directory: /root | ||
# Cribbed from the Fedora RPM, leaves out a lot. System's Tcl is too old to run SQLite's tests. | ||
run: | | ||
yum install -y sqlite-devel | ||
yum install -y file tcl-devel make | ||
curl -L 'https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release' | tar xz && cd sqlite | ||
export CFLAGS="-DSQLITE_DISABLE_DIRSYNC=1 -DSQLITE_SECURE_DELETE=1" | ||
./configure --prefix=/usr --libdir=/usr/lib64 --enable-fts3 --enable-all --with-tcl=/usr/lib64 | ||
make all install | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Run tests with Thread Sanitizer | ||
run: swift test --enable-test-discovery --sanitize=thread | ||
macOS: | ||
runs-on: macos-latest | ||
steps: | ||
- run: apt update -y; apt install -y libsqlite3-dev | ||
- run: git clone -b master https://github.com/vapor/fluent-sqlite-driver.git | ||
working-directory: ./ | ||
- run: swift package edit sqlite-nio --revision ${{ github.sha }} | ||
working-directory: ./fluent-sqlite-driver | ||
- run: swift test --enable-test-discovery --sanitize=thread | ||
working-directory: ./fluent-sqlite-driver | ||
- name: Select latest available Xcode | ||
uses: maxim-lobanov/[email protected] | ||
with: | ||
xcode-version: latest | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Run tests with Thread Sanitizer | ||
run: swift test --enable-test-discovery --sanitize=thread |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
DerivedData | ||
.swiftpm | ||
Package.resolved | ||
Tests/LinuxMain.swift | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
public struct SQLiteColumns { | ||
public let offsets: [String: Int] | ||
public struct SQLiteColumn: CustomStringConvertible { | ||
public let name: String | ||
public let data: SQLiteData | ||
|
||
public var description: String { | ||
"\(self.name): \(self.data)" | ||
} | ||
} | ||
|
||
public struct SQLiteRow: CustomStringConvertible { | ||
public let columns: SQLiteColumns | ||
public let data: [SQLiteData] | ||
public struct SQLiteRow { | ||
let columnOffsets: SQLiteColumnOffsets | ||
let data: [SQLiteData] | ||
|
||
public var description: String { | ||
return self.columns.offsets | ||
.mapValues { self.data[$0] } | ||
.description | ||
public var columns: [SQLiteColumn] { | ||
self.columnOffsets.offsets.map { (name, offset) in | ||
SQLiteColumn(name: name, data: self.data[offset]) | ||
} | ||
} | ||
|
||
public func column(_ name: String) -> SQLiteData? { | ||
guard let offset = self.columns.offsets[name] else { | ||
guard let offset = self.columnOffsets.lookupTable[name] else { | ||
return nil | ||
} | ||
return self.data[offset] | ||
} | ||
} | ||
|
||
extension SQLiteRow: CustomStringConvertible { | ||
public var description: String { | ||
self.columns.description | ||
} | ||
} | ||
|
||
final class SQLiteColumnOffsets { | ||
let offsets: [(String, Int)] | ||
let lookupTable: [String: Int] | ||
|
||
init(offsets: [(String, Int)]) { | ||
self.offsets = offsets | ||
self.lookupTable = .init(offsets, uniquingKeysWith: { a, b in a }) | ||
} | ||
} |
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