Merge pull request #319 from groue/GRDB3-Associations

Associations & Joins
This commit is contained in:
Gwendal Roué authored and GitHub committed 2018-05-01 21:48:06 +02:00
commit 7a30eb2613
108 files changed
+12724 -1588

No files matched your search

+1 -1
View File
@@ -1 +1 @@
4.0
4.1
+46 -104
View File
@@ -15,198 +15,140 @@ jobs:
###########################################
## Test GRDB
# Test GRDBOSX (Xcode 9.2)
# Test GRDBOSX (Xcode 9.3)
- stage: Test GRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBOSX (Xcode 9.2, macOS)
- TID=GRDBOSX (Xcode 9.3, macOS)
script: make test_framework_GRDBOSX
# Test GRDBWatchOS (Xcode 9.2)
# Test GRDBWatchOS (Xcode 9.3)
- stage: Test GRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBWatchOS (Xcode 9.2, watchOS)
- TID=GRDBWatchOS (Xcode 9.3, watchOS)
script: make test_framework_GRDBWatchOS
# Test GRDBiOS (Xcode 9.2, iOS <MAXIMUM VERSION>)
# Test GRDBiOS (Xcode 9.3, iOS <MAXIMUM VERSION>)
- stage: Test GRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBiOS (Xcode 9.2, iOS <MAX>)
- TID=GRDBiOS (Xcode 9.3, iOS <MAX>)
script: make test_framework_GRDBiOS_maxTarget
# Test GRDBiOS (Xcode 9.2, iOS <MINIMUM VERSION>))
# Test GRDBiOS (Xcode 9.3, iOS <MINIMUM VERSION>))
- stage: Test GRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBiOS (Xcode 9.2, iOS <MIN>)
- TID=GRDBiOS (Xcode 9.3, iOS <MIN>)
script: make test_framework_GRDBiOS_minTarget
# Test GRDB [SPM] (Xcode 9.2, macOS)
# Test GRDB [SPM] (Xcode 9.3, macOS)
- stage: Test GRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDB [SPM] (Xcode 9.2, macOS)
- TID=GRDB [SPM] (Xcode 9.3, macOS)
script: make test_SPM
# Test GRDBOSX (Xcode 9.0)
- stage: Test GRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9
env:
- TID=GRDBOSX (Xcode 9.0, macOS)
script: make test_framework_GRDBOSX
# Test GRDBiOS (Xcode 9.0, iOS <MAXIMUM VERSION>)
- stage: Test GRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9
env:
- TID=GRDBiOS (Xcode 9.0, iOS <MAX>)
script: make test_framework_GRDBiOS_maxTarget
###########################################
## Test GRDB (Custom SQLite)
# Test GRDBCustomSQLiteOSX (Xcode 9.2)
# Test GRDBCustomSQLiteOSX (Xcode 9.3)
- stage: Test GRDB + Custom SQLite
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBCustomSQLiteOSX (Xcode 9.2, macOS)
- TID=GRDBCustomSQLiteOSX (Xcode 9.3, macOS)
script: make test_framework_GRDBCustomSQLiteOSX
# Test GRDBCustomSQLiteiOS (Xcode 9.2, iOS <MAXIMUM VERSION>)
# Test GRDBCustomSQLiteiOS (Xcode 9.3, iOS <MAXIMUM VERSION>)
- stage: Test GRDB + Custom SQLite
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBCustomSQLiteiOS (Xcode 9.2, iOS <MAX>)
- TID=GRDBCustomSQLiteiOS (Xcode 9.3, iOS <MAX>)
script: make test_framework_GRDBCustomSQLiteiOS_maxTarget
# Test GRDBCustomSQLiteiOS (Xcode 9.2, iOS <MINIMUM VERSION>))
# Test GRDBCustomSQLiteiOS (Xcode 9.3, iOS <MINIMUM VERSION>))
- stage: Test GRDB + Custom SQLite
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBCustomSQLiteiOS (Xcode 9.2, iOS <MIN>)
- TID=GRDBCustomSQLiteiOS (Xcode 9.3, iOS <MIN>)
script: make test_framework_GRDBCustomSQLiteiOS_minTarget
# Test GRDBCustomSQLiteOSX (Xcode 9.0)
- stage: Test GRDB + Custom SQLite
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9
env:
- TID=GRDBCustomSQLiteOSX (Xcode 9.0, macOS)
script: make test_framework_GRDBCustomSQLiteOSX
# Test GRDBCustomSQLiteiOS (Xcode 9.0, iOS <MAXIMUM VERSION>)
- stage: Test GRDB + Custom SQLite
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9
env:
- TID=GRDBCustomSQLiteiOS (Xcode 9.0, iOS <MAX>)
script: make test_framework_GRDBCustomSQLiteiOS_maxTarget
###########################################
## Test GRDB (SQLCipher)
# Test GRDBCipherOSX (Xcode 9.2)
# Test GRDBCipherOSX (Xcode 9.3)
- stage: Test GRDB + SQLCipher
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBCipherOSX (Xcode 9.2, macOS)
- TID=GRDBCipherOSX (Xcode 9.3, macOS)
script: make test_framework_GRDBCipherOSX
# Test GRDBCipheriOS (Xcode 9.2, iOS <MAXIMUM VERSION>)
# Test GRDBCipheriOS (Xcode 9.3, iOS <MAXIMUM VERSION>)
- stage: Test GRDB + SQLCipher
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBCipheriOS (Xcode 9.2, iOS <MAX>)
- TID=GRDBCipheriOS (Xcode 9.3, iOS <MAX>)
script: make test_framework_GRDBCipheriOS_maxTarget
# Test GRDBCipheriOS (Xcode 9.2, iOS <MINIMUM VERSION>))
# Test GRDBCipheriOS (Xcode 9.3, iOS <MINIMUM VERSION>))
- stage: Test GRDB + SQLCipher
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=GRDBCipheriOS (Xcode 9.2, iOS <MIN>)
- TID=GRDBCipheriOS (Xcode 9.3, iOS <MIN>)
script: make test_framework_GRDBCipheriOS_minTarget
# Test GRDBCipherOSX (Xcode 9.0)
- stage: Test GRDB + SQLCipher
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9
env:
- TID=GRDBCipherOSX (Xcode 9.0, macOS)
script: make test_framework_GRDBCipherOSX
# Test GRDBCipheriOS (Xcode 9.0, iOS <MAXIMUM VERSION>)
- stage: Test GRDB + SQLCipher
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9
env:
- TID=GRDBCipheriOS (Xcode 9.0, iOS <MAX>)
script: make test_framework_GRDBCipheriOS_maxTarget
###########################################
## Test Installation Methods
# Manual Install (Xcode 9.2)
# Manual Install (Xcode 9.3)
- stage: Test Installation
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=Manual Install (Xcode 9.2)
- TID=Manual Install (Xcode 9.3)
script: make test_install_manual
# Manual Install (GRDBCipher, Xcode 9.2)
# Manual Install (GRDBCipher, Xcode 9.3)
- stage: Test Installation
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.2
osx_image: xcode9.3
env:
- TID=Manual Install (GRDBCipher, Xcode 9.2)
- TID=Manual Install (GRDBCipher, Xcode 9.3)
script: make test_install_GRDBCipher
# Cocoapods Lint (Xcode 9.2)
# Cocoapods Lint (Xcode 9.3)
- stage: Test Installation
osx_image: xcode9.2
osx_image: xcode9.3
install:
- gem install cocoapods # Since Travis is not always on latest version
env:
- TID=Cocoapods (Xcode 9.2)
- TID=Cocoapods (Xcode 9.3)
script: make test_CocoaPodsLint
# Cocoapods Lint (Xcode 9.0)
# SPM Install (Xcode 9.3)
- stage: Test Installation
osx_image: xcode9
install:
- gem install cocoapods # Since Travis is not always on latest version
osx_image: xcode9.3
env:
- TID=Cocoapods (Xcode 9.0)
script: make test_CocoaPodsLint
# SPM Install (Xcode 9.2)
- stage: Test Installation
osx_image: xcode9.2
env:
- TID=SPM (Xcode 9.2)
- TID=SPM (Xcode 9.3)
script: make test_install_SPM
## Carthage Build
## Commented out until `make test_CarthageBuild` performs *reliably*.
## See https://github.com/groue/GRDB.swift/pull/262
# - stage: Test Installation
# osx_image: xcode9.2
# osx_image: xcode9.3
# before_install:
# - brew update
# - brew outdated carthage || brew upgrade carthage
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="468px" height="145px" viewBox="0 0 468 145" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>AmbiguousForeignKeys</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="200" height="127" rx="10"></rect>
<filter x="-7.2%" y="-9.1%" width="114.5%" height="122.8%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-5" x="0" y="0" width="200" height="103" rx="10"></rect>
<filter x="-7.2%" y="-11.2%" width="114.5%" height="128.2%" filterUnits="objectBoundingBox" id="filter-7">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-8" cx="3.5" cy="28.5" r="3.5"></circle>
<path d="M57.4068802,4.62378409 L50.4819187,0.815055312 C49.9979981,0.548898936 49.3899405,0.725431787 49.1237841,1.20935247 C49.0425794,1.35699745 49,1.52276825 49,1.69127122 L49,9.30872878 C49,9.86101353 49.4477153,10.3087288 50,10.3087288 C50.168503,10.3087288 50.3342738,10.2661494 50.4819187,10.1849447 L57.4068802,6.37621591 C57.8908008,6.11005953 58.0673337,5.50200193 57.8011773,5.01808125 C57.7097895,4.85192153 57.5730399,4.71517193 57.4068802,4.62378409 Z" id="path-9"></path>
<circle id="path-10" cx="3.5" cy="47.5" r="3.5"></circle>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="AmbiguousForeignKeys" transform="translate(9.000000, 6.000000)">
<g id="Table">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="128" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">authorId</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">translatorId</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 103.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">title</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="book" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="82.9443359" y="21">book</tspan>
</text>
</g>
<g id="Table-Copy-2" transform="translate(250.000000, 0.000000)">
<mask id="mask-6" fill="white">
<use xlink:href="#path-5"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-5"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-5"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-5"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="104" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">name</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500"></text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal"></text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="person" mask="url(#mask-6)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="76.2109375" y="21">person</tspan>
</text>
</g>
<g id="Group-3" transform="translate(197.000000, 39.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-8"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="3.5" cy="28.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-9"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M57.6478395,4.18567614 C57.8970791,4.3227579 58.1022035,4.5278823 58.2392853,4.77712188 C58.6385198,5.5030029 58.3737206,6.4150893 57.6478395,6.81432386 L50.7228781,10.6230526 C50.5014107,10.7448598 50.2527545,10.8087288 50,10.8087288 C49.1715729,10.8087288 48.5,10.1371559 48.5,9.30872878 L48.5,1.69127122 C48.5,1.43851677 48.563869,1.18986057 48.6856761,0.968393096 C49.0849107,0.242512071 49.9969971,-0.0222872062 50.7228781,0.376947358 L57.6478395,4.18567614 Z"></path>
</g>
<path d="M2.5,28.5 C2.5,28.5 2.5,28.5 16.5,28.5 C30.5,28.5 27.5,5.5 40.5,5.5 C49.1666667,5.5 53.5,5.5 53.5,5.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
<g id="Group-3" transform="translate(197.000000, 44.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-10"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="3.5" cy="47.5" r="4"></circle>
</g>
<path d="M2.5,47.5 C2.5,47.5 2.5,47.5 16.5,47.5 C30.5,47.5 27.5,0.5 40.5,0.5 C49.1666667,0.5 53.5,0.5 53.5,0.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 12 KiB

@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="468px" height="121px" viewBox="0 0 468 121" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>BelongsToSchema</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="200" height="103" rx="10"></rect>
<filter x="-7.2%" y="-11.2%" width="114.5%" height="128.2%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-5" x="0" y="0" width="200" height="103" rx="10"></rect>
<filter x="-7.2%" y="-11.2%" width="114.5%" height="128.2%" filterUnits="objectBoundingBox" id="filter-7">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-8" cx="200.5" cy="67.5" r="3.5"></circle>
<path d="M254.40688,43.6237841 L247.481919,39.8150553 C246.997998,39.5488989 246.38994,39.7254318 246.123784,40.2093525 C246.042579,40.3569975 246,40.5227683 246,40.6912712 L246,48.3087288 C246,48.8610135 246.447715,49.3087288 247,49.3087288 C247.168503,49.3087288 247.334274,49.2661494 247.481919,49.1849447 L254.40688,45.3762159 C254.890801,45.1100595 255.067334,44.5020019 254.801177,44.0180813 C254.709789,43.8519215 254.57304,43.7151719 254.40688,43.6237841 Z" id="path-9"></path>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="BelongsToSchema" transform="translate(9.000000, 6.000000)">
<g id="Table">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="104" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">authorId</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">title</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="book" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="82.9443359" y="21">book</tspan>
</text>
</g>
<g id="Table-Copy-2" transform="translate(250.000000, 0.000000)">
<mask id="mask-6" fill="white">
<use xlink:href="#path-5"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-5"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-5"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-5"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="104" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">name</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500"></text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal"></text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="author" mask="url(#mask-6)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="77.3867188" y="21">author</tspan>
</text>
</g>
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-8"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="200.5" cy="67.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-9"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M254.64784,43.1856761 C254.897079,43.3227579 255.102204,43.5278823 255.239285,43.7771219 C255.63852,44.5030029 255.373721,45.4150893 254.64784,45.8143239 L247.722878,49.6230526 C247.501411,49.7448598 247.252754,49.8087288 247,49.8087288 C246.171573,49.8087288 245.5,49.1371559 245.5,48.3087288 L245.5,40.6912712 C245.5,40.4385168 245.563869,40.1898606 245.685676,39.9683931 C246.084911,39.2425121 246.996997,38.9777128 247.722878,39.3769474 L254.64784,43.1856761 Z"></path>
</g>
<path d="M199.5,67.5 C199.5,67.5 199.5,67.5 213.5,67.5 C227.5,67.5 224.5,44.5 237.5,44.5 C246.166667,44.5 250.5,44.5 250.5,44.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 10 KiB

@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="468px" height="121px" viewBox="0 0 468 121" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>HasManySchema</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="200" height="103" rx="10"></rect>
<filter x="-7.2%" y="-11.2%" width="114.5%" height="128.2%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-5" x="0" y="0" width="200" height="103" rx="10"></rect>
<filter x="-7.2%" y="-11.2%" width="114.5%" height="128.2%" filterUnits="objectBoundingBox" id="filter-7">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-8" cx="3.5" cy="28.5" r="3.5"></circle>
<path d="M57.4068802,4.62378409 L50.4819187,0.815055312 C49.9979981,0.548898936 49.3899405,0.725431787 49.1237841,1.20935247 C49.0425794,1.35699745 49,1.52276825 49,1.69127122 L49,9.30872878 C49,9.86101353 49.4477153,10.3087288 50,10.3087288 C50.168503,10.3087288 50.3342738,10.2661494 50.4819187,10.1849447 L57.4068802,6.37621591 C57.8908008,6.11005953 58.0673337,5.50200193 57.8011773,5.01808125 C57.7097895,4.85192153 57.5730399,4.71517193 57.4068802,4.62378409 Z" id="path-9"></path>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="HasManySchema" transform="translate(9.000000, 6.000000)">
<g id="Table" transform="translate(250.000000, 0.000000)">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="104" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">authorId</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">title</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="book" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="82.9443359" y="21">book</tspan>
</text>
</g>
<g id="Table-Copy-2">
<mask id="mask-6" fill="white">
<use xlink:href="#path-5"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-5"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-5"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-5"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="104" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">name</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500"></text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal"></text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="author" mask="url(#mask-6)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="77.3867188" y="21">author</tspan>
</text>
</g>
<g id="Group" transform="translate(224.000000, 55.000000) scale(-1, 1) translate(-224.000000, -55.000000) translate(195.000000, 39.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-8"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="3.5" cy="28.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-9"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M57.6478395,4.18567614 C57.8970791,4.3227579 58.1022035,4.5278823 58.2392853,4.77712188 C58.6385198,5.5030029 58.3737206,6.4150893 57.6478395,6.81432386 L50.7228781,10.6230526 C50.5014107,10.7448598 50.2527545,10.8087288 50,10.8087288 C49.1715729,10.8087288 48.5,10.1371559 48.5,9.30872878 L48.5,1.69127122 C48.5,1.43851677 48.563869,1.18986057 48.6856761,0.968393096 C49.0849107,0.242512071 49.9969971,-0.0222872062 50.7228781,0.376947358 L57.6478395,4.18567614 Z"></path>
</g>
<path d="M2.5,28.5 C2.5,28.5 2.5,28.5 16.5,28.5 C30.5,28.5 27.5,5.5 40.5,5.5 C49.1666667,5.5 53.5,5.5 53.5,5.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 10 KiB

@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="468px" height="200px" viewBox="0 0 468 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>HasManyThroughSchema</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="200" height="103" rx="10"></rect>
<filter x="-7.2%" y="-11.2%" width="114.5%" height="128.2%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-5" x="0" y="0" width="200" height="79" rx="10"></rect>
<filter x="-7.2%" y="-14.6%" width="114.5%" height="136.7%" filterUnits="objectBoundingBox" id="filter-7">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-8" x="0" y="0" width="200" height="79" rx="10"></rect>
<filter x="-7.2%" y="-14.6%" width="114.5%" height="136.7%" filterUnits="objectBoundingBox" id="filter-10">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-11" cx="3.5" cy="44.5" r="3.5"></circle>
<path d="M57.4068802,4.62378409 L50.4819187,0.815055312 C49.9979981,0.548898936 49.3899405,0.725431787 49.1237841,1.20935247 C49.0425794,1.35699745 49,1.52276825 49,1.69127122 L49,9.30872878 C49,9.86101353 49.4477153,10.3087288 50,10.3087288 C50.168503,10.3087288 50.3342738,10.2661494 50.4819187,10.1849447 L57.4068802,6.37621591 C57.8908008,6.11005953 58.0673337,5.50200193 57.8011773,5.01808125 C57.7097895,4.85192153 57.5730399,4.71517193 57.4068802,4.62378409 Z" id="path-12"></path>
<circle id="path-13" cx="3.5" cy="3.5" r="3.5"></circle>
<path d="M57.4068802,42.6237841 L50.4819187,38.8150553 C49.9979981,38.5488989 49.3899405,38.7254318 49.1237841,39.2093525 C49.0425794,39.3569975 49,39.5227683 49,39.6912712 L49,47.3087288 C49,47.8610135 49.4477153,48.3087288 50,48.3087288 C50.168503,48.3087288 50.3342738,48.2661494 50.4819187,48.1849447 L57.4068802,44.3762159 C57.8908008,44.1100595 58.0673337,43.5020019 57.8011773,43.0180813 C57.7097895,42.8519215 57.5730399,42.7151719 57.4068802,42.6237841 Z" id="path-14"></path>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="HasManyThroughSchema" transform="translate(9.000000, 6.000000)">
<g id="Table" transform="translate(250.000000, 40.000000)">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="104" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">countryCode</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">citizenId</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">issueDate</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">date</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="passport" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="69.3613281" y="21">passport</tspan>
</text>
</g>
<g id="Table-Copy-2">
<mask id="mask-6" fill="white">
<use xlink:href="#path-5"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-5"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-5"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-5"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="80" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">code</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">name</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="country" mask="url(#mask-6)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="73.3740234" y="21">country</tspan>
</text>
</g>
<g id="Table-Copy-2" transform="translate(0.000000, 103.000000)">
<mask id="mask-9" fill="white">
<use xlink:href="#path-8"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-10)" xlink:href="#path-8"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-8"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-8"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="80" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-9)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-9)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">name</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="citizen" mask="url(#mask-9)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="77.1782227" y="21">citizen</tspan>
</text>
</g>
<g id="Group" transform="translate(224.000000, 63.000000) scale(-1, 1) translate(-224.000000, -63.000000) translate(195.000000, 39.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-11"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="3.5" cy="44.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-12"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M57.6478395,4.18567614 C57.8970791,4.3227579 58.1022035,4.5278823 58.2392853,4.77712188 C58.6385198,5.5030029 58.3737206,6.4150893 57.6478395,6.81432386 L50.7228781,10.6230526 C50.5014107,10.7448598 50.2527545,10.8087288 50,10.8087288 C49.1715729,10.8087288 48.5,10.1371559 48.5,9.30872878 L48.5,1.69127122 C48.5,1.43851677 48.563869,1.18986057 48.6856761,0.968393096 C49.0849107,0.242512071 49.9969971,-0.0222872062 50.7228781,0.376947358 L57.6478395,4.18567614 Z"></path>
</g>
<path d="M2.5,44.5 C2.5,44.5 2.5,44.5 16.5,44.5 C30.5,44.5 27.5,5.5 40.5,5.5 C49.1666667,5.5 53.5,5.5 53.5,5.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
<g id="Group" transform="translate(224.000000, 128.500000) scale(-1, 1) translate(-224.000000, -128.500000) translate(195.000000, 104.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-13"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="3.5" cy="3.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-14"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M57.6478395,42.1856761 C57.8970791,42.3227579 58.1022035,42.5278823 58.2392853,42.7771219 C58.6385198,43.5030029 58.3737206,44.4150893 57.6478395,44.8143239 L50.7228781,48.6230526 C50.5014107,48.7448598 50.2527545,48.8087288 50,48.8087288 C49.1715729,48.8087288 48.5,48.1371559 48.5,47.3087288 L48.5,39.6912712 C48.5,39.4385168 48.563869,39.1898606 48.6856761,38.9683931 C49.0849107,38.2425121 49.9969971,37.9777128 50.7228781,38.3769474 L57.6478395,42.1856761 Z"></path>
</g>
<path d="M2.5,3.5 C2.5,3.5 2.5,3.5 16.5,3.5 C30.5,3.5 27.5,43.5 40.5,43.5 C49.1666667,43.5 53.5,43.5 53.5,43.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 15 KiB

@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="468px" height="145px" viewBox="0 0 468 145" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>HasOneSchema</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="200" height="127" rx="10"></rect>
<filter x="-7.2%" y="-9.1%" width="114.5%" height="122.8%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-5" x="0" y="0" width="200" height="127" rx="10"></rect>
<filter x="-7.2%" y="-9.1%" width="114.5%" height="122.8%" filterUnits="objectBoundingBox" id="filter-7">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-8" cx="3.5" cy="28.5" r="3.5"></circle>
<path d="M57.4068802,4.62378409 L50.4819187,0.815055312 C49.9979981,0.548898936 49.3899405,0.725431787 49.1237841,1.20935247 C49.0425794,1.35699745 49,1.52276825 49,1.69127122 L49,9.30872878 C49,9.86101353 49.4477153,10.3087288 50,10.3087288 C50.168503,10.3087288 50.3342738,10.2661494 50.4819187,10.1849447 L57.4068802,6.37621591 C57.8908008,6.11005953 58.0673337,5.50200193 57.8011773,5.01808125 C57.7097895,4.85192153 57.5730399,4.71517193 57.4068802,4.62378409 Z" id="path-9"></path>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="HasOneSchema" transform="translate(9.000000, 6.000000)">
<g id="Table" transform="translate(250.000000, 0.000000)">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="128" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">countryCode</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">population</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 103.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">density</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">double</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="demographics" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="50.894043" y="21">demographics</tspan>
</text>
</g>
<g id="Table-Copy-2">
<mask id="mask-6" fill="white">
<use xlink:href="#path-5"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-5"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-5"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-5"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="128" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">code</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">name</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500"></text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal"></text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 103.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500"></text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal"></text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="country" mask="url(#mask-6)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="73.3740234" y="21">country</tspan>
</text>
</g>
<g id="Group" transform="translate(224.000000, 55.000000) scale(-1, 1) translate(-224.000000, -55.000000) translate(195.000000, 39.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-8"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="3.5" cy="28.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-9"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M57.6478395,4.18567614 C57.8970791,4.3227579 58.1022035,4.5278823 58.2392853,4.77712188 C58.6385198,5.5030029 58.3737206,6.4150893 57.6478395,6.81432386 L50.7228781,10.6230526 C50.5014107,10.7448598 50.2527545,10.8087288 50,10.8087288 C49.1715729,10.8087288 48.5,10.1371559 48.5,9.30872878 L48.5,1.69127122 C48.5,1.43851677 48.563869,1.18986057 48.6856761,0.968393096 C49.0849107,0.242512071 49.9969971,-0.0222872062 50.7228781,0.376947358 L57.6478395,4.18567614 Z"></path>
</g>
<path d="M2.5,28.5 C2.5,28.5 2.5,28.5 16.5,28.5 C30.5,28.5 27.5,5.5 40.5,5.5 C49.1666667,5.5 53.5,5.5 53.5,5.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 12 KiB

@@ -0,0 +1,198 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="468px" height="247px" viewBox="0 0 468 247" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>HasOneThroughSchema</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="200" height="79" rx="10"></rect>
<filter x="-7.2%" y="-14.6%" width="114.5%" height="136.7%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-5" x="0" y="0" width="200" height="103" rx="10"></rect>
<filter x="-7.2%" y="-11.2%" width="114.5%" height="128.2%" filterUnits="objectBoundingBox" id="filter-7">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-8" x="0" y="0" width="200" height="102" rx="10"></rect>
<filter x="-7.2%" y="-11.3%" width="114.5%" height="128.4%" filterUnits="objectBoundingBox" id="filter-10">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-11" cx="3.5" cy="56.5" r="3.5"></circle>
<path d="M57.4068802,4.62378409 L50.4819187,0.815055312 C49.9979981,0.548898936 49.3899405,0.725431787 49.1237841,1.20935247 C49.0425794,1.35699745 49,1.52276825 49,1.69127122 L49,9.30872878 C49,9.86101353 49.4477153,10.3087288 50,10.3087288 C50.168503,10.3087288 50.3342738,10.2661494 50.4819187,10.1849447 L57.4068802,6.37621591 C57.8908008,6.11005953 58.0673337,5.50200193 57.8011773,5.01808125 C57.7097895,4.85192153 57.5730399,4.71517193 57.4068802,4.62378409 Z" id="path-12"></path>
<circle id="path-13" cx="3.5" cy="3.5" r="3.5"></circle>
<path d="M57.4068802,54.6237841 L50.4819187,50.8150553 C49.9979981,50.5488989 49.3899405,50.7254318 49.1237841,51.2093525 C49.0425794,51.3569975 49,51.5227683 49,51.6912712 L49,59.3087288 C49,59.8610135 49.4477153,60.3087288 50,60.3087288 C50.168503,60.3087288 50.3342738,60.2661494 50.4819187,60.1849447 L57.4068802,56.3762159 C57.8908008,56.1100595 58.0673337,55.5020019 57.8011773,55.0180813 C57.7097895,54.8519215 57.5730399,54.7151719 57.4068802,54.6237841 Z" id="path-14"></path>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="HasOneThroughSchema" transform="translate(9.000000, 6.000000)">
<g id="Table" transform="translate(250.000000, 75.000000)">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="80" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">name</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="library" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="77.800293" y="21">library</tspan>
</text>
</g>
<g id="Group-2">
<g id="Table-Copy-2">
<mask id="mask-6" fill="white">
<use xlink:href="#path-5"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-5"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-5"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-5"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="104" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">libraryId</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-6)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">title</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="book" mask="url(#mask-6)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="82.9443359" y="21">book</tspan>
</text>
</g>
<g id="Table-Copy-2" transform="translate(0.000000, 127.000000)">
<mask id="mask-9" fill="white">
<use xlink:href="#path-8"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-10)" xlink:href="#path-8"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-8"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-8"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="103" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-9)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">libraryId</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-9)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">street</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-9)">
<g transform="translate(0.000000, 78.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">city</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="address" mask="url(#mask-9)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="72.4545898" y="21">address</tspan>
</text>
</g>
</g>
<g id="Group" transform="translate(226.000000, 93.500000) scale(1, -1) translate(-226.000000, -93.500000) translate(197.000000, 63.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-11"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="3.5" cy="56.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-12"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M57.6478395,4.18567614 C57.8970791,4.3227579 58.1022035,4.5278823 58.2392853,4.77712188 C58.6385198,5.5030029 58.3737206,6.4150893 57.6478395,6.81432386 L50.7228781,10.6230526 C50.5014107,10.7448598 50.2527545,10.8087288 50,10.8087288 C49.1715729,10.8087288 48.5,10.1371559 48.5,9.30872878 L48.5,1.69127122 C48.5,1.43851677 48.563869,1.18986057 48.6856761,0.968393096 C49.0849107,0.242512071 49.9969971,-0.0222872062 50.7228781,0.376947358 L57.6478395,4.18567614 Z"></path>
</g>
<path d="M2.5,56.5 C2.5,56.5 2.5,56.5 16.5,56.5 C30.5,56.5 27.5,5.5 40.5,5.5 C49.1666667,5.5 53.5,5.5 53.5,5.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
<g id="Group" transform="translate(226.000000, 143.500000) scale(1, -1) translate(-226.000000, -143.500000) translate(197.000000, 113.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-13"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="3.5" cy="3.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-14"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M57.6478395,54.1856761 C57.8970791,54.3227579 58.1022035,54.5278823 58.2392853,54.7771219 C58.6385198,55.5030029 58.3737206,56.4150893 57.6478395,56.8143239 L50.7228781,60.6230526 C50.5014107,60.7448598 50.2527545,60.8087288 50,60.8087288 C49.1715729,60.8087288 48.5,60.1371559 48.5,59.3087288 L48.5,51.6912712 C48.5,51.4385168 48.563869,51.1898606 48.6856761,50.9683931 C49.0849107,50.2425121 49.9969971,49.9777128 50.7228781,50.3769474 L57.6478395,54.1856761 Z"></path>
</g>
<path d="M2.5,3.5 C2.5,3.5 2.5,3.5 16.5,3.5 C30.5,3.5 27.5,55.5 40.5,55.5 C49.1666667,55.5 53.5,55.5 53.5,55.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 16 KiB

@@ -0,0 +1,3 @@
fixfonts:
sed -i '' -- 's/SFUIText-Regular, SF UI Text/-apple-system,sans-serif/g' *.svg
sed -i '' -- 's/SFUIText-Semibold, SF UI Text/-apple-system,sans-serif/g' *.svg
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="233px" height="121px" viewBox="0 0 233 121" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>RecursiveSchema</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="200" height="103" rx="10"></rect>
<filter x="-7.2%" y="-11.2%" width="114.5%" height="128.2%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-5" cx="22.5" cy="28.5" r="3.5"></circle>
<path d="M27.4068802,4.62378409 L20.4819187,0.815055312 C19.9979981,0.548898936 19.3899405,0.725431787 19.1237841,1.20935247 C19.0425794,1.35699745 19,1.52276825 19,1.69127122 L19,9.30872878 C19,9.86101353 19.4477153,10.3087288 20,10.3087288 C20.168503,10.3087288 20.3342738,10.2661494 20.4819187,10.1849447 L27.4068802,6.37621591 C27.8908008,6.11005953 28.0673337,5.50200193 27.8011773,5.01808125 C27.7097895,4.85192153 27.5730399,4.71517193 27.4068802,4.62378409 Z" id="path-6"></path>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="RecursiveSchema" transform="translate(9.000000, 6.000000)">
<g id="Table-Copy-2">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="201" height="104" rx="10"></rect>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 31.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">id</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 55.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">managerId</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">integer</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500">
<tspan x="10" y="17" fill="#000000">name</tspan>
</text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal">
<tspan x="110" y="17" fill="#000000">text</tspan>
</text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<g id="Field" mask="url(#mask-3)">
<g transform="translate(0.000000, 79.000000)">
<text id="name" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="500"></text>
<text id="type" fill="none" font-family="-apple-system,sans-serif" font-size="14" font-weight="normal"></text>
<rect id="Rectangle" fill-opacity="0.12" fill="#000000" fill-rule="evenodd" x="0" y="0" width="200" height="1"></rect>
</g>
</g>
<text id="employee" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="66.8730469" y="21">employee</tspan>
</text>
</g>
<g id="Group" transform="translate(209.000000, 55.000000) scale(-1, 1) translate(-209.000000, -55.000000) translate(195.000000, 39.000000)">
<g id="Oval">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-5"></use>
<circle stroke="#FFFFFF" stroke-width="1" cx="22.5" cy="28.5" r="4"></circle>
</g>
<g id="Path-3">
<use fill="#000000" fill-rule="evenodd" xlink:href="#path-6"></use>
<path stroke="#FFFFFF" stroke-width="1" d="M27.6478395,4.18567614 C27.8970791,4.3227579 28.1022035,4.5278823 28.2392853,4.77712188 C28.6385198,5.5030029 28.3737206,6.4150893 27.6478395,6.81432386 L20.7228781,10.6230526 C20.5014107,10.7448598 20.2527545,10.8087288 20,10.8087288 C19.1715729,10.8087288 18.5,10.1371559 18.5,9.30872878 L18.5,1.69127122 C18.5,1.43851677 18.563869,1.18986057 18.6856761,0.968393096 C19.0849107,0.242512071 19.9969971,-0.0222872062 20.7228781,0.376947358 L27.6478395,4.18567614 Z"></path>
</g>
<path d="M23.5,28.5 C23.5,28.5 19.1666667,28.5 10.5,28.5 C-2.5,28.5 -2.5,5.5 10.5,5.5 C19.1666667,5.5 23.5,5.5 23.5,5.5" id="Path-2" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 7.1 KiB

@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="292px" height="166px" viewBox="0 0 292 166" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>TreeOfAssociationKeys</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="119" height="28" rx="10"></rect>
<filter x="-12.2%" y="-41.1%" width="124.4%" height="203.6%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-5" x="0" y="0" width="119" height="28" rx="10"></rect>
<filter x="-12.2%" y="-41.1%" width="124.4%" height="203.6%" filterUnits="objectBoundingBox" id="filter-7">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-8" x="0" y="0" width="119" height="28" rx="10"></rect>
<filter x="-12.2%" y="-41.1%" width="124.4%" height="203.6%" filterUnits="objectBoundingBox" id="filter-10">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-11" x="0" y="0" width="119" height="28" rx="10"></rect>
<filter x="-12.2%" y="-41.1%" width="124.4%" height="203.6%" filterUnits="objectBoundingBox" id="filter-13">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="TreeOfAssociationKeys" transform="translate(9.000000, 6.000000)">
<path d="M60,78 L60,114" id="Line" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path id="Line-decoration-1" d="M57,103.2 L60,114 L63,103.2" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M139,14 L77,57" id="Line" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path id="Line-decoration-1" d="M84.1648227,48.3799469 L77,57 L87.5842165,53.3102356" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M140,14 L206,57" id="Line-Copy" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path id="Line-Copy-decoration-1" d="M195.313438,53.61808 L206,57 L198.58872,48.5909017" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<g id="Table-Copy-2" transform="translate(80.000000, 0.000000)">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="120" height="29" rx="10"></rect>
</g>
<text id="root" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="45.390625" y="19">root</tspan>
</text>
</g>
<g id="Table-Copy-3" transform="translate(0.000000, 62.000000)">
<mask id="mask-6" fill="white">
<use xlink:href="#path-5"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-5"></use>
<use fill="#417505" fill-rule="evenodd" xlink:href="#path-5"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-5"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="120" height="29" rx="10"></rect>
</g>
<text id="&quot;author&quot;" mask="url(#mask-6)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="30.2421875" y="19">"author"</tspan>
</text>
</g>
<g id="Table-Copy-5" transform="translate(155.000000, 62.000000)">
<mask id="mask-9" fill="white">
<use xlink:href="#path-8"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-10)" xlink:href="#path-8"></use>
<use fill="#9013FE" fill-rule="evenodd" xlink:href="#path-8"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-8"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="120" height="29" rx="10"></rect>
</g>
<text id="&quot;coverImage&quot;" mask="url(#mask-9)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="12.8037109" y="19">"coverImage"</tspan>
</text>
</g>
<g id="Table-Copy-4" transform="translate(0.000000, 120.000000)">
<mask id="mask-12" fill="white">
<use xlink:href="#path-11"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-13)" xlink:href="#path-11"></use>
<use fill="#D0021B" fill-rule="evenodd" xlink:href="#path-11"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-11"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="120" height="29" rx="10"></rect>
</g>
<text id="&quot;country&quot;" mask="url(#mask-12)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="26.2294922" y="19">"country"</tspan>
</text>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.5 KiB

@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="421px" height="227px" viewBox="0 0 421 227" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->
<title>TreeOfAssociationKeysMapping</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="100%" x2="50%" y2="1.41638472e-14%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.9" offset="0%"></stop>
<stop stop-color="#FFFFFF" offset="100%"></stop>
</linearGradient>
<rect id="path-2" x="0" y="0" width="119" height="28" rx="10"></rect>
<filter x="-12.2%" y="-41.1%" width="124.4%" height="203.6%" filterUnits="objectBoundingBox" id="filter-4">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-5" x="0" y="0" width="119" height="28" rx="10"></rect>
<filter x="-12.2%" y="-41.1%" width="124.4%" height="203.6%" filterUnits="objectBoundingBox" id="filter-7">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-8" x="0" y="0" width="119" height="28" rx="10"></rect>
<filter x="-12.2%" y="-41.1%" width="124.4%" height="203.6%" filterUnits="objectBoundingBox" id="filter-10">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<rect id="path-11" x="0" y="0" width="119" height="28" rx="10"></rect>
<filter x="-12.2%" y="-41.1%" width="124.4%" height="203.6%" filterUnits="objectBoundingBox" id="filter-13">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="3" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="4" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="TreeOfAssociationKeysMapping" transform="translate(0.000000, 6.000000)">
<g id="Group-4">
<path d="M83,36 L83,186" id="Line-Copy-2" stroke="#727272" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4,8"></path>
<path d="M159,96 L159,186" id="Line-Copy-3" stroke="#727272" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4,8"></path>
<path d="M246,156 L246,186" id="Line-Copy-4" stroke="#727272" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4,8"></path>
<path d="M352,96 L352,186" id="Line-Copy-5" stroke="#727272" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4,8"></path>
<path d="M85,14 L136,57" id="Line" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path id="Line-decoration-1" d="M125.809367,52.3319166 L136,57 L129.676951,47.7447827" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M85,14 L292,57" id="Line" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path id="Line-decoration-1" d="M280.815576,57.7407092 L292,57 L282.035901,51.8661193" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M156,72 L207,115" id="Line" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<path id="Line-decoration-1" d="M196.809367,110.331917 L207,115 L200.676951,105.744783" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path>
<g id="Table-Copy-6" transform="translate(23.000000, 0.000000)">
<mask id="mask-3" fill="white">
<use xlink:href="#path-2"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-2"></use>
<use fill="#005CC5" fill-rule="evenodd" xlink:href="#path-2"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="120" height="29" rx="10"></rect>
</g>
<text id="root" mask="url(#mask-3)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="45.390625" y="19">root</tspan>
</text>
</g>
<g id="Table-Copy-7" transform="translate(100.000000, 62.000000)">
<mask id="mask-6" fill="white">
<use xlink:href="#path-5"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-7)" xlink:href="#path-5"></use>
<use fill="#417505" fill-rule="evenodd" xlink:href="#path-5"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-5"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="120" height="29" rx="10"></rect>
</g>
<text id="&quot;author&quot;" mask="url(#mask-6)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="30.2421875" y="19">"author"</tspan>
</text>
</g>
<g id="Table-Copy-8" transform="translate(293.000000, 62.000000)">
<mask id="mask-9" fill="white">
<use xlink:href="#path-8"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-10)" xlink:href="#path-8"></use>
<use fill="#9013FE" fill-rule="evenodd" xlink:href="#path-8"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-8"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="120" height="29" rx="10"></rect>
</g>
<text id="&quot;coverImage&quot;" mask="url(#mask-9)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="12.8037109" y="19">"coverImage"</tspan>
</text>
</g>
<g id="Table-Copy-9" transform="translate(187.000000, 120.000000)">
<mask id="mask-12" fill="white">
<use xlink:href="#path-11"></use>
</mask>
<g id="Rectangle">
<use fill="black" fill-opacity="1" filter="url(#filter-13)" xlink:href="#path-11"></use>
<use fill="#D0021B" fill-rule="evenodd" xlink:href="#path-11"></use>
<use fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-11"></use>
<rect stroke-opacity="0.25" stroke="#000000" stroke-width="1" x="-0.5" y="-0.5" width="120" height="29" rx="10"></rect>
</g>
<text id="&quot;country&quot;" mask="url(#mask-12)" font-family="-apple-system,sans-serif" font-size="14" font-weight="500" fill="#000000">
<tspan x="26.2294922" y="19">"country"</tspan>
</text>
</g>
<g id="Group-5" transform="translate(0.000000, 191.000000)" font-family="Menlo-Regular, Menlo" font-size="14" font-weight="normal">
<text id="SELECT-book.*,-autho">
<tspan x="0" y="13" fill="#404040">SELECT </tspan>
<tspan x="59.0009766" y="13" fill="#4A90E2">book.*</tspan>
<tspan x="109.573242" y="13" fill="#404040">, </tspan>
<tspan x="126.430664" y="13" fill="#417505">author.*</tspan>
<tspan x="193.860352" y="13" fill="#404040">, </tspan>
<tspan x="210.717773" y="13" fill="#D0021B">country.*</tspan>
<tspan x="286.576172" y="13" fill="#404040">, </tspan>
<tspan x="303.433594" y="13" fill="#9013FE">coverImage.*</tspan>
<tspan x="404.578125" y="13" fill="#404040"></tspan>
<tspan x="0" y="29" fill="#404040">FROM …</tspan>
</text>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 10 KiB

+180 -8
View File
@@ -148,6 +148,64 @@
564F9C2D1F075DD200877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
564F9C311F07611600877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
564F9C341F07611900877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
5653EAD620944B4F00F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAC620944B4C00F46237 /* AssociationChainRowScopesTests.swift */; };
5653EAD720944B4F00F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAC620944B4C00F46237 /* AssociationChainRowScopesTests.swift */; };
5653EAD820944B4F00F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAC720944B4C00F46237 /* AssociationBelongsToRowScopeTests.swift */; };
5653EAD920944B4F00F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAC720944B4C00F46237 /* AssociationBelongsToRowScopeTests.swift */; };
5653EADA20944B4F00F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAC820944B4D00F46237 /* AssociationRowScopeSearchTests.swift */; };
5653EADB20944B4F00F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAC820944B4D00F46237 /* AssociationRowScopeSearchTests.swift */; };
5653EADC20944B4F00F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAC920944B4D00F46237 /* AssociationBelongsToSQLTests.swift */; };
5653EADD20944B4F00F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAC920944B4D00F46237 /* AssociationBelongsToSQLTests.swift */; };
5653EADE20944B4F00F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACA20944B4D00F46237 /* AssociationHasOneSQLDerivationTests.swift */; };
5653EADF20944B4F00F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACA20944B4D00F46237 /* AssociationHasOneSQLDerivationTests.swift */; };
5653EAE020944B4F00F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACB20944B4D00F46237 /* AssociationTableAliasTestsSQLTests.swift */; };
5653EAE120944B4F00F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACB20944B4D00F46237 /* AssociationTableAliasTestsSQLTests.swift */; };
5653EAE220944B4F00F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACC20944B4D00F46237 /* AssociationHasOneSQLTests.swift */; };
5653EAE320944B4F00F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACC20944B4D00F46237 /* AssociationHasOneSQLTests.swift */; };
5653EAE420944B4F00F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACD20944B4D00F46237 /* AssociationParallelRowScopesTests.swift */; };
5653EAE520944B4F00F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACD20944B4D00F46237 /* AssociationParallelRowScopesTests.swift */; };
5653EAE620944B4F00F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACE20944B4D00F46237 /* AssociationBelongsToFetchableRecordTests.swift */; };
5653EAE720944B4F00F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACE20944B4D00F46237 /* AssociationBelongsToFetchableRecordTests.swift */; };
5653EAE820944B4F00F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACF20944B4E00F46237 /* AssociationChainSQLTests.swift */; };
5653EAE920944B4F00F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EACF20944B4E00F46237 /* AssociationChainSQLTests.swift */; };
5653EAEC20944B4F00F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAD120944B4E00F46237 /* AssociationBelongsToSQLDerivationTests.swift */; };
5653EAED20944B4F00F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAD120944B4E00F46237 /* AssociationBelongsToSQLDerivationTests.swift */; };
5653EAEE20944B4F00F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAD220944B4E00F46237 /* AssociationParallelDecodableRecordTests.swift */; };
5653EAEF20944B4F00F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAD220944B4E00F46237 /* AssociationParallelDecodableRecordTests.swift */; };
5653EAF220944B4F00F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAD420944B4E00F46237 /* AssociationBelongsToDecodableRecordTests.swift */; };
5653EAF320944B4F00F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAD420944B4E00F46237 /* AssociationBelongsToDecodableRecordTests.swift */; };
5653EAF420944B4F00F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAD520944B4F00F46237 /* AssociationParallelSQLTests.swift */; };
5653EAF520944B4F00F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAD520944B4F00F46237 /* AssociationParallelSQLTests.swift */; };
5653EB0320944C7C00F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */; };
5653EB0420944C7C00F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */; };
5653EB0520944C7C00F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */; };
5653EB0620944C7C00F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */; };
5653EB0720944C7C00F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */; };
5653EB0820944C7C00F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */; };
5653EB0920944C7C00F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFA20944C7B00F46237 /* Association.swift */; };
5653EB0A20944C7C00F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFA20944C7B00F46237 /* Association.swift */; };
5653EB0B20944C7C00F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFA20944C7B00F46237 /* Association.swift */; };
5653EB0C20944C7C00F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */; };
5653EB0D20944C7C00F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */; };
5653EB0E20944C7C00F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */; };
5653EB0F20944C7C00F46237 /* AssociationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFC20944C7B00F46237 /* AssociationRequest.swift */; };
5653EB1020944C7C00F46237 /* AssociationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFC20944C7B00F46237 /* AssociationRequest.swift */; };
5653EB1120944C7C00F46237 /* AssociationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFC20944C7B00F46237 /* AssociationRequest.swift */; };
5653EB1520944C7C00F46237 /* AssociationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFE20944C7C00F46237 /* AssociationQuery.swift */; };
5653EB1620944C7C00F46237 /* AssociationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFE20944C7C00F46237 /* AssociationQuery.swift */; };
5653EB1720944C7C00F46237 /* AssociationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFE20944C7C00F46237 /* AssociationQuery.swift */; };
5653EB1820944C7C00F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFF20944C7C00F46237 /* ForeignKey.swift */; };
5653EB1920944C7C00F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFF20944C7C00F46237 /* ForeignKey.swift */; };
5653EB1A20944C7C00F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EAFF20944C7C00F46237 /* ForeignKey.swift */; };
5653EB2120944C7C00F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB0220944C7C00F46237 /* HasOneAssociation.swift */; };
5653EB2220944C7C00F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB0220944C7C00F46237 /* HasOneAssociation.swift */; };
5653EB2320944C7C00F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB0220944C7C00F46237 /* HasOneAssociation.swift */; };
5653EB252094A14400F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB242094A14400F46237 /* QueryInterfaceRequest+Association.swift */; };
5653EB262094A14400F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB242094A14400F46237 /* QueryInterfaceRequest+Association.swift */; };
5653EB272094A14400F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB242094A14400F46237 /* QueryInterfaceRequest+Association.swift */; };
5653EC122098738B00F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC0B2098738B00F46237 /* SQLGenerationContext.swift */; };
5653EC132098738B00F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC0B2098738B00F46237 /* SQLGenerationContext.swift */; };
5653EC142098738B00F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC0B2098738B00F46237 /* SQLGenerationContext.swift */; };
565490B41D5A4820005622CB /* GRDB.h in Headers */ = {isa = PBXBuildFile; fileRef = DC3773F819C8CBB3004FCF85 /* GRDB.h */; settings = {ATTRIBUTES = (Public, ); }; };
565490B51D5A4827005622CB /* GRDB-Bridging.h in Headers */ = {isa = PBXBuildFile; fileRef = DC2393C61ABE35F8003FF113 /* GRDB-Bridging.h */; settings = {ATTRIBUTES = (Public, ); }; };
565490B61D5AE236005622CB /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238701B9C75030082EB20 /* Configuration.swift */; };
@@ -423,9 +481,6 @@
56B021CD1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; };
56B14E831D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */; };
56B15D0B1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; };
56B1C3CD201C8D0E001938DA /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B1C3CC201C8D0E001938DA /* Swift4.1.swift */; };
56B1C3CE201C8D0E001938DA /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B1C3CC201C8D0E001938DA /* Swift4.1.swift */; };
56B1C3CF201C8D0E001938DA /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B1C3CC201C8D0E001938DA /* Swift4.1.swift */; };
56B6EF56208CB4E3002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */; };
56B6EF57208CB4E3002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */; };
56B7F42A1BE14A1900E39BBF /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; };
@@ -809,6 +864,30 @@
564E73DE203D50B9000C443C /* JoinSupportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = "<group>"; };
564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAggregateTests.swift; sourceTree = "<group>"; };
564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunction.swift; sourceTree = "<group>"; };
5653EAC620944B4C00F46237 /* AssociationChainRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainRowScopesTests.swift; sourceTree = "<group>"; };
5653EAC720944B4C00F46237 /* AssociationBelongsToRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToRowScopeTests.swift; sourceTree = "<group>"; };
5653EAC820944B4D00F46237 /* AssociationRowScopeSearchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRowScopeSearchTests.swift; sourceTree = "<group>"; };
5653EAC920944B4D00F46237 /* AssociationBelongsToSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLTests.swift; sourceTree = "<group>"; };
5653EACA20944B4D00F46237 /* AssociationHasOneSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLDerivationTests.swift; sourceTree = "<group>"; };
5653EACB20944B4D00F46237 /* AssociationTableAliasTestsSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationTableAliasTestsSQLTests.swift; sourceTree = "<group>"; };
5653EACC20944B4D00F46237 /* AssociationHasOneSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLTests.swift; sourceTree = "<group>"; };
5653EACD20944B4D00F46237 /* AssociationParallelRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelRowScopesTests.swift; sourceTree = "<group>"; };
5653EACE20944B4D00F46237 /* AssociationBelongsToFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToFetchableRecordTests.swift; sourceTree = "<group>"; };
5653EACF20944B4E00F46237 /* AssociationChainSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainSQLTests.swift; sourceTree = "<group>"; };
5653EAD120944B4E00F46237 /* AssociationBelongsToSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLDerivationTests.swift; sourceTree = "<group>"; };
5653EAD220944B4E00F46237 /* AssociationParallelDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelDecodableRecordTests.swift; sourceTree = "<group>"; };
5653EAD420944B4E00F46237 /* AssociationBelongsToDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToDecodableRecordTests.swift; sourceTree = "<group>"; };
5653EAD520944B4F00F46237 /* AssociationParallelSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelSQLTests.swift; sourceTree = "<group>"; };
5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BelongsToAssociation.swift; sourceTree = "<group>"; };
5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyRequest.swift; sourceTree = "<group>"; };
5653EAFA20944C7B00F46237 /* Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Association.swift; sourceTree = "<group>"; };
5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyAssociation.swift; sourceTree = "<group>"; };
5653EAFC20944C7B00F46237 /* AssociationRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRequest.swift; sourceTree = "<group>"; };
5653EAFE20944C7C00F46237 /* AssociationQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationQuery.swift; sourceTree = "<group>"; };
5653EAFF20944C7C00F46237 /* ForeignKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKey.swift; sourceTree = "<group>"; };
5653EB0220944C7C00F46237 /* HasOneAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasOneAssociation.swift; sourceTree = "<group>"; };
5653EB242094A14400F46237 /* QueryInterfaceRequest+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "QueryInterfaceRequest+Association.swift"; sourceTree = "<group>"; };
5653EC0B2098738B00F46237 /* SQLGenerationContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLGenerationContext.swift; sourceTree = "<group>"; };
565490A01D5A4798005622CB /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
56553C181C3E906C00522B5C /* GRDBOSXCrashTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXCrashTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5657AAB81D107001006283EF /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = "<group>"; };
@@ -948,7 +1027,6 @@
56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = "<group>"; };
56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = "<group>"; };
56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsControllerTests.swift; sourceTree = "<group>"; };
56B1C3CC201C8D0E001938DA /* Swift4.1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swift4.1.swift; sourceTree = "<group>"; };
56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = "<group>"; };
56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = "<group>"; };
56B7F4391BEB42D500E39BBF /* Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = "<group>"; };
@@ -1268,6 +1346,7 @@
56300B5C1C53C38F005A543B /* QueryInterface */ = {
isa = PBXGroup;
children = (
5653EABF20944B1300F46237 /* Association */,
56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */,
56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */,
56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */,
@@ -1284,17 +1363,20 @@
56300B6D1C53F592005A543B /* QueryInterface */ = {
isa = PBXGroup;
children = (
5653EAF720944BC900F46237 /* Association */,
56CEB5401EAA359A00BFAF62 /* Column.swift */,
56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */,
56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */,
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */,
56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */,
5653EB242094A14400F46237 /* QueryInterfaceRequest+Association.swift */,
5616AAF0207CD45E00AC3664 /* RequestProtocols.swift */,
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */,
566475991D97D8A000FF74B8 /* SQLCollection.swift */,
56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */,
56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */,
56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */,
5653EC0B2098738B00F46237 /* SQLGenerationContext.swift */,
56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */,
56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */,
566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */,
@@ -1319,6 +1401,42 @@
name = DatabaseQueue;
sourceTree = "<group>";
};
5653EABF20944B1300F46237 /* Association */ = {
isa = PBXGroup;
children = (
5653EAD420944B4E00F46237 /* AssociationBelongsToDecodableRecordTests.swift */,
5653EACE20944B4D00F46237 /* AssociationBelongsToFetchableRecordTests.swift */,
5653EAC720944B4C00F46237 /* AssociationBelongsToRowScopeTests.swift */,
5653EAD120944B4E00F46237 /* AssociationBelongsToSQLDerivationTests.swift */,
5653EAC920944B4D00F46237 /* AssociationBelongsToSQLTests.swift */,
5653EAC620944B4C00F46237 /* AssociationChainRowScopesTests.swift */,
5653EACF20944B4E00F46237 /* AssociationChainSQLTests.swift */,
5653EACA20944B4D00F46237 /* AssociationHasOneSQLDerivationTests.swift */,
5653EACC20944B4D00F46237 /* AssociationHasOneSQLTests.swift */,
5653EAD220944B4E00F46237 /* AssociationParallelDecodableRecordTests.swift */,
5653EACD20944B4D00F46237 /* AssociationParallelRowScopesTests.swift */,
5653EAD520944B4F00F46237 /* AssociationParallelSQLTests.swift */,
5653EAC820944B4D00F46237 /* AssociationRowScopeSearchTests.swift */,
5653EACB20944B4D00F46237 /* AssociationTableAliasTestsSQLTests.swift */,
);
name = Association;
sourceTree = "<group>";
};
5653EAF720944BC900F46237 /* Association */ = {
isa = PBXGroup;
children = (
5653EAFA20944C7B00F46237 /* Association.swift */,
5653EAFE20944C7C00F46237 /* AssociationQuery.swift */,
5653EAFC20944C7B00F46237 /* AssociationRequest.swift */,
5653EAF820944C7B00F46237 /* BelongsToAssociation.swift */,
5653EAFF20944C7C00F46237 /* ForeignKey.swift */,
5653EAF920944C7B00F46237 /* ForeignKeyRequest.swift */,
5653EAFB20944C7B00F46237 /* HasManyAssociation.swift */,
5653EB0220944C7C00F46237 /* HasOneAssociation.swift */,
);
path = Association;
sourceTree = "<group>";
};
5659F4861EA8D94E004A4992 /* Utils */ = {
isa = PBXGroup;
children = (
@@ -1626,7 +1744,6 @@
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */,
56B1C3CC201C8D0E001938DA /* Swift4.1.swift */,
);
path = Legacy;
sourceTree = "<group>";
@@ -2191,6 +2308,7 @@
5698AD1C1DAAD17F0056AF8C /* FTS5Tokenizer.swift in Sources */,
56CEB5171EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */,
56B964B71DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */,
5653EB0B20944C7C00F46237 /* Association.swift in Sources */,
56F5ABDA1D814330001F60CB /* NSData.swift in Sources */,
56D121601ED34978001347D2 /* Fixits-0.109.0.swift in Sources */,
564F9C341F07611900877A00 /* DatabaseFunction.swift in Sources */,
@@ -2198,6 +2316,7 @@
5659F4961EA8D964004A4992 /* ReadWriteBox.swift in Sources */,
5659F48E1EA8D94E004A4992 /* Utils.swift in Sources */,
56CEB5671EAA359A00BFAF62 /* SQLSelectable.swift in Sources */,
5653EB272094A14400F46237 /* QueryInterfaceRequest+Association.swift in Sources */,
565490B91D5AE236005622CB /* DatabasePool.swift in Sources */,
5674A6EF1F307F0E0095F066 /* DatabaseValueConvertible+Encodable.swift in Sources */,
565490D81D5AE252005622CB /* DatabaseMigrator.swift in Sources */,
@@ -2207,12 +2326,14 @@
565490D91D5AE252005622CB /* Migration.swift in Sources */,
56CEB5001EAA2F4D00BFAF62 /* FTS3.swift in Sources */,
5698AD271DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
5653EB1120944C7C00F46237 /* AssociationRequest.swift in Sources */,
C96C0F2D2084A45A006B2981 /* SQLiteDateParser.swift in Sources */,
566A841C2041146100E50BFD /* DatabaseSnapshot.swift in Sources */,
565490D51D5AE252005622CB /* DatabaseValueConvertible+RawRepresentable.swift in Sources */,
565490C51D5AE236005622CB /* SerializedDatabase.swift in Sources */,
56F3E7691E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */,
5698AC7E1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */,
5653EB1A20944C7C00F46237 /* ForeignKey.swift in Sources */,
5698AC3D1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
565490BF1D5AE236005622CB /* DatabaseValueConvertible.swift in Sources */,
566B91191FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */,
@@ -2227,6 +2348,7 @@
565490C31D5AE236005622CB /* RowAdapter.swift in Sources */,
5698AD3B1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */,
5659F49E1EA8D989004A4992 /* Pool.swift in Sources */,
5653EB0E20944C7C00F46237 /* HasManyAssociation.swift in Sources */,
565490DA1D5AE252005622CB /* QueryInterfaceRequest.swift in Sources */,
565490CA1D5AE252005622CB /* DatabaseDateComponents.swift in Sources */,
565490D01D5AE252005622CB /* NSString.swift in Sources */,
@@ -2235,6 +2357,7 @@
5674A6E81F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */,
56873BF21F2CB400004D24B4 /* Fixits-1.2.swift in Sources */,
56BF6D431DEF47DA006039A3 /* Fixits-Swift2.swift in Sources */,
5653EB2320944C7C00F46237 /* HasOneAssociation.swift in Sources */,
565490C01D5AE236005622CB /* DatabaseWriter.swift in Sources */,
565490C41D5AE236005622CB /* SchedulingWatchdog.swift in Sources */,
566B91311FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
@@ -2243,6 +2366,7 @@
56BF6D351DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */,
566B91291FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
5671FC261DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */,
5653EC142098738B00F46237 /* SQLGenerationContext.swift in Sources */,
56CEB5521EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
565490DB1D5AE252005622CB /* SQLCollatedExpression.swift in Sources */,
5674A7071F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */,
@@ -2267,13 +2391,15 @@
56F5ABDD1D814330001F60CB /* UUID.swift in Sources */,
565490CB1D5AE252005622CB /* (null) in Sources */,
565490D61D5AE252005622CB /* StandardLibrary.swift in Sources */,
5653EB1720944C7C00F46237 /* AssociationQuery.swift in Sources */,
565490B81D5AE236005622CB /* DatabaseError.swift in Sources */,
56BF6D3C1DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */,
56B1C3CF201C8D0E001938DA /* Swift4.1.swift in Sources */,
56DAA2E11DE9C827006E10C8 /* Cursor.swift in Sources */,
5653EB0520944C7C00F46237 /* BelongsToAssociation.swift in Sources */,
565490BC1D5AE236005622CB /* DatabaseSchemaCache.swift in Sources */,
565490BA1D5AE236005622CB /* DatabaseQueue.swift in Sources */,
565490CD1D5AE252005622CB /* Date.swift in Sources */,
5653EB0820944C7C00F46237 /* ForeignKeyRequest.swift in Sources */,
565490BE1D5AE236005622CB /* DatabaseValue.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -2307,16 +2433,19 @@
5605F18E1C6B1A8700235C62 /* SQLCollatedExpression.swift in Sources */,
566475D61D981D5E00FF74B8 /* SQLOperators.swift in Sources */,
5698AD381DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */,
5653EB0A20944C7C00F46237 /* Association.swift in Sources */,
56A2387E1B9C75030082EB20 /* Database.swift in Sources */,
56CEB4FD1EAA2F4D00BFAF62 /* FTS3.swift in Sources */,
5605F15A1C672E4000235C62 /* CGFloat.swift in Sources */,
56CEB5481EAA359A00BFAF62 /* Column.swift in Sources */,
5653EB262094A14400F46237 /* QueryInterfaceRequest+Association.swift in Sources */,
5605F1641C672E4000235C62 /* Date.swift in Sources */,
566B91361FA4D3810012D5B0 /* TransactionObserver.swift in Sources */,
5605F1721C672E4000235C62 /* DatabaseValueConvertible+RawRepresentable.swift in Sources */,
56CEB5141EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */,
566475CF1D981D5E00FF74B8 /* SQLFunctions.swift in Sources */,
5659F49B1EA8D989004A4992 /* Pool.swift in Sources */,
5653EB2220944C7C00F46237 /* HasOneAssociation.swift in Sources */,
569A98EE2039B6F3008D7DBF /* Fixits-3.0.swift in Sources */,
56CEB51C1EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */,
5698AC3A1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
@@ -2325,6 +2454,7 @@
563363C51C942C37000BE133 /* DatabaseWriter.swift in Sources */,
5698AD1B1DAAD17D0056AF8C /* FTS5Tokenizer.swift in Sources */,
56F3E7661E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */,
5653EB0420944C7C00F46237 /* BelongsToAssociation.swift in Sources */,
56B964B41DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */,
560A37A81C8FF6E500949E71 /* SerializedDatabase.swift in Sources */,
566A841B2041146100E50BFD /* DatabaseSnapshot.swift in Sources */,
@@ -2335,11 +2465,14 @@
56A8C2331D1914540096E9D4 /* UUID.swift in Sources */,
56BF6D321DEF47DA006039A3 /* Fixits-0-84-0.swift in Sources */,
560D92411C672C3E00F4F92B /* DatabaseValueConvertible.swift in Sources */,
5653EB1020944C7C00F46237 /* AssociationRequest.swift in Sources */,
566475BD1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */,
56A238A51B9C753B0082EB20 /* Record.swift in Sources */,
5671FC231DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */,
56D51D031EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */,
5653EB1620944C7C00F46237 /* AssociationQuery.swift in Sources */,
560D924C1C672C4B00F4F92B /* TableRecord.swift in Sources */,
5653EC132098738B00F46237 /* SQLGenerationContext.swift in Sources */,
5657AB121D10899D006283EF /* URL.swift in Sources */,
5616AAF2207CD45E00AC3664 /* RequestProtocols.swift in Sources */,
5659F48B1EA8D94E004A4992 /* Utils.swift in Sources */,
@@ -2349,7 +2482,6 @@
5674A7081F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */,
56A2388C1B9C75030082EB20 /* Statement.swift in Sources */,
5659F4931EA8D964004A4992 /* ReadWriteBox.swift in Sources */,
56B1C3CE201C8D0E001938DA /* Swift4.1.swift in Sources */,
5605F1941C6B1A8700235C62 /* QueryInterfaceQuery.swift in Sources */,
56B7F43B1BEB42D500E39BBF /* Migration.swift in Sources */,
5690C3431D23E82A00E59934 /* Data.swift in Sources */,
@@ -2363,6 +2495,7 @@
5605F15E1C672E4000235C62 /* DatabaseDateComponents.swift in Sources */,
56BF6D391DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */,
563363C11C942C04000BE133 /* DatabaseReader.swift in Sources */,
5653EB1920944C7C00F46237 /* ForeignKey.swift in Sources */,
5659F4A31EA8D997004A4992 /* Result.swift in Sources */,
56B964BC1DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */,
5605F1661C672E4000235C62 /* NSNull.swift in Sources */,
@@ -2371,6 +2504,7 @@
5698AC7B1DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */,
56A238821B9C75030082EB20 /* DatabaseError.swift in Sources */,
56D1215D1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */,
5653EB0D20944C7C00F46237 /* HasManyAssociation.swift in Sources */,
566AD8B51D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
5698AD241DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
C96C0F2C2084A459006B2981 /* SQLiteDateParser.swift in Sources */,
@@ -2380,6 +2514,7 @@
560D92481C672C4B00F4F92B /* PersistableRecord.swift in Sources */,
560D92431C672C3E00F4F92B /* StatementColumnConvertible.swift in Sources */,
566475A51D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */,
5653EB0720944C7C00F46237 /* ForeignKeyRequest.swift in Sources */,
5657AABC1D107001006283EF /* NSData.swift in Sources */,
31A778841C6A4E0600F507F6 /* FetchedRecordsController.swift in Sources */,
56A238861B9C75030082EB20 /* DatabaseValue.swift in Sources */,
@@ -2434,6 +2569,7 @@
56B14E831D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */,
562393341DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */,
5698AC841DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */,
5653EAE320944B4F00F46237 /* AssociationHasOneSQLTests.swift in Sources */,
566AD8CA1D531BEC002EC1A8 /* TableDefinitionTests.swift in Sources */,
56A238541B9C74A90082EB20 /* RecordPrimaryKeyMultipleTests.swift in Sources */,
56FDECE31BB32DFD009AD709 /* RowFromStatementTests.swift in Sources */,
@@ -2448,12 +2584,14 @@
5657AB421D108BA9006283EF /* FoundationNSDataTests.swift in Sources */,
56CC922D201DFFB900CB597E /* DropWhileCursorTests.swift in Sources */,
56D507621F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */,
5653EADD20944B4F00F46237 /* AssociationBelongsToSQLTests.swift in Sources */,
56176C6B1EACCCC9000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */,
56300B621C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */,
56EA869F1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift in Sources */,
567F45AC1F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */,
5657AB621D108BA9006283EF /* FoundationNSURLTests.swift in Sources */,
5657AB6A1D108BA9006283EF /* FoundationURLTests.swift in Sources */,
5653EADF20944B4F00F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */,
56F3E74D1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */,
56EB0AB31BCD787300A3DC55 /* DataMemoryTests.swift in Sources */,
56B6EF57208CB4E3002F0ACB /* ColumnExpressionTests.swift in Sources */,
@@ -2472,6 +2610,7 @@
560A37AC1C90085D00949E71 /* DatabasePoolConcurrencyTests.swift in Sources */,
5607EFD41BB827FD00605DE3 /* TransactionObserverTests.swift in Sources */,
5690C33B1D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
5653EAF320944B4F00F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */,
565D5D721BBC694D00DC9BD4 /* Row+FoundationTests.swift in Sources */,
5623936D1DEE0CD200A6B01F /* FlattenCursorTests.swift in Sources */,
567A80571D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
@@ -2491,19 +2630,25 @@
565B0FF01BBC7D980098DE03 /* FetchableRecordTests.swift in Sources */,
5698AC9A1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */,
562393521DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */,
5653EAE520944B4F00F46237 /* AssociationParallelRowScopesTests.swift in Sources */,
56A4CDB41D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */,
56CC9247201E058100CB597E /* DropFirstCursorTests.swift in Sources */,
56E8CE0E1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift in Sources */,
56A238581B9C74A90082EB20 /* RecordPrimaryKeyRowIDTests.swift in Sources */,
56A5EF131EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */,
5653EAE920944B4F00F46237 /* AssociationChainSQLTests.swift in Sources */,
5698ACD21DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */,
56A238621B9C74A90082EB20 /* RecordEditedTests.swift in Sources */,
5653EAE120944B4F00F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */,
5653EAE720944B4F00F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */,
5695312A1C908A5B00CF1A2B /* DatabasePoolSchemaCacheTests.swift in Sources */,
5653EADB20944B4F00F46237 /* AssociationRowScopeSearchTests.swift in Sources */,
5698ACA21DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */,
56A2385C1B9C74A90082EB20 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */,
56A238401B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift in Sources */,
564F9C221F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */,
56A8C2481D1918F00096E9D4 /* FoundationUUIDTests.swift in Sources */,
5653EAEF20944B4F00F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
56A2383C1B9C74A90082EB20 /* DatabaseErrorTests.swift in Sources */,
5690C32A1D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */,
5657AB3A1D108BA9006283EF /* FoundationDataTests.swift in Sources */,
@@ -2519,17 +2664,21 @@
568068351EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */,
565D5D751BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift in Sources */,
5623931C1DECC02000A6B01F /* RowFetchTests.swift in Sources */,
5653EAD720944B4F00F46237 /* AssociationChainRowScopesTests.swift in Sources */,
562393641DEE06D300A6B01F /* CursorTests.swift in Sources */,
5657AB5A1D108BA9006283EF /* FoundationNSStringTests.swift in Sources */,
56300B6C1C53D3E8005A543B /* TableRecord+QueryInterfaceRequestTests.swift in Sources */,
5674A7231F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */,
56F0B9921B6001C600A2F135 /* FoundationNSDateTests.swift in Sources */,
56A238381B9C74A90082EB20 /* DatabaseTests.swift in Sources */,
5653EAED20944B4F00F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */,
56300B5F1C53C38F005A543B /* QueryInterfaceRequestTests.swift in Sources */,
5634B10A1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */,
560C97C81BFD0B8400BF8471 /* DatabaseFunctionTests.swift in Sources */,
5653EAD920944B4F00F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */,
56A2383A1B9C74A90082EB20 /* DatabaseQueueInMemoryTests.swift in Sources */,
56A5E40A1BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift in Sources */,
5653EAF520944B4F00F46237 /* AssociationParallelSQLTests.swift in Sources */,
56FF455A1D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */,
56B7F42A1BE14A1900E39BBF /* CGFloatTests.swift in Sources */,
5605F1881C69111300235C62 /* DatabaseRegionTests.swift in Sources */,
@@ -2581,6 +2730,7 @@
56D4967C1D8130DB008276D7 /* CGFloatTests.swift in Sources */,
56D496631D81304E008276D7 /* FoundationURLTests.swift in Sources */,
56D496B71D81344B008276D7 /* RecordUniqueIndexTests.swift in Sources */,
5653EAE220944B4F00F46237 /* AssociationHasOneSQLTests.swift in Sources */,
56D496671D813086008276D7 /* Record+QueryInterfaceRequestTests.swift in Sources */,
56DAA2D21DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */,
56D496AE1D813345008276D7 /* DatabasePoolCollationTests.swift in Sources */,
@@ -2595,12 +2745,14 @@
56D4965E1D81304E008276D7 /* FoundationNSStringTests.swift in Sources */,
5698AC891DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */,
56CC922C201DFFB900CB597E /* DropWhileCursorTests.swift in Sources */,
5653EADC20944B4F00F46237 /* AssociationBelongsToSQLTests.swift in Sources */,
56D5075E1F6BAE8600AE1C5B /* PrimaryKeyInfoTests.swift in Sources */,
56176C591EACCCC7000F3F2B /* FTS5CustomTokenizerTests.swift in Sources */,
56D4968A1D81316E008276D7 /* DatabaseValueConvertibleSubclassTests.swift in Sources */,
56D496601D81304E008276D7 /* FoundationNSUUIDTests.swift in Sources */,
567F45A81F888B2600030B59 /* TruncateOptimizationTests.swift in Sources */,
56D4968D1D81316E008276D7 /* DatabaseFunctionTests.swift in Sources */,
5653EADE20944B4F00F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */,
56D496661D813086008276D7 /* QueryInterfaceRequestTests.swift in Sources */,
56F3E7491E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */,
56B6EF56208CB4E3002F0ACB /* ColumnExpressionTests.swift in Sources */,
@@ -2619,6 +2771,7 @@
5698AC031D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */,
56D496611D81304E008276D7 /* Row+FoundationTests.swift in Sources */,
56D496C41D813767008276D7 /* DatabaseQueueTests.swift in Sources */,
5653EAF220944B4F00F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */,
56D496851D813147008276D7 /* StatementArgumentsTests.swift in Sources */,
56D496B81D813465008276D7 /* DataMemoryTests.swift in Sources */,
56D496541D812F5B008276D7 /* SQLExpressionLiteralTests.swift in Sources */,
@@ -2638,19 +2791,25 @@
56176C5D1EACCCC7000F3F2B /* FTS5TokenizerTests.swift in Sources */,
56D496B21D8133CE008276D7 /* DatabaseQueueInMemoryTests.swift in Sources */,
562393601DEE06D300A6B01F /* CursorTests.swift in Sources */,
5653EAE420944B4F00F46237 /* AssociationParallelRowScopesTests.swift in Sources */,
56D4968F1D81316E008276D7 /* RowFromDictionaryTests.swift in Sources */,
56D4968E1D81316E008276D7 /* RowCopiedFromStatementTests.swift in Sources */,
56CC9246201E058100CB597E /* DropFirstCursorTests.swift in Sources */,
5698AC401DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */,
562393571DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
5653EAE820944B4F00F46237 /* AssociationChainSQLTests.swift in Sources */,
56A5EF0F1EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */,
56D496B61D813434008276D7 /* DatabaseRegionTests.swift in Sources */,
5653EAE020944B4F00F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */,
5653EAE620944B4F00F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */,
562393181DECC02000A6B01F /* RowFetchTests.swift in Sources */,
5653EADA20944B4F00F46237 /* AssociationRowScopeSearchTests.swift in Sources */,
56D4965A1D81304E008276D7 /* FoundationNSDataTests.swift in Sources */,
56D496741D81309E008276D7 /* RecordCopyTests.swift in Sources */,
56D496791D81309E008276D7 /* RecordWithColumnNameManglingTests.swift in Sources */,
56D4966C1D81309E008276D7 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */,
564F9C1E1F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */,
5653EAEE20944B4F00F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
56D496861D813147008276D7 /* UpdateStatementTests.swift in Sources */,
56D4965D1D81304E008276D7 /* FoundationNSNumberTests.swift in Sources */,
56B021C91D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */,
@@ -2666,17 +2825,21 @@
568068311EBBA26100EFB8AA /* SQLRequestTests.swift in Sources */,
56D496B41D8133F8008276D7 /* DatabaseTests.swift in Sources */,
56D496951D81317B008276D7 /* MutablePersistableRecordTests.swift in Sources */,
5653EAD620944B4F00F46237 /* AssociationChainRowScopesTests.swift in Sources */,
5698AC801DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */,
56D496821D813131008276D7 /* TransactionObserverTests.swift in Sources */,
56D496941D81317B008276D7 /* SchedulingWatchdogTests.swift in Sources */,
5674A7201F30A8DF0095F066 /* MutablePersistableRecordEncodableTests.swift in Sources */,
56D496551D812F83008276D7 /* FoundationDataTests.swift in Sources */,
56D4966A1D813086008276D7 /* TableRecord+QueryInterfaceRequestTests.swift in Sources */,
5653EAEC20944B4F00F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */,
562206071E420EA4005860AC /* DatabasePoolConcurrencyTests.swift in Sources */,
5698ACB61DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */,
56D4965C1D81304E008276D7 /* FoundationNSNullTests.swift in Sources */,
5653EAD820944B4F00F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */,
562205F11E420E47005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */,
56D4967F1D813131008276D7 /* StatementColumnConvertibleTests.swift in Sources */,
5653EAF420944B4F00F46237 /* AssociationParallelSQLTests.swift in Sources */,
56D496971D81317B008276D7 /* DatabaseReaderTests.swift in Sources */,
56D496911D81316E008276D7 /* RowFromStatementTests.swift in Sources */,
56071A411DB54ED000CA6E47 /* FetchedRecordsControllerTests.swift in Sources */,
@@ -2728,11 +2891,13 @@
5664759A1D97D8A000FF74B8 /* SQLCollection.swift in Sources */,
567404881CEF84C8003ED5CC /* RowAdapter.swift in Sources */,
56E06F061E859064008AE2A4 /* Fixits-0.102.0.swift in Sources */,
5653EB0320944C7C00F46237 /* BelongsToAssociation.swift in Sources */,
563363C41C942C37000BE133 /* DatabaseWriter.swift in Sources */,
5698AD181DAAD17A0056AF8C /* FTS5Tokenizer.swift in Sources */,
56F3E7631E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */,
56B964B11DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */,
560A37A71C8FF6E500949E71 /* SerializedDatabase.swift in Sources */,
5653EB252094A14400F46237 /* QueryInterfaceRequest+Association.swift in Sources */,
5605F1691C672E4000235C62 /* NSString.swift in Sources */,
560D92401C672C3E00F4F92B /* DatabaseValueConvertible.swift in Sources */,
56A8C2301D1914540096E9D4 /* UUID.swift in Sources */,
@@ -2742,6 +2907,7 @@
56A238811B9C75030082EB20 /* DatabaseError.swift in Sources */,
56D51D001EA789FA0074638A /* FetchableRecord+TableRecord.swift in Sources */,
566475BA1D981AD200FF74B8 /* SQLSpecificExpressible+QueryInterface.swift in Sources */,
5653EB0920944C7C00F46237 /* Association.swift in Sources */,
56A238851B9C75030082EB20 /* DatabaseValue.swift in Sources */,
5671FC201DA3CAC9003BF4FF /* FTS3TokenizerDescriptor.swift in Sources */,
56A238A41B9C753B0082EB20 /* Record.swift in Sources */,
@@ -2755,7 +2921,6 @@
5605F1931C6B1A8700235C62 /* QueryInterfaceQuery.swift in Sources */,
566B912B1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
56A2388B1B9C75030082EB20 /* Statement.swift in Sources */,
56B1C3CD201C8D0E001938DA /* Swift4.1.swift in Sources */,
5690C3401D23E82A00E59934 /* Data.swift in Sources */,
5659F4881EA8D94E004A4992 /* Utils.swift in Sources */,
56FC98781D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */,
@@ -2763,12 +2928,16 @@
5695311F1C907A8C00CF1A2B /* DatabaseSchemaCache.swift in Sources */,
5605F15D1C672E4000235C62 /* DatabaseDateComponents.swift in Sources */,
56BF6D361DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */,
5653EB0F20944C7C00F46237 /* AssociationRequest.swift in Sources */,
56193E8E1CD8A3E200F95862 /* FetchedRecordsController.swift in Sources */,
56B964B91DA51D0A0002DA19 /* FTS5Pattern.swift in Sources */,
5653EB1520944C7C00F46237 /* AssociationQuery.swift in Sources */,
563363C01C942C04000BE133 /* DatabaseReader.swift in Sources */,
5605F1651C672E4000235C62 /* NSNull.swift in Sources */,
56CEB5191EAA328900BFAF62 /* FTS5+QueryInterface.swift in Sources */,
5653EB1820944C7C00F46237 /* ForeignKey.swift in Sources */,
5674A6FB1F307F600095F066 /* FetchableRecord+Decodable.swift in Sources */,
5653EB0620944C7C00F46237 /* ForeignKeyRequest.swift in Sources */,
5698AC781DA37DCB0056AF8C /* VirtualTableModule.swift in Sources */,
56A2387D1B9C75030082EB20 /* Database.swift in Sources */,
566AD8B21D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
@@ -2778,10 +2947,13 @@
5605F1671C672E4000235C62 /* NSNumber.swift in Sources */,
C96C0F2B2084A442006B2981 /* SQLiteDateParser.swift in Sources */,
56A238871B9C75030082EB20 /* Row.swift in Sources */,
5653EB2120944C7C00F46237 /* HasOneAssociation.swift in Sources */,
5605F1731C672E4000235C62 /* StandardLibrary.swift in Sources */,
5653EC122098738B00F46237 /* SQLGenerationContext.swift in Sources */,
560D92471C672C4B00F4F92B /* PersistableRecord.swift in Sources */,
566475A21D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */,
5674A6E41F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */,
5653EB0C20944C7C00F46237 /* HasManyAssociation.swift in Sources */,
5657AAB91D107001006283EF /* NSData.swift in Sources */,
560D92421C672C3E00F4F92B /* StatementColumnConvertible.swift in Sources */,
56CEB5531EAA359A00BFAF62 /* SQLExpression.swift in Sources */,
-8
View File
@@ -132,7 +132,6 @@ extension Cursor {
return nil
}
#if swift(>=4.1)
/// Returns a cursor over the concatenated non-nil results of mapping
/// transform over this cursor.
public func compactMap<ElementOfResult>(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor<FilterCursor<MapCursor<Self, ElementOfResult?>>, ElementOfResult> {
@@ -143,13 +142,6 @@ extension Cursor {
public func flatMap<ElementOfResult>(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor<FilterCursor<MapCursor<Self, ElementOfResult?>>, ElementOfResult> {
return compactMap(transform)
}
#else
/// Returns a cursor over the concatenated non-nil results of mapping
/// transform over this cursor.
public func flatMap<ElementOfResult>(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor<FilterCursor<MapCursor<Self, ElementOfResult?>>, ElementOfResult> {
return map(transform).filter { $0 != nil }.map { $0! }
}
#endif
/// Returns a cursor that skips any initial elements that satisfy
/// `predicate`.
+22 -22
View File
@@ -232,24 +232,24 @@ extension Database {
}
/// Returns the actual name of the database table
func canonicalName(table: String) throws -> String {
if let canonicalName = schemaCache.canonicalName(table: table) {
return canonicalName
func canonicalTableName(_ tableName: String) throws -> String {
if let canonicalTableName = schemaCache.canonicalTableName(tableName) {
return canonicalTableName
}
guard let canonicalName = try String.fetchOne(self, """
guard let canonicalTableName = try String.fetchOne(self, """
SELECT name FROM (
SELECT name, type FROM sqlite_master
UNION
SELECT name, type FROM sqlite_temp_master)
WHERE type = 'table' AND LOWER(name) = ?
""", arguments: [table.lowercased()])
""", arguments: [tableName.lowercased()])
else {
throw DatabaseError(message: "no such table: \(table)")
throw DatabaseError(message: "no such table: \(tableName)")
}
schemaCache.set(canonicalName: canonicalName, forTable: table)
return canonicalName
schemaCache.set(canonicalTableName: canonicalTableName, forTable: tableName)
return canonicalTableName
}
}
@@ -327,11 +327,11 @@ extension Database {
/// This type closely matches the information returned by the
/// `table_info` pragma.
///
/// > CREATE TABLE players (
/// > CREATE TABLE player (
/// id INTEGER PRIMARY KEY,
/// firstName TEXT,
/// lastName TEXT)
/// > PRAGMA table_info("players")
/// > PRAGMA table_info("player")
/// cid name type notnull dflt_value pk
/// ---- ----- ------- -------- ---------- ---
/// 0 id INTEGER 0 NULL 1
@@ -362,14 +362,14 @@ public struct ColumnInfo : FetchableRecord {
/// For example:
///
/// try db.execute("""
/// CREATE TABLE players(
/// CREATE TABLE player(
/// id INTEGER PRIMARY KEY,
/// name TEXT DEFAULT 'Anonymous',
/// score INT DEFAULT 0,
/// creationDate DATE DEFAULT CURRENT_TIMESTAMP
/// )
/// """)
/// let columnInfos = try db.columns(in: "players")
/// let columnInfos = try db.columns(in: "player")
/// columnInfos[0].defaultValueSQL // nil
/// columnInfos[1].defaultValueSQL // "'Anoynymous'"
/// columnInfos[2].defaultValueSQL // "0"
@@ -424,38 +424,38 @@ public struct IndexInfo {
///
/// When the table's primary key is the rowid:
///
/// // CREATE TABLE items (name TEXT)
/// let pk = try db.primaryKey("items")
/// // CREATE TABLE item (name TEXT)
/// let pk = try db.primaryKey("item")
/// pk.columns // ["rowid"]
/// pk.rowIDColumn // nil
/// pk.isRowID // true
///
/// // CREATE TABLE citizens (
/// // CREATE TABLE citizen (
/// // id INTEGER PRIMARY KEY,
/// // name TEXT
/// // )
/// let pk = try db.primaryKey("citizens")!
/// let pk = try db.primaryKey("citizen")!
/// pk.columns // ["id"]
/// pk.rowIDColumn // "id"
/// pk.isRowID // true
///
/// When the table's primary key is not the rowid:
///
/// // CREATE TABLE countries (
/// // CREATE TABLE country (
/// // isoCode TEXT NOT NULL PRIMARY KEY
/// // name TEXT
/// // )
/// let pk = db.primaryKey("countries")!
/// let pk = db.primaryKey("country")!
/// pk.columns // ["isoCode"]
/// pk.rowIDColumn // nil
/// pk.isRowID // false
///
/// // CREATE TABLE citizenships (
/// // citizenID INTEGER NOT NULL REFERENCES citizens(id)
/// // countryIsoCode TEXT NOT NULL REFERENCES countries(isoCode)
/// // CREATE TABLE citizenship (
/// // citizenID INTEGER NOT NULL REFERENCES citizen(id)
/// // countryIsoCode TEXT NOT NULL REFERENCES country(isoCode)
/// // PRIMARY KEY (citizenID, countryIsoCode)
/// // )
/// let pk = db.primaryKey("citizenships")!
/// let pk = db.primaryKey("citizenship")!
/// pk.columns // ["citizenID", "countryIsoCode"]
/// pk.rowIDColumn // nil
/// pk.isRowID // false
+12 -12
View File
@@ -1,12 +1,12 @@
import Foundation
extension Database {
// MARK: - Statements
/// Returns a new prepared statement that can be reused.
///
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?")
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?")
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
///
@@ -19,7 +19,7 @@ extension Database {
/// Returns a new prepared statement that can be reused.
///
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?", prepFlags: 0)
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?", prepFlags: 0)
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
///
@@ -34,7 +34,7 @@ extension Database {
/// Returns a prepared statement that can be reused.
///
/// let statement = try db.cachedSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?")
/// let statement = try db.cachedSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?")
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
///
@@ -55,7 +55,7 @@ extension Database {
/// Returns a new prepared statement that can be reused.
///
/// let statement = try db.makeUpdateStatement("INSERT INTO players (name) VALUES (?)")
/// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)")
/// try statement.execute(arguments: ["Arthur"])
/// try statement.execute(arguments: ["Barbara"])
///
@@ -68,7 +68,7 @@ extension Database {
/// Returns a new prepared statement that can be reused.
///
/// let statement = try db.makeUpdateStatement("INSERT INTO players (name) VALUES (?)", prepFlags: 0)
/// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)", prepFlags: 0)
/// try statement.execute(arguments: ["Arthur"])
/// try statement.execute(arguments: ["Barbara"])
///
@@ -83,7 +83,7 @@ extension Database {
/// Returns a prepared statement that can be reused.
///
/// let statement = try db.cachedUpdateStatement("INSERT INTO players (name) VALUES (?)")
/// let statement = try db.cachedUpdateStatement("INSERT INTO player (name) VALUES (?)")
/// try statement.execute(arguments: ["Arthur"])
/// try statement.execute(arguments: ["Barbara"])
///
@@ -105,13 +105,13 @@ extension Database {
/// Executes one or several SQL statements, separated by semi-colons.
///
/// try db.execute(
/// "INSERT INTO players (name) VALUES (:name)",
/// "INSERT INTO player (name) VALUES (:name)",
/// arguments: ["name": "Arthur"])
///
/// try db.execute("""
/// INSERT INTO players (name) VALUES (?);
/// INSERT INTO players (name) VALUES (?);
/// INSERT INTO players (name) VALUES (?);
/// INSERT INTO player (name) VALUES (?);
/// INSERT INTO player (name) VALUES (?);
/// INSERT INTO player (name) VALUES (?);
/// """, arguments; ['Arthur', 'Barbara', 'Craig'])
///
/// This method may throw a DatabaseError.
+1 -17
View File
@@ -867,14 +867,6 @@ extension Database {
self.rawValue = rawValue
}
#if !swift(>=4.1)
/// The hash value
/// :nodoc:
public var hashValue: Int {
return rawValue.hashValue
}
#endif
/// The `BINARY` built-in SQL collation
public static let binary = CollationName("BINARY")
@@ -887,7 +879,7 @@ extension Database {
/// An SQL column type.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// }
@@ -906,14 +898,6 @@ extension Database {
self.rawValue = rawValue
}
#if !swift(>=4.1)
/// The hash value
/// :nodoc:
public var hashValue: Int {
return rawValue.hashValue
}
#endif
/// The `TEXT` SQL column type
public static let text = ColumnType("TEXT")
+1 -1
View File
@@ -16,7 +16,7 @@ public final class DatabaseCollation {
/// return (string1 as NSString).localizedStandardCompare(string2)
/// }
/// db.add(collation: collation)
/// try db.execute("CREATE TABLE files (name TEXT COLLATE localized_standard")
/// try db.execute("CREATE TABLE file (name TEXT COLLATE localized_standard")
///
/// - parameters:
/// - name: The function name.
-10
View File
@@ -139,16 +139,6 @@ public struct ResultCode : RawRepresentable, Equatable, CustomStringConvertible
public static let SQLITE_OK_LOAD_PERMANENTLY = ResultCode(rawValue: (SQLITE_OK.rawValue | (1<<8)))
}
#if !swift(>=4.1)
// Equatable
extension ResultCode {
/// :nodoc:
public static func == (_ lhs: ResultCode, _ rhs: ResultCode) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}
#endif
// CustomStringConvertible
extension ResultCode {
/// :nodoc:
+2 -12
View File
@@ -10,16 +10,6 @@ public final class DatabaseFunction: Hashable {
private struct Identity: Hashable {
let name: String
let nArg: Int32 // -1 for variadic functions
#if !swift(>=4.1)
var hashValue: Int {
return name.hashValue ^ nArg.hashValue
}
static func == (lhs: Identity, rhs: Identity) -> Bool {
return lhs.name == rhs.name && lhs.nArg == rhs.nArg
}
#endif
}
public var name: String { return identity.name }
@@ -373,10 +363,10 @@ public protocol DatabaseAggregate {
/// aggregate function.
///
/// -- One value
/// SELECT maxLength(name) FROM players
/// SELECT maxLength(name) FROM player
///
/// -- Two values
/// SELECT maxFullNameLength(firstName, lastName) FROM players
/// SELECT maxFullNameLength(firstName, lastName) FROM player
///
/// This method is never called after the finalize() method has been called.
mutating func step(_ dbValues: [DatabaseValue]) throws
+12 -12
View File
@@ -224,14 +224,14 @@ extension DatabasePool : DatabaseReader {
///
/// try dbPool.read { db in
/// // Those two values are guaranteed to be equal, even if the
/// // `wines` table is modified between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// // `wine` table is modified between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// try dbPool.read { db in
/// // Now this value may be different:
/// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// This method is *not* reentrant.
@@ -266,8 +266,8 @@ extension DatabasePool : DatabaseReader {
/// try dbPool.unsafeRead { db in
/// // Those two values may be different because some other thread
/// // may have inserted or deleted a wine between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Cursor iteration is safe, though:
@@ -303,8 +303,8 @@ extension DatabasePool : DatabaseReader {
/// try dbPool.unsafeReentrantRead { db in
/// // Those two values may be different because some other thread
/// // may have inserted or deleted a wine between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Cursor iteration is safe, though:
@@ -346,12 +346,12 @@ extension DatabasePool : DatabaseReader {
/// database updates are *not visible* inside the block.
///
/// try dbPool.write { db in
/// try db.execute("DELETE FROM players")
/// try db.execute("DELETE FROM player")
/// try dbPool.readFromCurrentState { db in
/// // Guaranteed to be zero
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM players")!
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM player")!
/// }
/// try db.execute("INSERT INTO players ...")
/// try db.execute("INSERT INTO player ...")
/// }
///
/// This method blocks the current thread until the isolation guarantee has
@@ -611,7 +611,7 @@ extension DatabasePool : DatabaseReader {
/// }
/// dbPool.add(collation: collation)
/// try dbPool.write { db in
/// try db.execute("CREATE TABLE files (name TEXT COLLATE LOCALIZED_STANDARD")
/// try db.execute("CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
/// }
public func add(collation: DatabaseCollation) {
collations.update(with: collation)
+4 -4
View File
@@ -10,7 +10,7 @@ public final class DatabaseQueue: DatabaseWriter {
#if os(iOS)
private weak var application: UIApplication?
#endif
// MARK: - Configuration
/// The database configuration
@@ -291,7 +291,7 @@ extension DatabaseQueue {
/// Synchronously executes a block in a protected dispatch queue, and
/// returns its result.
///
/// // INSERT INTO players ...
/// // INSERT INTO player ...
/// let players = try dbQueue.inDatabase { db in
/// try Player(...).insert(db)
/// }
@@ -307,7 +307,7 @@ extension DatabaseQueue {
/// Synchronously executes a block in a protected dispatch queue, and
/// returns its result.
///
/// // INSERT INTO players ...
/// // INSERT INTO player ...
/// try dbQueue.unsafeReentrantWrite { db in
/// try Player(...).insert(db)
/// }
@@ -350,7 +350,7 @@ extension DatabaseQueue {
/// }
/// dbQueue.add(collation: collation)
/// try dbQueue.write { db in
/// try db.execute("CREATE TABLE files (name TEXT COLLATE LOCALIZED_STANDARD")
/// try db.execute("CREATE TABLE file (name TEXT COLLATE LOCALIZED_STANDARD")
/// }
public func add(collation: DatabaseCollation) {
writer.sync { $0.add(collation: collation) }
+9 -9
View File
@@ -31,14 +31,14 @@ public protocol DatabaseReader : class {
///
/// try reader.read { db in
/// // Those two values are guaranteed to be equal, even if the
/// // `wines` table is modified between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// // `wine` table is modified between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// try reader.read { db in
/// // Now this value may be different:
/// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Guarantee 2: Starting iOS 8.2, OSX 10.10, and with custom SQLite builds
@@ -61,8 +61,8 @@ public protocol DatabaseReader : class {
/// try reader.unsafeRead { db in
/// // Those two values may be different because some other thread
/// // may have inserted or deleted a wine between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Cursor iterations are isolated, though:
@@ -92,8 +92,8 @@ public protocol DatabaseReader : class {
/// try reader.unsafeReentrantRead { db in
/// // Those two values may be different because some other thread
/// // may have inserted or deleted a wine between the two requests:
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wines")!
/// let count1 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// let count2 = try Int.fetchOne(db, "SELECT COUNT(*) FROM wine")!
/// }
///
/// Cursor iterations are isolated, though:
@@ -144,7 +144,7 @@ public protocol DatabaseReader : class {
/// return (string1 as NSString).localizedStandardCompare(string2)
/// }
/// reader.add(collation: collation)
/// try reader.execute("SELECT * FROM files ORDER BY name COLLATE localized_standard")
/// try reader.execute("SELECT * FROM file ORDER BY name COLLATE localized_standard")
func add(collation: DatabaseCollation)
/// Remove a collation.
+6 -14
View File
@@ -18,27 +18,27 @@
///
/// - `SelectStatement.fetchedRegion`:
///
/// let statement = db.makeSelectStatement("SELECT name, score FROM players")
/// let statement = db.makeSelectStatement("SELECT name, score FROM player")
/// print(statement.fetchedRegion)
/// // prints "players(name,score)"
/// // prints "player(name,score)"
///
/// - `Request.fetchedRegion(_:)`
///
/// let request = Player.filter(key: 1)
/// try print(request.fetchedRegion(db))
/// // prints "players(*)[1]"
/// // prints "player(*)[1]"
///
/// Database regions returned by requests can be more precise than regions
/// returned by select statements. Especially, regions returned by statements
/// don't know about rowids:
///
/// // A plain statement
/// let statement = db.makeSelectStatement("SELECT * FROM players WHERE id = 1")
/// statement.fetchedRegion // "players(*)"
/// let statement = db.makeSelectStatement("SELECT * FROM player WHERE id = 1")
/// statement.fetchedRegion // "player(*)"
///
/// // A query interface request that executes the same statement:
/// let request = Player.filter(key: 1)
/// try request.fetchedRegion(db) // "players(*)[1]"
/// try request.fetchedRegion(db) // "player(*)[1]"
public struct DatabaseRegion: CustomStringConvertible, Equatable {
private let tableRegions: [String: TableRegion]?
private init(tableRegions: [String: TableRegion]?) {
@@ -255,14 +255,6 @@ private struct TableRegion: Equatable {
return false
}
#if !swift(>=4.1)
static func == (lhs: TableRegion, rhs: TableRegion) -> Bool {
if lhs.columns != rhs.columns { return false }
if lhs.rowIds != rhs.rowIds { return false }
return true
}
#endif
func intersection(_ other: TableRegion) -> TableRegion {
let columnsIntersection: Set<String>?
switch (self.columns, other.columns) {
+10 -10
View File
@@ -2,8 +2,8 @@
protocol DatabaseSchemaCache {
mutating func clear()
func canonicalName(table: String) -> String?
mutating func set(canonicalName: String, forTable table: String)
func canonicalTableName(_ table: String) -> String?
mutating func set(canonicalTableName: String, forTable table: String)
func primaryKey(_ table: String) -> PrimaryKeyInfo?
mutating func set(primaryKey: PrimaryKeyInfo, forTable table: String)
@@ -20,26 +20,26 @@ protocol DatabaseSchemaCache {
/// A thread-unsafe database schema cache
struct SimpleDatabaseSchemaCache: DatabaseSchemaCache {
private var canonicalNames: [String: String] = [:]
private var canonicalTableNames: [String: String] = [:]
private var primaryKeys: [String: PrimaryKeyInfo] = [:]
private var columns: [String: [ColumnInfo]] = [:]
private var indexes: [String: [IndexInfo]] = [:]
private var foreignKeys: [String: [ForeignKeyInfo]] = [:]
mutating func clear() {
canonicalNames = [:]
canonicalTableNames = [:]
primaryKeys = [:]
columns = [:]
indexes = [:]
foreignKeys = [:]
}
func canonicalName(table: String) -> String? {
return canonicalNames[table]
func canonicalTableName(_ table: String) -> String? {
return canonicalTableNames[table]
}
mutating func set(canonicalName: String, forTable table: String) {
canonicalNames[table] = table
mutating func set(canonicalTableName: String, forTable table: String) {
canonicalTableNames[table] = table
}
func primaryKey(_ table: String) -> PrimaryKeyInfo? {
@@ -79,8 +79,8 @@ struct SimpleDatabaseSchemaCache: DatabaseSchemaCache {
struct EmptyDatabaseSchemaCache: DatabaseSchemaCache {
func clear() { }
func canonicalName(table: String) -> String? { return nil }
func set(canonicalName: String, forTable table: String) { }
func canonicalTableName(_ table: String) -> String? { return nil }
func set(canonicalTableName: String, forTable table: String) { }
func primaryKey(_ table: String) -> PrimaryKeyInfo? { return nil }
func set(primaryKey: PrimaryKeyInfo, forTable table: String) { }
+1 -1
View File
@@ -110,7 +110,7 @@ extension DatabaseSnapshot {
/// }
/// snapshot.add(collation: collation)
/// let files = try snapshot.read { db in
/// try File.fetchAll(db, "SELECT * FROM files ORDER BY name COLLATE localized_standard")
/// try File.fetchAll(db, "SELECT * FROM file ORDER BY name COLLATE localized_standard")
/// }
public func add(collation: DatabaseCollation) {
serializedDatabase.sync { $0.add(collation: collation) }
+9 -4
View File
@@ -308,14 +308,13 @@ extension DatabaseValue {
extension DatabaseValue {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
public func expressionSQL(_ context: inout SQLGenerationContext) -> String {
// fast path for NULL
if isNull {
return "NULL"
}
if arguments != nil {
arguments!.values.append(self)
if context.appendArguments([self]) {
return "?"
} else {
// Correctness above all: use SQLite to quote the value.
@@ -352,7 +351,13 @@ extension DatabaseValue {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return self
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return self
}
}
+2 -2
View File
@@ -42,7 +42,7 @@ extension DatabaseValueConvertible {
/// For example:
///
/// try dbQueue.read { db in
/// let urls: DatabaseValueCursor<URL> = try URL.fetchCursor(db, "SELECT url FROM links")
/// let urls: DatabaseValueCursor<URL> = try URL.fetchCursor(db, "SELECT url FROM link")
/// while let url = urls.next() { // URL
/// print(url)
/// }
@@ -82,7 +82,7 @@ public final class DatabaseValueCursor<Value: DatabaseValueConvertible> : Cursor
/// For example:
///
/// try dbQueue.read { db in
/// let urls: NullableDatabaseValueCursor<URL> = try Optional<URL>.fetchCursor(db, "SELECT url FROM links")
/// let urls: NullableDatabaseValueCursor<URL> = try Optional<URL>.fetchCursor(db, "SELECT url FROM link")
/// while let url = urls.next() { // URL?
/// print(url)
/// }
+3 -3
View File
@@ -73,12 +73,12 @@ public protocol DatabaseWriter : DatabaseReader {
/// For example:
///
/// try writer.write { db in
/// try db.execute("DELETE FROM players")
/// try db.execute("DELETE FROM player")
/// try writer.readFromCurrentState { db in
/// // Guaranteed to be zero
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM players")!
/// try Int.fetchOne(db, "SELECT COUNT(*) FROM player")!
/// }
/// try db.execute("INSERT INTO players ...")
/// try db.execute("INSERT INTO player ...")
/// }
func readFromCurrentState(_ block: @escaping (Database) -> Void) throws
}
+4 -21
View File
@@ -73,23 +73,6 @@ public protocol FetchRequest: SelectStatementRequest {
}
extension FetchRequest {
/// Returns a request bound to type T.
///
/// The returned request can fetch if the type T is fetchable (Row,
/// value, record).
///
/// // Int?
/// let maxScore = Player
/// .select(max(scoreColumn))
/// .asRequest(of: Int.self) // <--
/// .fetchOne(db)
///
/// - parameter type: The fetched type T
/// - returns: A typed request bound to type T.
public func asRequest<T>(of type: T.Type) -> AnyFetchRequest<T> {
return AnyFetchRequest(self)
}
/// Returns an adapted request.
public func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedFetchRequest<Self> {
return AdaptedFetchRequest(self, adapter)
@@ -202,8 +185,8 @@ public struct SQLRequest<T> : FetchRequest {
/// Creates a request from an SQL string, optional arguments, and
/// optional row adapter.
///
/// let request = SQLRequest("SELECT * FROM players")
/// let request = SQLRequest("SELECT * FROM players WHERE id = ?", arguments: [1])
/// let request = SQLRequest("SELECT * FROM player")
/// let request = SQLRequest("SELECT * FROM player WHERE id = ?", arguments: [1])
///
/// - parameters:
/// - sql: An SQL query.
@@ -232,8 +215,8 @@ public struct SQLRequest<T> : FetchRequest {
/// Creates an SQL request from an SQL string, optional arguments, and
/// optional row adapter.
///
/// let request = SQLRequest("SELECT * FROM players")
/// let request = SQLRequest("SELECT * FROM players WHERE id = ?", arguments: [1])
/// let request = SQLRequest("SELECT * FROM player")
/// let request = SQLRequest("SELECT * FROM player WHERE id = ?", arguments: [1])
///
/// - parameters:
/// - sql: An SQL query.
+2 -2
View File
@@ -583,7 +583,7 @@ extension Row {
/// A cursor of database rows. For example:
///
/// try dbQueue.read { db in
/// let rows: RowCursor = try Row.fetchCursor(db, "SELECT * FROM players")
/// let rows: RowCursor = try Row.fetchCursor(db, "SELECT * FROM player")
/// }
public final class RowCursor : Cursor {
public let statement: SelectStatement
@@ -690,7 +690,7 @@ extension Row {
/// Returns a cursor over rows fetched from an SQL query.
///
/// let rows = try Row.fetchCursor(db, "SELECT id, name FROM players") // RowCursor
/// let rows = try Row.fetchCursor(db, "SELECT id, name FROM player") // RowCursor
/// while let row = try rows.next() { // Row
/// let id: Int64 = row[0]
/// let name: String = row[1]
+5 -17
View File
@@ -289,7 +289,7 @@ extension AuthorizedStatement {
/// You create SelectStatement with the Database.makeSelectStatement() method:
///
/// try dbQueue.read { db in
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?")
/// let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM player WHERE score > ?")
/// let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
/// let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
/// }
@@ -375,7 +375,7 @@ extension SelectStatement: AuthorizedStatement { }
/// For example:
///
/// try dbQueue.read { db in
/// let statement = db.makeSelectStatement("SELECT * FROM players")
/// let statement = db.makeSelectStatement("SELECT * FROM player")
/// let cursor: StatementCursor = statement.cursor()
/// }
public final class StatementCursor: Cursor {
@@ -414,7 +414,7 @@ public final class StatementCursor: Cursor {
/// You create UpdateStatement with the Database.makeUpdateStatement() method:
///
/// try dbQueue.inTransaction { db in
/// let statement = try db.makeUpdateStatement("INSERT INTO players (name) VALUES (?)")
/// let statement = try db.makeUpdateStatement("INSERT INTO player (name) VALUES (?)")
/// try statement.execute(arguments: ["Arthur"])
/// try statement.execute(arguments: ["Barbara"])
/// return .commit
@@ -588,8 +588,8 @@ extension UpdateStatement: AuthorizedStatement { }
/// print(row)
/// // Prints [two:2 foo:"foo" one:1 foo2:"foo" bar:"bar"]
public struct StatementArguments: CustomStringConvertible, Equatable, ExpressibleByArrayLiteral, ExpressibleByDictionaryLiteral {
var values: [DatabaseValue] = []
var namedValues: [String: DatabaseValue] = [:]
private(set) var values: [DatabaseValue] = []
private(set) var namedValues: [String: DatabaseValue] = [:]
public var isEmpty: Bool {
return values.isEmpty && namedValues.isEmpty
@@ -905,18 +905,6 @@ extension StatementArguments {
}
}
#if !swift(>=4.1)
// Equatable
extension StatementArguments {
/// :nodoc:
public static func == (lhs: StatementArguments, rhs: StatementArguments) -> Bool {
if lhs.values != rhs.values { return false }
if lhs.namedValues != rhs.namedValues { return false }
return true
}
}
#endif
/// A thread-unsafe statement cache
struct StatementCache {
unowned let db: Database
+2 -2
View File
@@ -75,7 +75,7 @@ extension StatementColumnConvertible {
/// For example:
///
/// try dbQueue.read { db in
/// let names: ColumnCursor<String> = try String.fetchCursor(db, "SELECT name FROM players")
/// let names: ColumnCursor<String> = try String.fetchCursor(db, "SELECT name FROM player")
/// while let name = names.next() { // String
/// print(name)
/// }
@@ -121,7 +121,7 @@ public final class ColumnCursor<Value: DatabaseValueConvertible & StatementColum
/// For example:
///
/// try dbQueue.read { db in
/// let emails: NullableColumnCursor<String> = try Optional<String>.fetchCursor(db, "SELECT email FROM players")
/// let emails: NullableColumnCursor<String> = try Optional<String>.fetchCursor(db, "SELECT email FROM player")
/// while let email = emails.next() { // String?
/// print(email ?? "<NULL>")
/// }
+9 -10
View File
@@ -29,13 +29,12 @@ extension Database {
/// Registers a closure to be executed after the next or current
/// transaction completion.
///
/// dbQueue.inTransaction { db in
/// try dbQueue.write { db in
/// db.afterNextTransactionCommit { _ in
/// print("commit did succeed")
/// print("success")
/// }
/// ...
/// return .commit // prints "commit did succeed"
/// }
/// } // prints "success"
///
/// If the transaction is rollbacked, the closure is not executed.
///
@@ -100,11 +99,11 @@ extension Database {
///
/// Then a statement is executed:
///
/// try db.execute("INSERT INTO documents ...")
/// try db.execute("INSERT INTO document ...")
///
/// The observation process starts when the statement is *compiled*:
/// sqlite3_set_authorizer tells that the statement performs insertion into the
/// `documents` table. Generally speaking, statements may have many effects, by
/// `document` table. Generally speaking, statements may have many effects, by
/// the mean of foreign key actions and SQL triggers. SQLite takes care of
/// exposing all those effects to sqlite3_set_authorizer.
///
@@ -129,7 +128,7 @@ extension Database {
///
/// Then another statement is executed:
///
/// try db.execute("INSERT INTO documents ...")
/// try db.execute("INSERT INTO document ...")
///
/// This time, when the statement is *executed* and SQLite tells that a row has
/// been inserted, the broker buffers the change event instead of immediately
@@ -738,14 +737,14 @@ extension TransactionObserver {
/// For example:
///
/// class PlayerObserver: TransactionObserver {
/// var playersTableWasModified = false
/// var playerTableWasModified = false
///
/// func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool {
/// return eventKind.tableName == "players"
/// return eventKind.tableName == "player"
/// }
///
/// func databaseDidChange(with event: DatabaseEvent) {
/// playersTableWasModified = true
/// playerTableWasModified = true
///
/// // It is pointless to keep on tracking further changes:
/// stopObservingDatabaseChangesUntilNextTransaction()
+7 -7
View File
@@ -1,15 +1,15 @@
/// FTS3 lets you define "fts3" virtual tables.
///
/// // CREATE VIRTUAL TABLE documents USING fts3(content)
/// try db.create(virtualTable: "documents", using: FTS3()) { t in
/// // CREATE VIRTUAL TABLE document USING fts3(content)
/// try db.create(virtualTable: "document", using: FTS3()) { t in
/// t.column("content")
/// }
public struct FTS3 : VirtualTableModule {
/// Creates a FTS3 module suitable for the Database
/// `create(virtualTable:using:)` method.
///
/// // CREATE VIRTUAL TABLE documents USING fts3(content)
/// try db.create(virtualTable: "documents", using: FTS3()) { t in
/// // CREATE VIRTUAL TABLE document USING fts3(content)
/// try db.create(virtualTable: "document", using: FTS3()) { t in
/// t.column("content")
/// }
public init() {
@@ -54,7 +54,7 @@ public struct FTS3 : VirtualTableModule {
/// You don't create instances of this class. Instead, you use the Database
/// `create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "documents", using: FTS3()) { t in // t is FTS3TableDefinition
/// try db.create(virtualTable: "document", using: FTS3()) { t in // t is FTS3TableDefinition
/// t.column("content")
/// }
public final class FTS3TableDefinition {
@@ -62,7 +62,7 @@ public final class FTS3TableDefinition {
/// The virtual table tokenizer
///
/// try db.create(virtualTable: "documents", using: FTS3()) { t in
/// try db.create(virtualTable: "document", using: FTS3()) { t in
/// t.tokenizer = .porter
/// }
/// See https://www.sqlite.org/fts3.html#creating_and_destroying_fts_tables
@@ -70,7 +70,7 @@ public final class FTS3TableDefinition {
/// Appends a table column.
///
/// try db.create(virtualTable: "documents", using: FTS3()) { t in
/// try db.create(virtualTable: "document", using: FTS3()) { t in
/// t.column("content")
/// }
///
+5 -5
View File
@@ -1,6 +1,6 @@
/// An FTS3 tokenizer, suitable for FTS3 and FTS4 table definitions:
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .simple // FTS3TokenizerDescriptor
/// }
///
@@ -16,7 +16,7 @@ public struct FTS3TokenizerDescriptor {
/// The "simple" tokenizer.
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .simple
/// }
///
@@ -25,7 +25,7 @@ public struct FTS3TokenizerDescriptor {
/// The "porter" tokenizer.
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .porter
/// }
///
@@ -35,7 +35,7 @@ public struct FTS3TokenizerDescriptor {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// The "unicode61" tokenizer.
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .unicode61()
/// }
///
@@ -54,7 +54,7 @@ public struct FTS3TokenizerDescriptor {
#else
/// The "unicode61" tokenizer.
///
/// db.create(virtualTable: "books", using: FTS4()) { t in
/// db.create(virtualTable: "book", using: FTS4()) { t in
/// t.tokenizer = .unicode61()
/// }
///
+13 -13
View File
@@ -1,7 +1,7 @@
/// FTS4 lets you define "fts4" virtual tables.
///
/// // CREATE VIRTUAL TABLE documents USING fts4(content)
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// // CREATE VIRTUAL TABLE document USING fts4(content)
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("content")
/// }
///
@@ -11,8 +11,8 @@ public struct FTS4 : VirtualTableModule {
/// Creates a FTS4 module suitable for the Database
/// `create(virtualTable:using:)` method.
///
/// // CREATE VIRTUAL TABLE documents USING fts4(content)
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// // CREATE VIRTUAL TABLE document USING fts4(content)
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("content")
/// }
///
@@ -137,7 +137,7 @@ public struct FTS4 : VirtualTableModule {
/// You don't create instances of this class. Instead, you use the Database
/// `create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in // t is FTS4TableDefinition
/// try db.create(virtualTable: "document", using: FTS4()) { t in // t is FTS4TableDefinition
/// t.column("content")
/// }
///
@@ -153,7 +153,7 @@ public final class FTS4TableDefinition {
/// The virtual table tokenizer
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.tokenizer = .porter
/// }
///
@@ -201,8 +201,8 @@ public final class FTS4TableDefinition {
/// Support for the FTS5 `prefix` option
///
/// // CREATE VIRTUAL TABLE documents USING FTS4(content, prefix='2 4');
/// db.create(virtualTable: "documents", using:FTS4()) { t in
/// // CREATE VIRTUAL TABLE document USING FTS4(content, prefix='2 4');
/// db.create(virtualTable: "document", using:FTS4()) { t in
/// t.prefixes = [2, 4]
/// t.column("content")
/// }
@@ -212,7 +212,7 @@ public final class FTS4TableDefinition {
/// Appends a table column.
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("content")
/// }
///
@@ -242,7 +242,7 @@ public final class FTS4TableDefinition {
///
/// You get instances of this class when you create an FTS4 table:
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("content") // FTS4ColumnDefinition
/// }
///
@@ -261,7 +261,7 @@ public final class FTS4ColumnDefinition {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Excludes the column from the full-text index.
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("a")
/// t.column("b").notIndexed()
/// }
@@ -280,7 +280,7 @@ public final class FTS4ColumnDefinition {
#else
/// Excludes the column from the full-text index.
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("a")
/// t.column("b").notIndexed()
/// }
@@ -300,7 +300,7 @@ public final class FTS4ColumnDefinition {
/// Uses the column as the Int32 language id hidden column.
///
/// try db.create(virtualTable: "documents", using: FTS4()) { t in
/// try db.create(virtualTable: "document", using: FTS4()) { t in
/// t.column("a")
/// t.column("lid").asLanguageId()
/// }
+9 -9
View File
@@ -1,8 +1,8 @@
#if SQLITE_ENABLE_FTS5
/// FTS5 lets you define "fts5" virtual tables.
///
/// // CREATE VIRTUAL TABLE documents USING fts5(content)
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// // CREATE VIRTUAL TABLE document USING fts5(content)
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("content")
/// }
///
@@ -12,8 +12,8 @@
/// Creates a FTS5 module suitable for the Database
/// `create(virtualTable:using:)` method.
///
/// // CREATE VIRTUAL TABLE documents USING fts5(content)
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// // CREATE VIRTUAL TABLE document USING fts5(content)
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("content")
/// }
///
@@ -156,7 +156,7 @@
/// You don't create instances of this class. Instead, you use the Database
/// `create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in // t is FTS5TableDefinition
/// try db.create(virtualTable: "document", using: FTS5()) { t in // t is FTS5TableDefinition
/// t.column("content")
/// }
///
@@ -172,7 +172,7 @@
/// The virtual table tokenizer
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.tokenizer = .porter()
/// }
///
@@ -254,7 +254,7 @@
/// Appends a table column.
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("content")
/// }
///
@@ -284,7 +284,7 @@
///
/// You get instances of this class when you create an FTS5 table:
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("content") // FTS5ColumnDefinition
/// }
///
@@ -300,7 +300,7 @@
/// Excludes the column from the full-text index.
///
/// try db.create(virtualTable: "documents", using: FTS5()) { t in
/// try db.create(virtualTable: "document", using: FTS5()) { t in
/// t.column("a")
/// t.column("b").notIndexed()
/// }
+2 -2
View File
@@ -11,7 +11,7 @@
/// VIRTUAL TABLE statement. In the example below, the arguments will
/// be `["arg1", "arg2"]`.
///
/// CREATE VIRTUAL TABLE documents USING fts5(
/// CREATE VIRTUAL TABLE document USING fts5(
/// tokenize='custom arg1 arg2'
/// )
///
@@ -26,7 +26,7 @@
///
/// class MyTokenizer : FTS5CustomTokenizer { ... }
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// let tokenizer = MyTokenizer.tokenizerDescriptor(arguments: ["unicode61", "remove_diacritics", "0"])
/// t.tokenizer = tokenizer
/// }
+4 -4
View File
@@ -65,7 +65,7 @@
// that pattern.
do {
try DatabaseQueue().inDatabase { db in
try db.create(virtualTable: "documents", using: FTS5()) { t in
try db.create(virtualTable: "document", using: FTS5()) { t in
if allowedColumns.isEmpty {
t.column("__grdb__")
} else {
@@ -74,7 +74,7 @@
}
}
}
try db.makeSelectStatement("SELECT * FROM documents WHERE documents MATCH ?")
try db.makeSelectStatement("SELECT * FROM document WHERE document MATCH ?")
.cursor(arguments: [rawPattern])
.next() // error on next() for invalid patterns
}
@@ -97,8 +97,8 @@
///
/// The pattern syntax is documented at https://www.sqlite.org/fts5.html#full_text_query_syntax
///
/// try db.makeFTS5Pattern(rawPattern: "and", forTable: "documents") // OK
/// try db.makeFTS5Pattern(rawPattern: "AND", forTable: "documents") // malformed MATCH expression: [AND]
/// try db.makeFTS5Pattern(rawPattern: "and", forTable: "document") // OK
/// try db.makeFTS5Pattern(rawPattern: "AND", forTable: "document") // malformed MATCH expression: [AND]
public func makeFTS5Pattern(rawPattern: String, forTable table: String) throws -> FTS5Pattern {
return try FTS5Pattern(rawPattern: rawPattern, allowedColumns: columns(in: table).map { $0.name })
}
+5 -5
View File
@@ -1,7 +1,7 @@
#if SQLITE_ENABLE_FTS5
/// An FTS5 tokenizer, suitable for FTS5 table definitions:
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// t.tokenizer = .unicode61() // FTS5TokenizerDescriptor
/// }
///
@@ -33,7 +33,7 @@
/// Creates an FTS5 tokenizer descriptor.
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// let tokenizer = FTS5TokenizerDescriptor(components: ["porter", "unicode61", "remove_diacritics", "0"])
/// t.tokenizer = tokenizer
/// }
@@ -47,7 +47,7 @@
/// The "ascii" tokenizer
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// t.tokenizer = .ascii()
/// }
///
@@ -66,7 +66,7 @@
/// The "porter" tokenizer
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// t.tokenizer = .porter()
/// }
///
@@ -85,7 +85,7 @@
/// An "unicode61" tokenizer
///
/// db.create(virtualTable: "books", using: FTS5()) { t in
/// db.create(virtualTable: "book", using: FTS5()) { t in
/// t.tokenizer = .unicode61()
/// }
///
+1 -1
View File
@@ -1,4 +1,4 @@
extension FetchRequest {
@available(*, unavailable, renamed:"asRequest(of:)")
@available(*, unavailable, message:"Use QueryInterfaceRequest.asRequest(of:), or AnyFetchRequest")
public func bound<T>(to type: T.Type) -> AnyFetchRequest<T> { preconditionFailure() }
}
+4
View File
@@ -18,6 +18,10 @@ public typealias MutablePersistable = MutablePersistableRecord
@available(*, unavailable, renamed:"PersistableRecord")
public typealias Persistable = PersistableRecord
/// :nodoc:
@available(*, unavailable, renamed:"TableAlias")
public typealias SQLTableQualifier = TableAlias
extension Database {
/// :nodoc:
@available(*, unavailable, message: "Use db.columns(in: tableName).count instead")
-24
View File
@@ -1,24 +0,0 @@
// Compatibility layer for Swift < 4.1
#if !swift(>=4.1)
extension Sequence {
// From future import SE-0187
func compactMap<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult] {
return try flatMap(transform)
}
}
extension UnsafeMutablePointer {
// From future import SE-0184
func deallocate() {
deallocate(capacity: 0)
}
}
extension UnsafeMutableRawBufferPointer {
// From future import SE-0184
func copyMemory<C>(from source: C) where C : Collection, C.Element == UInt8 {
copyBytes(from: source)
}
}
#endif
+46 -43
View File
@@ -9,34 +9,37 @@
///
/// var migrator = DatabaseMigrator()
///
/// // v1.0 database
/// migrator.registerMigration("createAuthors") { db in
/// try db.execute("""
/// CREATE TABLE authors (
/// id INTEGER PRIMARY KEY,
/// creationDate TEXT,
/// name TEXT NOT NULL
/// )
/// """)
/// // 1st migration
/// migrator.registerMigration("createLibrary") { db in
/// try db.create(table: "author") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("creationDate", .datetime)
/// t.column("name", .text).notNull()
/// }
///
/// try db.create(table: "book") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("authorId", .integer)
/// .notNull()
/// .references("author", onDelete: .cascade)
/// t.column("title", .text).notNull()
/// }
/// }
///
/// migrator.registerMigration("createBooks") { db in
/// try db.execute("""
/// CREATE TABLE books (
/// uuid TEXT PRIMARY KEY,
/// authorID INTEGER NOT NULL
/// REFERENCES authors(id)
/// ON DELETE CASCADE ON UPDATE CASCADE,
/// title TEXT NOT NULL
/// )
/// """)
/// }
///
/// // v2.0 database
/// // 2nd migration
/// migrator.registerMigration("AddBirthYearToAuthors") { db in
/// try db.execute("ALTER TABLE authors ADD COLUMN birthYear INT")
/// try db.alter(table: "author") { t
/// t.add(column: "birthYear", .integer)
/// }
/// }
///
/// // Migrations for future versions will be inserted here:
/// //
/// // // 3rd migration
/// // migrator.registerMigration("...") { db in
/// // ...
/// // }
///
/// try migrator.migrate(dbQueue)
public struct DatabaseMigrator {
@@ -46,14 +49,12 @@ public struct DatabaseMigrator {
/// Registers a migration.
///
/// migrator.registerMigration("createPlayers") { db in
/// try db.execute("""
/// CREATE TABLE players (
/// id INTEGER PRIMARY KEY,
/// creationDate TEXT,
/// name TEXT NOT NULL
/// )
/// """)
/// migrator.registerMigration("createAuthors") { db in
/// try db.create(table: "author") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("creationDate", .datetime)
/// t.column("name", .text).notNull()
/// }
/// }
///
/// - parameters:
@@ -69,12 +70,13 @@ public struct DatabaseMigrator {
///
/// // Add a NOT NULL constraint on players.name:
/// migrator.registerMigrationWithDeferredForeignKeyCheck("AddNotNullCheckOnName") { db in
/// try db.execute("""
/// CREATE TABLE new_players (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
/// INSERT INTO new_players SELECT * FROM players;
/// DROP TABLE players;
/// ALTER TABLE new_players RENAME TO players;
/// """)
/// try db.create(table: "new_player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("name", .text).notNull()
/// }
/// try db.execute("INSERT INTO new_player SELECT * FROM player")
/// try db.drop(table: "player")
/// try db.rename(table: "new_player", to: "player")
/// }
///
/// While your migration code runs with disabled foreign key checks, those
@@ -96,12 +98,13 @@ public struct DatabaseMigrator {
///
/// // Add a NOT NULL constraint on players.name:
/// migrator.registerMigrationWithDeferredForeignKeyCheck("AddNotNullCheckOnName") { db in
/// try db.execute("""
/// CREATE TABLE new_players (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
/// INSERT INTO new_players SELECT * FROM players;
/// DROP TABLE players;
/// ALTER TABLE new_players RENAME TO players;
/// """)
/// try db.create(table: "new_player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("name", .text).notNull()
/// }
/// try db.execute("INSERT INTO new_player SELECT * FROM player")
/// try db.drop(table: "player")
/// try db.rename(table: "new_player", to: "player")
/// }
///
/// While your migration code runs with disabled foreign key checks, those
@@ -0,0 +1,298 @@
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// The base protocol for all associations that define a connection between two
/// record types.
public protocol Association: SelectionRequest, FilteredRequest, OrderedRequest {
associatedtype LeftAssociated
associatedtype RightAssociated
/// The association key defines how rows fetched from this association
/// should be consumed.
///
/// For example:
///
/// struct Player: TableRecord {
/// // The default key of this association is the name of the
/// // database table for teams, let's say "team":
/// static let team = belongsTo(Team.self)
/// }
/// print(Player.team.key) // Prints "team"
///
/// // Consume rows:
/// let request = Player.including(required: Player.team)
/// for row in Row.fetchAll(db, request) {
/// let team: Team = row["team"] // the association key
/// }
///
/// The key can be redefined with the `forKey` method:
///
/// let request = Player.including(required: Player.team.forKey("custom"))
/// for row in Row.fetchAll(db, request) {
/// let team: Team = row["custom"]
/// }
var key: String { get }
/// Creates an association with the given key.
///
/// This new key impacts how rows fetched from the resulting association
/// should be consumed:
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // Consume rows:
/// let request = Player.including(required: Player.team.forKey("custom"))
/// for row in Row.fetchAll(db, request) {
/// let team: Team = row["custom"]
/// }
func forKey(_ key: String) -> Self
// TODO: this one prevents "through" associations like HasOneThrough, HasManyThrough, etc.
/// :nodoc:
var request: AssociationRequest<RightAssociated> { get }
// TODO: this one prevents "through" associations like HasOneThrough, HasManyThrough, etc.
/// :nodoc:
func joinCondition(_ db: Database) throws -> JoinCondition
/// :nodoc:
func mapRequest(_ transform: (AssociationRequest<RightAssociated>) -> AssociationRequest<RightAssociated>) -> Self
}
extension Association {
/// Creates an association with a new net of selected columns.
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // SELECT player.*, team.color
/// // FROM player
/// // JOIN team ON team.id = player.teamId
/// let association = Player.team.select([Column("color")])
/// var request = Player.including(required: association)
///
/// Any previous selection is replaced:
///
/// // SELECT player.*, team.color
/// // FROM player
/// // JOIN team ON team.id = player.teamId
/// let association = Player.team
/// .select([Column("id")])
/// .select([Column("color")])
/// var request = Player.including(required: association)
public func select(_ selection: [SQLSelectable]) -> Self {
return mapRequest { $0.select(selection) }
}
/// Creates an association with the provided *predicate promise* added to
/// the eventual set of already applied predicates.
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // SELECT player.*, team.*
/// // FROM player
/// // JOIN team ON team.id = player.teamId AND 1
/// let association = Player.team.filter { db in true }
/// var request = Player.including(required: association)
public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> Self {
return mapRequest { $0.filter(predicate) }
}
/// Creates an association with the provided *orderings*.
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // SELECT player.*, team.*
/// // FROM player
/// // JOIN team ON team.id = player.teamId
/// // ORDER BY team.name
/// let association = Player.team.order(Column("name"))
/// var request = Player.including(required: association)
///
/// Any previous ordering is replaced:
///
/// // SELECT player.*, team.*
/// // FROM player
/// // JOIN team ON team.id = player.teamId
/// // ORDER BY team.name
/// let association = Player.team
/// .order(Column("color"))
/// .reversed()
/// .order(Column("name"))
/// var request = Player.including(required: association)
public func order(_ orderings: [SQLOrderingTerm]) -> Self {
return mapRequest { $0.order(orderings) }
}
/// Creates an association that reverses applied orderings.
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // SELECT player.*, team.*
/// // FROM player
/// // JOIN team ON team.id = player.teamId
/// // ORDER BY team.name DESC
/// let association = Player.team.order(Column("name")).reversed()
/// var request = Player.including(required: association)
///
/// If no ordering was applied, the returned association is identical.
///
/// // SELECT player.*, team.*
/// // FROM player
/// // JOIN team ON team.id = player.teamId
/// let association = Player.team.reversed()
/// var request = Player.including(required: association)
public func reversed() -> Self {
return mapRequest { $0.reversed() }
}
/// Creates an association with the given key.
///
/// This new key helps Decodable records decode rows fetched from the
/// resulting association:
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// struct PlayerInfo: FetchableRecord, Decodable {
/// let player: Player
/// let team: Team
///
/// static func all() -> QueryInterfaceRequest<PlayerInfo> {
/// return Player
/// .including(required: Player.team.forKey(CodingKeys.team))
/// .asRequest(of: PlayerInfo.self)
/// }
/// }
///
/// let playerInfos = PlayerInfo.all().fetchAll(db)
/// print(playerInfos.first?.team)
public func forKey(_ codingKey: CodingKey) -> Self {
return forKey(codingKey.stringValue)
}
/// Creates an association that allows you to define expressions that target
/// a specific database table.
///
/// In the example below, the "team.color = 'red'" condition in the where
/// clause could be not achieved without table aliases.
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // SELECT player.*, team.*
/// // JOIN team ON ...
/// // WHERE team.color = 'red'
/// let teamAlias = TableAlias()
/// let request = Player
/// .including(required: Player.team.aliased(teamAlias))
/// .filter(teamAlias[Column("color")] == "red")
///
/// When you give a name to a table alias, you can reliably inject sql
/// snippets in your requests:
///
/// // SELECT player.*, custom.*
/// // JOIN team custom ON ...
/// // WHERE custom.color = 'red'
/// let teamAlias = TableAlias(name: "custom")
/// let request = Player
/// .including(required: Player.team.aliased(teamAlias))
/// .filter(sql: "custom.color = ?", arguments: ["red"])
public func aliased(_ alias: TableAlias) -> Self {
return mapRequest { $0.aliased(alias) }
}
}
public typealias JoinCondition = (_ leftAlias: TableAlias, _ rightAlias: TableAlias) -> SQLExpression?
/// Turns a ForeignKeyRequest into a JoinCondition
struct ForeignKeyJoinConditionRequest {
var foreignKeyRequest: ForeignKeyRequest
var originIsLeft: Bool
func fetch(_ db: Database) throws -> JoinCondition {
let foreignKeyMapping = try foreignKeyRequest.fetch(db).mapping
let columnMapping: [(left: Column, right: Column)]
if originIsLeft {
columnMapping = foreignKeyMapping.map { (left: Column($0.origin), right: Column($0.destination)) }
} else {
columnMapping = foreignKeyMapping.map { (left: Column($0.destination), right: Column($0.origin)) }
}
return { (leftAlias, rightAlias) in
return columnMapping
.map { $0.right.qualifiedExpression(with: rightAlias) == $0.left.qualifiedExpression(with: leftAlias) }
.joined(operator: .and)
}
}
}
extension Association {
/// Creates an association that includes another one. The columns of the
/// associated record are selected. The returned association does not
/// require that the associated database table contains a matching row.
public func including<A: Association>(optional association: A) -> Self where A.LeftAssociated == RightAssociated {
return mapRequest { $0.joining(.optional, association) }
}
/// Creates an association that includes another one. The columns of the
/// associated record are selected. The returned association requires
/// that the associated database table contains a matching row.
public func including<A: Association>(required association: A) -> Self where A.LeftAssociated == RightAssociated {
return mapRequest { $0.joining(.required, association) }
}
/// Creates an association that joins another one. The columns of the
/// associated record are not selected. The returned association does not
/// require that the associated database table contains a matching row.
public func joining<A: Association>(optional association: A) -> Self where A.LeftAssociated == RightAssociated {
return mapRequest { $0.joining(.optional, association.select([])) }
}
/// Creates an association that joins another one. The columns of the
/// associated record are not selected. The returned association requires
/// that the associated database table contains a matching row.
public func joining<A: Association>(required association: A) -> Self where A.LeftAssociated == RightAssociated {
return mapRequest { $0.joining(.required, association.select([])) }
}
}
extension Association where LeftAssociated: MutablePersistableRecord {
/// Support for MutablePersistableRecord.request(for:).
///
/// For example:
///
/// struct Team: {
/// static let players = hasMany(Player.self)
/// var players: QueryInterfaceRequest<Player> {
/// return request(for: Team.players)
/// }
/// }
///
/// let team: Team = ...
/// let players = try team.players.fetchAll(db) // [Player]
func request(from record: LeftAssociated) -> QueryInterfaceRequest<RightAssociated> {
// Turn `JOIN associated ON associated.recordId = record.id`
// into `FROM associated WHERE associated.recordId = 1`
let associationAlias = TableAlias()
let recordAlias = TableAlias(tableName: LeftAssociated.databaseTableName)
return QueryInterfaceRequest(request)
.aliased(associationAlias)
.filter { db in
guard let joinCondition = try self.joinCondition(db)(recordAlias, associationAlias) else {
fatalError("Can't request from record without join condition")
}
let container = PersistenceContainer(record) // support for record classes: late construction of container
return joinCondition.resolvedExpression(inContext: [recordAlias: container])
}
}
}
@@ -0,0 +1,138 @@
struct AssociationQuery {
var source: SQLSource
var selection: [SQLSelectable]
var filterPromise: DatabasePromise<SQLExpression?>
var ordering: QueryOrdering
var joins: [AssociationJoin]
var alias: TableAlias? {
return source.alias
}
}
extension AssociationQuery {
init(_ query: QueryInterfaceQuery) {
GRDBPrecondition(!query.isDistinct, "Not implemented: join distinct queries")
GRDBPrecondition(query.groupByExpressions.isEmpty, "Can't join aggregated queries")
GRDBPrecondition(query.havingExpression == nil, "Can't join aggregated queries")
GRDBPrecondition(query.limit == nil, "Can't join limited queries")
self.init(
source: query.source,
selection: query.selection,
filterPromise: query.filterPromise,
ordering: query.ordering,
joins: query.joins)
}
}
extension AssociationQuery {
func select(_ selection: [SQLSelectable]) -> AssociationQuery {
var query = self
query.selection = selection
return query
}
func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> AssociationQuery {
var query = self
query.filterPromise = query.filterPromise.map { (db, filter) in
if let filter = filter {
return try filter && predicate(db)
} else {
return try predicate(db).sqlExpression
}
}
return query
}
func order(_ orderings: [SQLOrderingTerm]) -> AssociationQuery {
return order(QueryOrdering(orderings: orderings))
}
func reversed() -> AssociationQuery {
return order(ordering.reversed)
}
private func order(_ ordering: QueryOrdering) -> AssociationQuery {
var query = self
query.ordering = ordering
return query
}
func joining(_ join: AssociationJoin) -> AssociationQuery {
var query = self
query.joins.append(join)
return query
}
func qualified(with alias: TableAlias) -> AssociationQuery {
var query = self
query.source = source.qualified(with: alias)
return query
}
}
extension AssociationQuery {
/// A finalized query is ready for SQL generation
var finalizedQuery: AssociationQuery {
var query = self
let alias = TableAlias()
query.source = source.qualified(with: alias)
query.selection = selection.map { $0.qualifiedSelectable(with: alias) }
query.filterPromise = filterPromise.map { [alias] (_, expr) in expr?.qualifiedExpression(with: alias) }
query.ordering = ordering.qualified(with: alias)
query.joins = joins.map { $0.finalizedJoin }
return query
}
/// precondition: self is the result of finalizedQuery
var finalizedAliases: [TableAlias] {
var aliases: [TableAlias] = []
if let alias = alias {
aliases.append(alias)
}
return joins.reduce(into: aliases) {
$0.append(contentsOf: $1.finalizedAliases)
}
}
/// precondition: self is the result of finalizedQuery
var finalizedSelection: [SQLSelectable] {
return joins.reduce(into: selection) {
$0.append(contentsOf: $1.finalizedSelection)
}
}
/// precondition: self is the result of finalizedQuery
var finalizedOrdering: QueryOrdering {
return joins.reduce(ordering) {
$0.appending($1.finalizedOrdering)
}
}
/// precondition: self is the result of finalizedQuery
func finalizedRowAdapter(_ db: Database, fromIndex startIndex: Int, forKeyPath keyPath: [String]) throws -> (adapter: RowAdapter, endIndex: Int)? {
let selectionWidth = try selection
.map { try $0.columnCount(db) }
.reduce(0, +)
var endIndex = startIndex + selectionWidth
var scopes: [String: RowAdapter] = [:]
for join in joins {
if let (joinAdapter, joinEndIndex) = try join.finalizedRowAdapter(db, fromIndex: endIndex, forKeyPath: keyPath + [join.key]) {
GRDBPrecondition(scopes[join.key] == nil, "The association key \"\((keyPath + [join.key]).joined(separator: "."))\" is ambiguous. Use the Association.forKey(_:) method is order to disambiguate.")
scopes[join.key] = joinAdapter
endIndex = joinEndIndex
}
}
if selectionWidth == 0 && scopes.isEmpty {
return nil
}
let adapter = RangeRowAdapter(startIndex ..< (startIndex + selectionWidth))
return (adapter: adapter.addingScopes(scopes), endIndex: endIndex)
}
}
@@ -0,0 +1,49 @@
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// In `SELECT a.*, b.* FROM a JOIN b ON b.aid = a.id AND b.name = 'foo'`,
/// the AssociationRequest is (`b.*` + `b.name = 'foo'`).
public struct AssociationRequest<T> {
let query: AssociationQuery
init(query: AssociationQuery) {
self.query = query
}
init(_ request: QueryInterfaceRequest<T>) {
self.init(query: AssociationQuery(request.query))
}
}
extension AssociationRequest {
func select(_ selection: [SQLSelectable]) -> AssociationRequest {
return AssociationRequest(query: query.select(selection))
}
func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> AssociationRequest {
return AssociationRequest(query: query.filter(predicate))
}
func order(_ orderings: [SQLOrderingTerm]) -> AssociationRequest {
return AssociationRequest(query: query.order(orderings))
}
func reversed() -> AssociationRequest {
return AssociationRequest(query: query.reversed())
}
func aliased(_ alias: TableAlias) -> AssociationRequest {
return AssociationRequest(query: query.qualified(with: alias))
}
func joining<A: Association>(_ joinOperator: AssociationJoinOperator, _ association: A)
-> AssociationRequest
where A.LeftAssociated == T
{
let join = AssociationJoin(
joinOperator: joinOperator,
query: association.request.query,
key: association.key,
joinConditionPromise: DatabasePromise(association.joinCondition))
return AssociationRequest(query: query.joining(join))
}
}
@@ -0,0 +1,67 @@
public struct BelongsToAssociation<Left, Right> : Association, TableRequest where
Left: TableRecord,
Right: TableRecord
{
public typealias LeftAssociated = Left
public typealias RightAssociated = Right
public var key: String
/// :nodoc:
public var databaseTableName: String { return RightAssociated.databaseTableName }
/// :nodoc:
public var request: AssociationRequest<Right>
let foreignKeyRequest: ForeignKeyRequest
public func forKey(_ key: String) -> BelongsToAssociation<Left, Right> {
var association = self
association.key = key
return association
}
/// :nodoc:
public func joinCondition(_ db: Database) throws -> JoinCondition {
return try ForeignKeyJoinConditionRequest(foreignKeyRequest: foreignKeyRequest, originIsLeft: true).fetch(db)
}
/// :nodoc:
public func mapRequest(_ transform: (AssociationRequest<Right>) -> AssociationRequest<Right>) -> BelongsToAssociation<Left, Right> {
var association = self
association.request = transform(request)
return association
}
}
extension TableRecord {
// TODO: Make it public if and only if we really want to build an association from any request
static func belongsTo<Right>(
_ rightRequest: QueryInterfaceRequest<Right>,
key: String? = nil,
using foreignKey: ForeignKey? = nil)
-> BelongsToAssociation<Self, Right>
where Right: TableRecord
{
let foreignKeyRequest = ForeignKeyRequest(
originTable: databaseTableName,
destinationTable: Right.databaseTableName,
foreignKey: foreignKey)
return BelongsToAssociation(
key: key ?? Right.databaseTableName,
request: AssociationRequest(rightRequest),
foreignKeyRequest: foreignKeyRequest)
}
/// TODO
public static func belongsTo<Right>(
_ right: Right.Type,
key: String? = nil,
using foreignKey: ForeignKey? = nil)
-> BelongsToAssociation<Self, Right>
where Right: TableRecord
{
return belongsTo(Right.all(), key: key, using: foreignKey)
}
}
@@ -0,0 +1,16 @@
/// A Foreign Key that helps building associations.
public struct ForeignKey {
let originColumns: [String]
let destinationColumns: [String]?
/// TODO
public init(_ originColumns: [String], to destinationColumns: [String]? = nil) {
self.originColumns = originColumns
self.destinationColumns = destinationColumns
}
/// TODO
public init(_ originColumns: [Column], to destinationColumns: [Column]? = nil) {
self.init(originColumns.map { $0.name }, to: destinationColumns?.map { $0.name })
}
}
@@ -0,0 +1,85 @@
/// ForeignKeyRequest looks for the foreign keys associations need to
/// join tables.
///
/// Mappings come from foreign keys, when they exist in the database schema.
///
/// When the schema does not define any foreign key, we can still infer complete
/// mappings from partial information and primary keys.
struct ForeignKeyRequest {
let originTable: String
let destinationTable: String
let originColumns: [String]?
let destinationColumns: [String]?
init(originTable: String, destinationTable: String, foreignKey: ForeignKey?) {
self.originTable = originTable
self.destinationTable = destinationTable
self.originColumns = foreignKey?.originColumns
self.destinationColumns = foreignKey?.destinationColumns
}
func fetch(_ db: Database) throws -> ForeignKeyInfo {
if let originColumns = originColumns, let destinationColumns = destinationColumns {
// Total information: no need to query the database schema.
GRDBPrecondition(originColumns.count == destinationColumns.count, "Number of columns don't match")
let mapping = zip(originColumns, destinationColumns).map {
(origin: $0, destination: $1)
}
return ForeignKeyInfo(destinationTable: destinationTable, mapping: mapping)
}
// Incomplete information: let's look for schema foreign keys
let foreignKeys = try db.foreignKeys(on: originTable).filter { foreignKey in
if destinationTable.lowercased() != foreignKey.destinationTable.lowercased() {
return false
}
if let originColumns = originColumns {
let originColumns = Set(originColumns.lazy.map { $0.lowercased() })
let foreignKeyColumns = Set(foreignKey.mapping.lazy.map { $0.origin.lowercased() })
if originColumns != foreignKeyColumns {
return false
}
}
// TODO: test
if let destinationColumns = destinationColumns {
let destinationColumns = Set(destinationColumns.lazy.map { $0.lowercased() })
let foreignKeyColumns = Set(foreignKey.mapping.lazy.map { $0.destination.lowercased() })
if destinationColumns != foreignKeyColumns {
return false
}
}
return true
}
// Matching foreign key(s) found
if let foreignKey = foreignKeys.first {
if foreignKeys.count == 1 {
// Non-ambiguous
// TODO: test
return foreignKey
} else {
// Ambiguous: can't choose
fatalError("Ambiguous foreign key from \(originTable) to \(destinationTable)")
}
}
// No matching foreign key found: use the destination primary key
if let originColumns = originColumns {
let destinationColumns = try db.primaryKey(destinationTable).columns
if (originColumns.count == destinationColumns.count) {
// TODO: test
let mapping = zip(originColumns, destinationColumns).map {
(origin: $0, destination: $1)
}
return ForeignKeyInfo(destinationTable: destinationTable, mapping: mapping)
}
}
fatalError("Could not infer foreign key from \(originTable) to \(destinationTable)")
}
}
/// The (origin, destination) column pairs that join a left table to a right table.
/// :nodoc:
typealias ForeignKeyMapping = [(origin: String, destination: String)]
@@ -0,0 +1,67 @@
public struct HasManyAssociation<Left, Right> : Association, TableRequest where
Left: TableRecord,
Right: TableRecord
{
public typealias LeftAssociated = Left
public typealias RightAssociated = Right
public var key: String
/// :nodoc:
public var databaseTableName: String { return RightAssociated.databaseTableName }
/// :nodoc:
public var request: AssociationRequest<Right>
let foreignKeyRequest: ForeignKeyRequest
public func forKey(_ key: String) -> HasManyAssociation<Left, Right> {
var association = self
association.key = key
return association
}
/// :nodoc:
public func joinCondition(_ db: Database) throws -> JoinCondition {
return try ForeignKeyJoinConditionRequest(foreignKeyRequest: foreignKeyRequest, originIsLeft: false).fetch(db)
}
/// :nodoc:
public func mapRequest(_ transform: (AssociationRequest<Right>) -> AssociationRequest<Right>) -> HasManyAssociation<Left, Right> {
var association = self
association.request = transform(request)
return association
}
}
extension TableRecord {
// TODO: Make it public if and only if we really want to build an association from any request
static func hasMany<Right>(
_ rightRequest: QueryInterfaceRequest<Right>,
key: String? = nil,
using foreignKey: ForeignKey? = nil)
-> HasManyAssociation<Self, Right>
where Right: TableRecord
{
let foreignKeyRequest = ForeignKeyRequest(
originTable: Right.databaseTableName,
destinationTable: databaseTableName,
foreignKey: foreignKey)
return HasManyAssociation(
key: key ?? Right.databaseTableName,
request: AssociationRequest(rightRequest),
foreignKeyRequest: foreignKeyRequest)
}
/// TODO
public static func hasMany<Right>(
_ right: Right.Type,
key: String? = nil,
using foreignKey: ForeignKey? = nil)
-> HasManyAssociation<Self, Right>
where Right: TableRecord
{
return hasMany(Right.all(), key: key, using: foreignKey)
}
}
@@ -0,0 +1,67 @@
public struct HasOneAssociation<Left, Right> : Association, TableRequest where
Left: TableRecord,
Right: TableRecord
{
public typealias LeftAssociated = Left
public typealias RightAssociated = Right
public var key: String
/// :nodoc:
public var databaseTableName: String { return RightAssociated.databaseTableName }
/// :nodoc:
public var request: AssociationRequest<Right>
let foreignKeyRequest: ForeignKeyRequest
public func forKey(_ key: String) -> HasOneAssociation<Left, Right> {
var association = self
association.key = key
return association
}
/// :nodoc:
public func joinCondition(_ db: Database) throws -> JoinCondition {
return try ForeignKeyJoinConditionRequest(foreignKeyRequest: foreignKeyRequest, originIsLeft: false).fetch(db)
}
/// :nodoc:
public func mapRequest(_ transform: (AssociationRequest<Right>) -> AssociationRequest<Right>) -> HasOneAssociation<Left, Right> {
var association = self
association.request = transform(request)
return association
}
}
extension TableRecord {
// TODO: Make it public if and only if we really want to build an association from any request
static func hasOne<Right>(
_ rightRequest: QueryInterfaceRequest<Right>,
key: String? = nil,
using foreignKey: ForeignKey? = nil)
-> HasOneAssociation<Self, Right>
where Right: TableRecord
{
let foreignKeyRequest = ForeignKeyRequest(
originTable: Right.databaseTableName,
destinationTable: databaseTableName,
foreignKey: foreignKey)
return HasOneAssociation(
key: key ?? Right.databaseTableName,
request: AssociationRequest(rightRequest),
foreignKeyRequest: foreignKeyRequest)
}
/// TODO
public static func hasOne<Right>(
_ right: Right.Type,
key: String? = nil,
using foreignKey: ForeignKey? = nil)
-> HasOneAssociation<Self, Right>
where Right: TableRecord
{
return hasOne(Right.all(), key: key, using: foreignKey)
}
}
+26 -10
View File
@@ -28,14 +28,20 @@ public protocol ColumnExpression: SQLExpression {
extension ColumnExpression {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
public func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return name.quotedDatabaseIdentifier
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return QualifiedColumn(name, qualifier: qualifier)
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return QualifiedColumn(name, alias: alias)
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return self
}
}
@@ -61,25 +67,35 @@ public struct Column: ColumnExpression {
/// A qualified column in the database, as in `SELECT t.a FROM t`
struct QualifiedColumn: ColumnExpression {
var name: String
private let qualifier: SQLTableQualifier
private let alias: TableAlias
/// Creates a column given its name.
init(_ name: String, qualifier: SQLTableQualifier) {
init(_ name: String, alias: TableAlias) {
self.name = name
self.qualifier = qualifier
self.alias = alias
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
if let qualifierName = qualifier.name {
return qualifierName.quotedDatabaseIdentifier + "." + name.quotedDatabaseIdentifier
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
if let qualifier = context.qualifier(for: alias) {
return qualifier.quotedDatabaseIdentifier + "." + name.quotedDatabaseIdentifier
}
return name.quotedDatabaseIdentifier
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
// Never requalify
return self
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
guard
let container = context[alias.root],
let value = container.value(forCaseInsensitiveColumn: name) else
{
return self
}
return value
}
}
/// Support for column enums:
@@ -5,20 +5,20 @@ extension QueryInterfaceRequest {
/// Creates a request with a full-text predicate added to the eventual
/// set of already applied predicates.
///
/// // SELECT * FROM books WHERE books MATCH '...'
/// // SELECT * FROM book WHERE book MATCH '...'
/// var request = Book.all()
/// request = request.matching(pattern)
///
/// If the search pattern is nil, the request does not match any
/// database row.
public func matching(_ pattern: FTS3Pattern?) -> QueryInterfaceRequest<T> {
switch query.source {
case .table(let name, let alias)?:
return filter(SQLExpressionBinary(.match, Column(alias ?? name), pattern ?? DatabaseValue.null))
default:
// Programmer error
fatalError("fts3 match requires a table")
guard let pattern = pattern else {
return none()
}
let alias = TableAlias()
let qualifiedQuery = query.qualified(with: alias)
let matchExpression = TableMatchExpression(alias: alias, pattern: pattern.databaseValue)
return QueryInterfaceRequest(query: qualifiedQuery).filter(matchExpression)
}
}
@@ -28,7 +28,7 @@ extension TableRecord {
/// Returns a QueryInterfaceRequest with a matching predicate.
///
/// // SELECT * FROM books WHERE books MATCH '...'
/// // SELECT * FROM book WHERE book MATCH '...'
/// var request = Book.matching(pattern)
///
/// If the search pattern is nil, the request does not match any
+8 -12
View File
@@ -6,7 +6,7 @@
/// Creates a request with a full-text predicate added to the eventual
/// set of already applied predicates.
///
/// // SELECT * FROM books WHERE books MATCH '...'
/// // SELECT * FROM book WHERE book MATCH '...'
/// var request = Book.all()
/// request = request.matching(pattern)
///
@@ -17,17 +17,13 @@
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func matching(_ pattern: FTS5Pattern?) -> QueryInterfaceRequest<T> {
switch query.source {
case .table(let name, let alias)?:
if let pattern = pattern {
return filter(SQLExpressionBinary(.match, Column(alias ?? name), pattern))
} else {
return filter(false)
}
default:
// Programmer error
fatalError("fts5 match requires a table")
guard let pattern = pattern else {
return none()
}
let alias = TableAlias()
let qualifiedQuery = query.qualified(with: alias)
let matchExpression = TableMatchExpression(alias: alias, pattern: pattern.databaseValue)
return QueryInterfaceRequest(query: qualifiedQuery).filter(matchExpression)
}
}
@@ -37,7 +33,7 @@
/// Returns a QueryInterfaceRequest with a matching predicate.
///
/// // SELECT * FROM books WHERE books MATCH '...'
/// // SELECT * FROM book WHERE book MATCH '...'
/// var request = Book.matching(pattern)
///
/// If the search pattern is nil, the request does not match any
+447 -87
View File
@@ -17,70 +17,240 @@ struct DatabasePromise<T> {
}
struct QueryInterfaceQuery {
var source: SQLSource
var selection: [SQLSelectable]
var isDistinct: Bool
var source: SQLSource?
var wherePromise: DatabasePromise<SQLExpression?>
var filterPromise: DatabasePromise<SQLExpression?>
var groupByExpressions: [SQLExpression]
var ordering: QueryOrdering
var havingExpression: SQLExpression?
var limit: SQLLimit?
var joins: [AssociationJoin]
init(
select selection: [SQLSelectable],
source: SQLSource,
selection: [SQLSelectable] = [],
isDistinct: Bool = false,
from source: SQLSource? = nil,
filter whereExpression: SQLExpression? = nil,
groupBy groupByExpressions: [SQLExpression] = [],
orderBy ordering: QueryOrdering = QueryOrdering(),
having havingExpression: SQLExpression? = nil,
limit: SQLLimit? = nil)
filterPromise: DatabasePromise<SQLExpression?> = DatabasePromise(value: nil),
groupByExpressions: [SQLExpression] = [],
ordering: QueryOrdering = QueryOrdering(),
havingExpression: SQLExpression? = nil,
limit: SQLLimit? = nil,
joins: [AssociationJoin] = [])
{
self.source = source
self.selection = selection
self.isDistinct = isDistinct
self.source = source
self.wherePromise = DatabasePromise(value: whereExpression)
self.filterPromise = filterPromise
self.groupByExpressions = groupByExpressions
self.ordering = ordering
self.havingExpression = havingExpression
self.limit = limit
self.joins = joins
}
func mapWhereExpression(_ transform: @escaping (Database, SQLExpression?) throws -> SQLExpression?) -> QueryInterfaceQuery {
init(_ query: AssociationQuery) {
self.init(
source: query.source,
selection: query.selection,
filterPromise: query.filterPromise,
ordering: query.ordering,
joins: query.joins)
}
var alias: TableAlias? {
return source.alias
}
}
extension QueryInterfaceQuery {
func select(_ selection: [SQLSelectable]) -> QueryInterfaceQuery {
var query = self
query.wherePromise = query.wherePromise.map(transform)
query.selection = selection
return query
}
func sql(_ db: Database, _ arguments: inout StatementArguments?) throws -> String {
func distinct() -> QueryInterfaceQuery {
var query = self
query.isDistinct = true
return query
}
func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> QueryInterfaceQuery {
var query = self
query.filterPromise = query.filterPromise.map { (db, filter) in
if let filter = filter {
return try filter && predicate(db)
} else {
return try predicate(db).sqlExpression
}
}
return query
}
func group(_ expressions: [SQLExpressible]) -> QueryInterfaceQuery {
var query = self
query.groupByExpressions = expressions.map { $0.sqlExpression }
return query
}
func having(_ predicate: SQLExpressible) -> QueryInterfaceQuery {
var query = self
if let havingExpression = query.havingExpression {
query.havingExpression = (havingExpression && predicate).sqlExpression
} else {
query.havingExpression = predicate.sqlExpression
}
return query
}
func order(_ orderings: [SQLOrderingTerm]) -> QueryInterfaceQuery {
return order(QueryOrdering(orderings: orderings))
}
func reversed() -> QueryInterfaceQuery {
return order(ordering.reversed)
}
private func order(_ ordering: QueryOrdering) -> QueryInterfaceQuery {
var query = self
query.ordering = ordering
return query
}
func unordered() -> QueryInterfaceQuery {
var query = self
query.ordering = QueryOrdering()
return query
}
func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceQuery {
var query = self
query.limit = SQLLimit(limit: limit, offset: offset)
return query
}
func joining(_ join: AssociationJoin) -> QueryInterfaceQuery {
var query = self
query.joins.append(join)
return query
}
func qualified(with alias: TableAlias) -> QueryInterfaceQuery {
var query = self
query.source = source.qualified(with: alias)
return query
}
}
extension QueryInterfaceQuery {
/// A finalized query is ready for SQL generation
var finalizedQuery: QueryInterfaceQuery {
var query = self
let alias = TableAlias()
query.source = source.qualified(with: alias)
query.selection = query.selection.map { $0.qualifiedSelectable(with: alias) }
query.filterPromise = query.filterPromise.map { [alias] (_, expr) in expr?.qualifiedExpression(with: alias) }
query.groupByExpressions = query.groupByExpressions.map { $0.qualifiedExpression(with: alias) }
query.ordering = query.ordering.qualified(with: alias)
query.havingExpression = query.havingExpression?.qualifiedExpression(with: alias)
query.joins = query.joins.map { $0.finalizedJoin }
return query
}
/// precondition: self is the result of finalizedQuery
var finalizedAliases: [TableAlias] {
var aliases: [TableAlias] = []
if let alias = alias {
aliases.append(alias)
}
return joins.reduce(into: aliases) {
$0.append(contentsOf: $1.finalizedAliases)
}
}
/// precondition: self is the result of finalizedQuery
var finalizedSelection: [SQLSelectable] {
return joins.reduce(into: selection) {
$0.append(contentsOf: $1.finalizedSelection)
}
}
/// precondition: self is the result of finalizedQuery
var finalizedOrdering: QueryOrdering {
return joins.reduce(ordering) {
$0.appending($1.finalizedOrdering)
}
}
/// precondition: self is the result of finalizedQuery
private func finalizedRowAdapter(_ db: Database) throws -> RowAdapter? {
if joins.isEmpty {
return nil
}
let selectionWidth = try selection
.map { try $0.columnCount(db) }
.reduce(0, +)
var endIndex = selectionWidth
var scopes: [String: RowAdapter] = [:]
for join in joins {
if let (joinAdapter, joinEndIndex) = try join.finalizedRowAdapter(db, fromIndex: endIndex, forKeyPath: [join.key]) {
GRDBPrecondition(scopes[join.key] == nil, "The association key \"\(join.key)\" is ambiguous. Use the Association.forKey(_:) method is order to disambiguate.")
scopes[join.key] = joinAdapter
endIndex = joinEndIndex
}
}
if selectionWidth == 0 && scopes.isEmpty {
return nil
}
let adapter = RangeRowAdapter(0 ..< (0 + selectionWidth))
return adapter.addingScopes(scopes)
}
}
extension QueryInterfaceQuery {
/// precondition: self is the result of finalizedQuery
func sql(_ db: Database, _ context: inout SQLGenerationContext) throws -> String {
var sql = "SELECT"
if isDistinct {
sql += " DISTINCT"
}
assert(!selection.isEmpty)
sql += " " + selection.map { $0.resultColumnSQL(&arguments) }.joined(separator: ", ")
let selection = finalizedSelection
GRDBPrecondition(!selection.isEmpty, "Can't generate SQL with empty selection")
sql += " " + selection.map { $0.resultColumnSQL(&context) }.joined(separator: ", ")
if let source = source {
sql += try " FROM " + source.sourceSQL(db, &arguments)
sql += try " FROM " + source.sourceSQL(db, &context)
for join in joins {
sql += try " " + join.joinSQL(db, &context, leftAlias: alias!, isRequiredAllowed: true)
}
if let whereExpression = try wherePromise.resolve(db) {
sql += " WHERE " + whereExpression.expressionSQL(&arguments)
if let filter = try filterPromise.resolve(db) {
sql += " WHERE " + filter.expressionSQL(&context)
}
if !groupByExpressions.isEmpty {
sql += " GROUP BY " + groupByExpressions.map { $0.expressionSQL(&arguments) }.joined(separator: ", ")
sql += " GROUP BY "
sql += groupByExpressions.map { $0.expressionSQL(&context) }
.joined(separator: ", ")
}
if let havingExpression = havingExpression {
sql += " HAVING " + havingExpression.expressionSQL(&arguments)
sql += " HAVING " + havingExpression.expressionSQL(&context)
}
let orderings = self.ordering.resolve()
let orderings = finalizedOrdering.resolve()
if !orderings.isEmpty {
sql += " ORDER BY " + orderings.map { $0.orderingTermSQL(&arguments) }.joined(separator: ", ")
sql += " ORDER BY " + orderings.map { $0.orderingTermSQL(&context) }.joined(separator: ", ")
}
if let limit = limit {
@@ -90,32 +260,49 @@ struct QueryInterfaceQuery {
return sql
}
/// precondition: self is the result of finalizedQuery
private func makeSelectStatement(_ db: Database) throws -> SelectStatement {
var context = SQLGenerationContext.queryGenerationContext(aliases: finalizedAliases)
let sql = try self.sql(db, &context)
let statement = try db.makeSelectStatement(sql)
statement.arguments = context.arguments!
return statement
}
/// precondition: self is the result of finalizedQuery
func makeDeleteStatement(_ db: Database) throws -> UpdateStatement {
guard groupByExpressions.isEmpty else {
// Programmer error
fatalError("Can't delete query with GROUP BY expression")
fatalError("Can't delete query with GROUP BY clause")
}
guard havingExpression == nil else {
// Programmer error
fatalError("Can't delete query with GROUP BY expression")
fatalError("Can't delete query with HAVING clause")
}
var sql = "DELETE"
var arguments: StatementArguments? = StatementArguments()
if let source = source {
sql += try " FROM " + source.sourceSQL(db, &arguments)
guard joins.isEmpty else {
// Programmer error
fatalError("Can't delete query with JOIN clause")
}
if let whereExpression = try wherePromise.resolve(db) {
sql += " WHERE " + whereExpression.expressionSQL(&arguments)
guard case .table = source else {
// Programmer error
fatalError("Can't delete without any database table")
}
var context = SQLGenerationContext.queryGenerationContext(aliases: finalizedAliases)
var sql = try "DELETE FROM " + source.sourceSQL(db, &context)
if let filter = try filterPromise.resolve(db) {
sql += " WHERE " + filter.expressionSQL(&context)
}
if let limit = limit {
let orderings = self.ordering.resolve()
let orderings = finalizedOrdering.resolve()
if !orderings.isEmpty {
sql += " ORDER BY " + orderings.map { $0.orderingTermSQL(&arguments) }.joined(separator: ", ")
sql += " ORDER BY " + orderings.map { $0.orderingTermSQL(&context) }.joined(separator: ", ")
}
if Database.sqliteCompileOptions.contains("ENABLE_UPDATE_DELETE_LIMIT") {
@@ -126,25 +313,13 @@ struct QueryInterfaceQuery {
}
let statement = try db.makeUpdateStatement(sql)
statement.arguments = arguments!
statement.arguments = context.arguments!
return statement
}
/// Remove ordering
var unorderedQuery: QueryInterfaceQuery {
var query = self
query.ordering = QueryOrdering()
return query
}
}
extension QueryInterfaceQuery {
/// precondition: self is the result of finalizedQuery
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
var arguments: StatementArguments? = StatementArguments()
let sql = try self.sql(db, &arguments)
let statement = try db.makeSelectStatement(sql)
try statement.setArgumentsWithValidation(arguments!)
return (statement, nil)
return try (makeSelectStatement(db), finalizedRowAdapter(db))
}
func fetchCount(_ db: Database) throws -> Int {
@@ -153,17 +328,16 @@ extension QueryInterfaceQuery {
}
/// The database region that the request looks into.
/// precondition: self is the result of finalizedQuery
func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
let (statement, _) = try prepare(db)
let statement = try makeSelectStatement(db)
let region = statement.fetchedRegion
// Can we intersect the region with rowIds?
//
// Give up unless request feeds from a single database table
guard let source = source else {
return region
}
guard case .table(name: let tableName, alias: _) = source else {
guard case .table(tableName: let tableName, alias: _) = source else {
// TODO: try harder
return region
}
@@ -174,17 +348,17 @@ extension QueryInterfaceQuery {
}
// Give up unless there is a where clause
guard let whereExpression = try wherePromise.resolve(db) else {
guard let filter = try filterPromise.resolve(db) else {
return region
}
// The whereExpression knows better
guard let rowIds = whereExpression.matchedRowIds(rowIdName: primaryKeyInfo.rowIDColumn) else {
// The filter knows better
guard let rowIds = filter.matchedRowIds(rowIdName: primaryKeyInfo.rowIDColumn) else {
return region
}
// Database regions are case-insensitive: use the canonical table name
let canonicalTableName = try db.canonicalName(table: tableName)
let canonicalTableName = try db.canonicalTableName(tableName)
return region.tableIntersection(canonicalTableName, rowIds: rowIds)
}
@@ -195,17 +369,17 @@ extension QueryInterfaceQuery {
return trivialCountQuery
}
guard let source = source, case .table = source else {
// SELECT ... FROM (something which is not a table)
guard joins.isEmpty, case .table = source else {
// SELECT ... FROM (something which is not a plain table)
return trivialCountQuery
}
assert(!selection.isEmpty)
GRDBPrecondition(!selection.isEmpty, "Can't generate SQL with empty selection")
if selection.count == 1 {
guard let count = self.selection[0].count(distinct: isDistinct) else {
return trivialCountQuery
}
var countQuery = unorderedQuery
var countQuery = self.unordered()
countQuery.isDistinct = false
countQuery.selection = [count.sqlSelectable]
return countQuery
@@ -219,7 +393,7 @@ extension QueryInterfaceQuery {
// SELECT expr1, expr2, ... FROM tableName ...
// ->
// SELECT COUNT(*) FROM tableName ...
var countQuery = unorderedQuery
var countQuery = self.unordered()
countQuery.selection = [SQLExpressionCount(AllColumns())]
return countQuery
}
@@ -228,59 +402,245 @@ extension QueryInterfaceQuery {
// SELECT COUNT(*) FROM (self)
private var trivialCountQuery: QueryInterfaceQuery {
return QueryInterfaceQuery(
select: [SQLExpressionCount(AllColumns())],
from: .query(query: unorderedQuery, alias: nil))
source: .query(unordered()),
selection: [SQLExpressionCount(AllColumns())])
}
}
// MARK: - AssociationJoin
/// Not to be mismatched with SQL join operators (inner join, left join).
///
/// AssociationJoinOperator is designed to be hierarchically nested, unlike
/// SQL join operators.
///
/// Consider the following request for (A, B, C) tuples:
///
/// let r = A.including(optional: A.b.including(required: B.c))
///
/// It chains three associations, the first optional, the second required.
///
/// It looks like it means: "Give me all As, along with their Bs, granted those
/// Bs have their Cs. For As whose B has no C, give me a nil B".
///
/// It can not be expressed as one left join, and a regular join, as below,
/// Because this would not honor the first optional:
///
/// -- dubious
/// SELECT a.*, b.*, c.*
/// FROM a
/// LEFT JOIN b ON ...
/// JOIN c ON ...
///
/// Instead, it should:
/// - allow (A + missing (B + C))
/// - prevent (A + (B + missing C)).
///
/// This can be expressed in SQL with two left joins, and an extra condition:
///
/// -- likely correct
/// SELECT a.*, b.*, c.*
/// FROM a
/// LEFT JOIN b ON ...
/// LEFT JOIN c ON ...
/// WHERE NOT((b.id IS NOT NULL) AND (c.id IS NULL)) -- no B without C
///
/// This is currently not implemented, and requires a little more thought.
/// I don't even know if inventing a whole new way to perform joins should even
/// be on the table. But we have a hierarchical way to express joined queries,
/// and they have a meaning:
///
/// // what is my meaning?
/// A.including(optional: A.b.including(required: B.c))
enum AssociationJoinOperator {
case required, optional
}
struct AssociationJoin {
var joinOperator: AssociationJoinOperator
var query: AssociationQuery
var key: String
var joinConditionPromise: DatabasePromise<JoinCondition>
var finalizedJoin: AssociationJoin {
var join = self
join.query = query.finalizedQuery
return join
}
var finalizedAliases: [TableAlias] {
return query.finalizedAliases
}
var finalizedSelection: [SQLSelectable] {
return query.finalizedSelection
}
var finalizedOrdering: QueryOrdering {
return query.finalizedOrdering
}
func finalizedRowAdapter(_ db: Database, fromIndex startIndex: Int, forKeyPath keyPath: [String]) throws -> (adapter: RowAdapter, endIndex: Int)? {
return try query.finalizedRowAdapter(db, fromIndex: startIndex, forKeyPath: keyPath)
}
/// precondition: query is the result of finalizedQuery
func joinSQL(_ db: Database,_ context: inout SQLGenerationContext, leftAlias: TableAlias, isRequiredAllowed: Bool) throws -> String {
var isRequiredAllowed = isRequiredAllowed
var sql = ""
switch joinOperator {
case .optional:
isRequiredAllowed = false
sql += "LEFT JOIN"
case .required:
guard isRequiredAllowed else {
// TODO: chainOptionalRequired
fatalError("Not implemented: chaining a required association behind an optional association")
}
sql += "JOIN"
}
sql += try " " + query.source.sourceSQL(db, &context)
let rightAlias = query.alias!
let filters = try [
joinConditionPromise.resolve(db)(leftAlias, rightAlias),
query.filterPromise.resolve(db)
].compactMap { $0 }
if !filters.isEmpty {
sql += " ON " + filters.joined(operator: .and).expressionSQL(&context)
}
for join in query.joins {
sql += try " " + join.joinSQL(db, &context, leftAlias: rightAlias, isRequiredAllowed: isRequiredAllowed)
}
return sql
}
}
// MARK: - QueryOrdering
struct QueryOrdering {
private var orderings: [SQLOrderingTerm]
private var elements: [Element] = []
var isReversed: Bool
init(orderings: [SQLOrderingTerm] = [], isReversed: Bool = false) {
self.orderings = orderings
private enum Element {
case orderingTerm(SQLOrderingTerm)
case queryOrdering(QueryOrdering)
var reversed: Element {
switch self {
case .orderingTerm(let orderingTerm):
return .orderingTerm(orderingTerm.reversed)
case .queryOrdering(let queryOrdering):
return .queryOrdering(queryOrdering.reversed)
}
}
func qualified(with alias: TableAlias) -> Element {
switch self {
case .orderingTerm(let orderingTerm):
return .orderingTerm(orderingTerm.qualifiedOrdering(with: alias))
case .queryOrdering(let queryOrdering):
return .queryOrdering(queryOrdering.qualified(with: alias))
}
}
func resolve() -> [SQLOrderingTerm] {
switch self {
case .orderingTerm(let orderingTerm):
return [orderingTerm]
case .queryOrdering(let queryOrdering):
return queryOrdering.resolve()
}
}
}
private init(elements: [Element], isReversed: Bool) {
self.elements = elements
self.isReversed = isReversed
}
func reversed() -> QueryOrdering {
init() {
self.init(
elements: [],
isReversed: false)
}
init(orderings: [SQLOrderingTerm]) {
self.init(
elements: orderings.map { .orderingTerm($0) },
isReversed: false)
}
var reversed: QueryOrdering {
return QueryOrdering(
orderings: orderings,
elements: elements,
isReversed: !isReversed)
}
func appending(ordering: SQLOrderingTerm) -> QueryOrdering {
func qualified(with alias: TableAlias) -> QueryOrdering {
return QueryOrdering(
orderings: orderings + [ordering],
elements: elements.map { $0.qualified(with: alias) },
isReversed: isReversed)
}
func appending(_ ordering: QueryOrdering) -> QueryOrdering {
return QueryOrdering(
elements: elements + [.queryOrdering(ordering)],
isReversed: isReversed)
}
func resolve() -> [SQLOrderingTerm] {
if isReversed {
return orderings.map { $0.reversed }
return elements.flatMap { $0.reversed.resolve() }
} else {
return orderings
return elements.flatMap { $0.resolve() }
}
}
}
indirect enum SQLSource {
case table(name: String, alias: String?)
case query(query: QueryInterfaceQuery, alias: String?)
// MARK: - SQLSource
enum SQLSource {
case table(tableName: String, alias: TableAlias?)
indirect case query(QueryInterfaceQuery)
func sourceSQL(_ db: Database, _ arguments: inout StatementArguments?) throws -> String {
var alias: TableAlias? {
switch self {
case .table(let table, let alias):
if let alias = alias {
return table.quotedDatabaseIdentifier + " AS " + alias.quotedDatabaseIdentifier
case .table(_, let alias):
return alias
case .query(let query):
return query.alias
}
}
func sourceSQL(_ db: Database, _ context: inout SQLGenerationContext) throws -> String {
switch self {
case .table(let tableName, let alias):
if let alias = alias, let aliasName = context.aliasName(for: alias) {
return "\(tableName.quotedDatabaseIdentifier) \(aliasName.quotedDatabaseIdentifier)"
} else {
return table.quotedDatabaseIdentifier
return "\(tableName.quotedDatabaseIdentifier)"
}
case .query(let query, let alias):
if let alias = alias {
return try "(" + query.sql(db, &arguments) + ") AS " + alias.quotedDatabaseIdentifier
case .query(let query):
return try "(\(query.sql(db, &context)))"
}
}
func qualified(with alias: TableAlias) -> SQLSource {
switch self {
case .table(let tableName, let sourceAlias):
if let sourceAlias = sourceAlias {
alias.rebase(on: sourceAlias)
return self
} else {
return try "(" + query.sql(db, &arguments) + ")"
alias.setTableName(tableName)
return .table(tableName: tableName, alias: alias)
}
case .query(let query):
return .query(query.qualified(with: alias))
}
}
}
@@ -0,0 +1,95 @@
extension QueryInterfaceRequest where RowDecoder: TableRecord {
func joining<A: Association>(_ joinOperator: AssociationJoinOperator, _ association: A)
-> QueryInterfaceRequest<RowDecoder>
where A.LeftAssociated == RowDecoder
{
let join = AssociationJoin(
joinOperator: joinOperator,
query: association.request.query,
key: association.key,
joinConditionPromise: DatabasePromise(association.joinCondition))
return QueryInterfaceRequest(query: query.joining(join))
}
// MARK: - Associations
/// Creates a request that includes an association. The columns of the
/// associated record are selected. The returned association does not
/// require that the associated database table contains a matching row.
public func including<A: Association>(optional association: A) -> QueryInterfaceRequest<RowDecoder> where A.LeftAssociated == RowDecoder {
return joining(.optional, association)
}
/// Creates a request that includes an association. The columns of the
/// associated record are selected. The returned association requires
/// that the associated database table contains a matching row.
public func including<A: Association>(required association: A) -> QueryInterfaceRequest<RowDecoder> where A.LeftAssociated == RowDecoder {
return joining(.required, association)
}
/// Creates a request that includes an association. The columns of the
/// associated record are not selected. The returned association does not
/// require that the associated database table contains a matching row.
public func joining<A: Association>(optional association: A) -> QueryInterfaceRequest<RowDecoder> where A.LeftAssociated == RowDecoder {
return joining(.optional, association.select([]))
}
/// Creates a request that includes an association. The columns of the
/// associated record are not selected. The returned association requires
/// that the associated database table contains a matching row.
public func joining<A: Association>(required association: A) -> QueryInterfaceRequest<RowDecoder> where A.LeftAssociated == RowDecoder {
return joining(.required, association.select([]))
}
}
extension MutablePersistableRecord {
/// Creates a request that fetches the associated record(s).
///
/// For example:
///
/// struct Team: {
/// static let players = hasMany(Player.self)
/// var players: QueryInterfaceRequest<Player> {
/// return request(for: Team.players)
/// }
/// }
///
/// let team: Team = ...
/// let players = try team.players.fetchAll(db) // [Player]
public func request<A: Association>(for association: A) -> QueryInterfaceRequest<A.RightAssociated> where A.LeftAssociated == Self {
return association.request(from: self)
}
}
extension TableRecord {
// MARK: - Associations
/// Creates a request that includes an association. The columns of the
/// associated record are selected. The returned association does not
/// require that the associated database table contains a matching row.
public static func including<A: Association>(optional association: A) -> QueryInterfaceRequest<Self> where A.LeftAssociated == Self {
return all().including(optional: association)
}
/// Creates a request that includes an association. The columns of the
/// associated record are selected. The returned association requires
/// that the associated database table contains a matching row.
public static func including<A: Association>(required association: A) -> QueryInterfaceRequest<Self> where A.LeftAssociated == Self {
return all().including(required: association)
}
/// Creates a request that includes an association. The columns of the
/// associated record are not selected. The returned association does not
/// require that the associated database table contains a matching row.
public static func joining<A: Association>(optional association: A) -> QueryInterfaceRequest<Self> where A.LeftAssociated == Self {
return all().joining(optional: association)
}
/// Creates a request that includes an association. The columns of the
/// associated record are not selected. The returned association requires
/// that the associated database table contains a matching row.
public static func joining<A: Association>(required association: A) -> QueryInterfaceRequest<Self> where A.LeftAssociated == Self {
return all().joining(required: association)
}
}
+118 -190
View File
@@ -7,6 +7,10 @@ public struct QueryInterfaceRequest<T> {
init(query: QueryInterfaceQuery) {
self.query = query
}
init(_ request: AssociationRequest<T>) {
self.query = QueryInterfaceQuery(request.query)
}
}
extension QueryInterfaceRequest : FetchRequest {
@@ -19,7 +23,7 @@ extension QueryInterfaceRequest : FetchRequest {
/// - returns: A prepared statement and an eventual row adapter.
/// :nodoc:
public func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
return try query.prepare(db)
return try query.finalizedQuery.prepare(db)
}
/// Returns the number of rows fetched by the request.
@@ -35,7 +39,7 @@ extension QueryInterfaceRequest : FetchRequest {
/// - parameter db: A database connection.
/// :nodoc:
public func fetchedRegion(_ db: Database) throws -> DatabaseRegion {
return try query.fetchedRegion(db)
return try query.finalizedQuery.fetchedRegion(db)
}
}
@@ -45,242 +49,146 @@ extension QueryInterfaceRequest : SelectionRequest, FilteredRequest, Aggregating
/// Creates a request with a new net of selected columns.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// var request = Player.all()
/// request = request.select([Column("id"), Column("email")])
///
/// Any previous selection is replaced:
///
/// // SELECT email FROM players
/// // SELECT email FROM player
/// request
/// .select([Column("id")])
/// .select([Column("email")])
public func select(_ selection: [SQLSelectable]) -> QueryInterfaceRequest<T> {
var query = self.query
query.selection = selection
return QueryInterfaceRequest(query: query)
return QueryInterfaceRequest(query: query.select(selection))
}
/// Creates a request which returns distinct rows.
///
/// // SELECT DISTINCT * FROM players
/// // SELECT DISTINCT * FROM player
/// var request = Player.all()
/// request = request.distinct()
///
/// // SELECT DISTINCT name FROM players
/// // SELECT DISTINCT name FROM player
/// var request = Player.select(Column("name"))
/// request = request.distinct()
public func distinct() -> QueryInterfaceRequest<T> {
var query = self.query
query.isDistinct = true
return QueryInterfaceRequest(query: query)
return QueryInterfaceRequest(query: query.distinct())
}
/// Creates a request with the provided *predicate* added to the
/// Creates a request with the provided *predicate promise* added to the
/// eventual set of already applied predicates.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE 1
/// var request = Player.all()
/// request = request.filter(Column("email") == "arthur@example.com")
public func filter(_ predicate: SQLExpressible) -> QueryInterfaceRequest<T> {
return QueryInterfaceRequest(query: query.mapWhereExpression { (db, expression) in
if let expression = expression {
return expression && predicate.sqlExpression
} else {
return predicate.sqlExpression
}
})
}
/// Creates a request that matches nothing.
///
/// // SELECT * FROM players WHERE 0
/// var request = Player.all()
/// request = request.none()
public func none() -> QueryInterfaceRequest<T> {
var query = self.query
query.wherePromise = DatabasePromise(value: false.sqlExpression)
return QueryInterfaceRequest(query: query)
/// request = request.filter { db in true }
public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> QueryInterfaceRequest<T> {
return QueryInterfaceRequest(query: query.filter(predicate))
}
/// Creates a request grouped according to *expressions*.
public func group(_ expressions: [SQLExpressible]) -> QueryInterfaceRequest<T> {
var query = self.query
query.groupByExpressions = expressions.map { $0.sqlExpression }
return QueryInterfaceRequest(query: query)
return QueryInterfaceRequest(query: query.group(expressions))
}
/// Creates a request with the provided *predicate* added to the
/// eventual set of already applied predicates.
public func having(_ predicate: SQLExpressible) -> QueryInterfaceRequest<T> {
var query = self.query
if let havingExpression = query.havingExpression {
query.havingExpression = (havingExpression && predicate).sqlExpression
} else {
query.havingExpression = predicate.sqlExpression
}
return QueryInterfaceRequest(query: query)
return QueryInterfaceRequest(query: query.having(predicate))
}
/// Creates a request with the provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// var request = Player.all()
/// request = request.order([Column("name")])
///
/// Any previous ordering is replaced:
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// request
/// .order([Column("email")])
/// .reversed()
/// .order([Column("name")])
public func order(_ orderings: [SQLOrderingTerm]) -> QueryInterfaceRequest<T> {
var query = self.query
query.ordering = QueryOrdering(orderings: orderings)
return QueryInterfaceRequest(query: query)
return QueryInterfaceRequest(query: query.order(orderings))
}
/// Creates a request sorted in reversed order.
/// Creates a request that reverses applied orderings.
///
/// // SELECT * FROM players ORDER BY name DESC
/// // SELECT * FROM player ORDER BY name DESC
/// var request = Player.all().order(Column("name"))
/// request = request.reversed()
///
/// If no ordering was applied, the returned request is identical.
///
/// // SELECT * FROM player
/// var request = Player.all()
/// request = request.reversed()
public func reversed() -> QueryInterfaceRequest<T> {
var query = self.query
query.ordering = query.ordering.reversed()
return QueryInterfaceRequest(query: query)
return QueryInterfaceRequest(query: query.reversed())
}
/// Creates a request which fetches *limit* rows, starting at *offset*.
///
/// // SELECT * FROM players LIMIT 1
/// // SELECT * FROM player LIMIT 1
/// var request = Player.all()
/// request = request.limit(1)
///
/// Any previous limit is replaced.
public func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest<T> {
var query = self.query
query.limit = SQLLimit(limit: limit, offset: offset)
return QueryInterfaceRequest(query: query)
return QueryInterfaceRequest(query: query.limit(limit, offset: offset))
}
/// Creates a request that allows you to define expressions that target
/// a specific database table.
///
/// In the example below, the "team.avgScore < player.score" condition in
/// the ON clause could be not achieved without table aliases.
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // SELECT player.*, team.*
/// // JOIN team ON ... AND team.avgScore < player.score
/// let playerAlias = TableAlias()
/// let request = Player
/// .all()
/// .aliased(playerAlias)
/// .including(required: Player.team.filter(Column("avgScore") < playerAlias[Column("score")])
public func aliased(_ alias: TableAlias) -> QueryInterfaceRequest {
return QueryInterfaceRequest(query: query.qualified(with: alias))
}
/// Creates a request bound to type Target.
///
/// The returned request can fetch if the type Target is fetchable (Row,
/// value, record).
///
/// // Int?
/// let maxScore = try Player
/// .select(max(scoreColumn))
/// .asRequest(of: Int.self) // <--
/// .fetchOne(db)
///
/// - parameter type: The fetched type Target
/// - returns: A typed request bound to type Target.
public func asRequest<Target>(of type: Target.Type) -> QueryInterfaceRequest<Target> {
return QueryInterfaceRequest<Target>(query: query)
}
}
extension QueryInterfaceRequest where T: TableRecord {
// MARK: Request Derivation
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM players WHERE id = 1
/// var request = Player.all()
/// request = request.filter(key: 1)
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func filter<PrimaryKeyType: DatabaseValueConvertible>(key: PrimaryKeyType?) -> QueryInterfaceRequest<T> {
guard let key = key else {
return T.none()
}
return filter(keys: [key])
}
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM players WHERE id IN (1, 2, 3)
/// var request = Player.all()
/// request = request.filter(keys: [1, 2, 3])
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func filter<Sequence: Swift.Sequence>(keys: Sequence) -> QueryInterfaceRequest<T> where Sequence.Element: DatabaseValueConvertible {
let keys = Array(keys)
let makePredicate: (Column) -> SQLExpression
switch keys.count {
case 0:
return T.none()
case 1:
makePredicate = { $0 == keys[0] }
default:
makePredicate = { keys.contains($0) }
}
return QueryInterfaceRequest(query: query.mapWhereExpression { (db, expression) in
let primaryKey = try db.primaryKey(T.databaseTableName)
GRDBPrecondition(primaryKey.columns.count == 1, "Requesting by key requires a single-column primary key in the table \(T.databaseTableName)")
let keysPredicate = makePredicate(Column(primaryKey.columns[0]))
if let expression = expression {
return expression && keysPredicate
} else {
return keysPredicate
}
})
}
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM passports WHERE personId = 1 AND countryCode = 'FR'
/// var request = Player.all()
/// request = request.filter(key: ["personId": 1, "countryCode": "FR"])
///
/// When executed, this request raises a fatal error if there is no unique
/// index on the key columns.
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func filter(key: [String: DatabaseValueConvertible?]?) -> QueryInterfaceRequest<T> {
guard let key = key else {
return T.none()
}
return filter(keys: [key])
}
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM passports WHERE (personId = 1 AND countryCode = 'FR') OR ...
/// let request = Passport.filter(keys: [["personId": 1, "countryCode": "FR"], ...])
///
/// When executed, this request raises a fatal error if there is no unique
/// index on the key columns.
///
/// The selection defaults to all columns. This default can be changed for
/// all requests by the `TableRecord.databaseSelection` property, or
/// for individual requests with the `TableRecord.select` method.
public func filter(keys: [[String: DatabaseValueConvertible?]]) -> QueryInterfaceRequest<T> {
guard !keys.isEmpty else {
return T.none()
}
return QueryInterfaceRequest(query: query.mapWhereExpression { (db, expression) in
let keyPredicates: [SQLExpression] = try keys.map { key in
// Prevent filter(keys: [["foo": 1, "bar": 2]]) where
// ("foo", "bar") is not a unique key (primary key or columns of a
// unique index)
guard let orderedColumns = try db.columnsForUniqueKey(key.keys, in: T.databaseTableName) else {
fatalError("table \(T.databaseTableName) has no unique index on column(s) \(key.keys.sorted().joined(separator: ", "))")
}
let lowercaseOrderedColumns = orderedColumns.map { $0.lowercased() }
let columnPredicates: [SQLExpression] = key
// Sort key columns in the same order as the unique index
.sorted { (kv1, kv2) in lowercaseOrderedColumns.index(of: kv1.0.lowercased())! < lowercaseOrderedColumns.index(of: kv2.0.lowercased())! }
.map { (column, value) in Column(column) == value }
return columnPredicates.joined(operator: .and)
}
let keysPredicate = keyPredicates.joined(operator: .or)
if let expression = expression {
return expression && keysPredicate
} else {
return keysPredicate
}
})
/// Conditional conformance to TableRequest when RowDecoder conforms
/// to TableRecord:
///
/// let request = Player.all()
/// request.filter(key: ...)
/// request.filter(keys: ...)
extension QueryInterfaceRequest: TableRequest where RowDecoder: TableRecord {
/// :nodoc:
public var databaseTableName: String {
return RowDecoder.databaseTableName
}
}
@@ -306,7 +214,7 @@ extension TableRecord {
/// Creates a request which fetches all records.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// let request = Player.all()
///
/// The selection defaults to all columns. This default can be changed for
@@ -314,19 +222,19 @@ extension TableRecord {
/// for individual requests with the `TableRecord.select` method.
public static func all() -> QueryInterfaceRequest<Self> {
let query = QueryInterfaceQuery(
select: databaseSelection,
from: .table(name: databaseTableName, alias: nil))
source: .table(tableName: databaseTableName, alias: nil),
selection: databaseSelection)
return QueryInterfaceRequest(query: query)
}
/// Creates a request which fetches no record.
public static func none() -> QueryInterfaceRequest<Self> {
return filter(false)
return all().none() // don't laugh
}
/// Creates a request which selects *selection*.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// let request = Player.select(Column("id"), Column("email"))
public static func select(_ selection: SQLSelectable...) -> QueryInterfaceRequest<Self> {
return all().select(selection)
@@ -334,7 +242,7 @@ extension TableRecord {
/// Creates a request which selects *selection*.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// let request = Player.select([Column("id"), Column("email")])
public static func select(_ selection: [SQLSelectable]) -> QueryInterfaceRequest<Self> {
return all().select(selection)
@@ -342,7 +250,7 @@ extension TableRecord {
/// Creates a request which selects *sql*.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// let request = Player.select(sql: "id, email")
public static func select(sql: String, arguments: StatementArguments? = nil) -> QueryInterfaceRequest<Self> {
return all().select(sql: sql, arguments: arguments)
@@ -350,7 +258,7 @@ extension TableRecord {
/// Creates a request with the provided *predicate*.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
/// let request = Player.filter(Column("email") == "arthur@example.com")
///
/// The selection defaults to all columns. This default can be changed for
@@ -362,7 +270,7 @@ extension TableRecord {
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM players WHERE id = 1
/// // SELECT * FROM player WHERE id = 1
/// let request = Player.filter(key: 1)
///
/// The selection defaults to all columns. This default can be changed for
@@ -374,7 +282,7 @@ extension TableRecord {
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM players WHERE id IN (1, 2, 3)
/// // SELECT * FROM player WHERE id IN (1, 2, 3)
/// let request = Player.filter(keys: [1, 2, 3])
///
/// The selection defaults to all columns. This default can be changed for
@@ -386,7 +294,7 @@ extension TableRecord {
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM passports WHERE personId = 1 AND countryCode = 'FR'
/// // SELECT * FROM passport WHERE personId = 1 AND countryCode = 'FR'
/// let request = Passport.filter(key: ["personId": 1, "countryCode": "FR"])
///
/// When executed, this request raises a fatal error if there is no unique
@@ -401,7 +309,7 @@ extension TableRecord {
/// Creates a request with the provided primary key *predicate*.
///
/// // SELECT * FROM passports WHERE (personId = 1 AND countryCode = 'FR') OR ...
/// // SELECT * FROM passport WHERE (personId = 1 AND countryCode = 'FR') OR ...
/// let request = Passport.filter(keys: [["personId": 1, "countryCode": "FR"], ...])
///
/// When executed, this request raises a fatal error if there is no unique
@@ -416,7 +324,7 @@ extension TableRecord {
/// Creates a request with the provided *predicate*.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
/// let request = Player.filter(sql: "email = ?", arguments: ["arthur@example.com"])
///
/// The selection defaults to all columns. This default can be changed for
@@ -429,7 +337,7 @@ extension TableRecord {
/// Creates a request sorted according to the
/// provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// let request = Player.order(Column("name"))
///
/// The selection defaults to all columns. This default can be changed for
@@ -442,7 +350,7 @@ extension TableRecord {
/// Creates a request sorted according to the
/// provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// let request = Player.order([Column("name")])
///
/// The selection defaults to all columns. This default can be changed for
@@ -454,7 +362,7 @@ extension TableRecord {
/// Creates a request sorted according to *sql*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// let request = Player.order(sql: "name")
///
/// The selection defaults to all columns. This default can be changed for
@@ -467,7 +375,7 @@ extension TableRecord {
/// Creates a request which fetches *limit* rows, starting at
/// *offset*.
///
/// // SELECT * FROM players LIMIT 1
/// // SELECT * FROM player LIMIT 1
/// let request = Player.limit(1)
///
/// The selection defaults to all columns. This default can be changed for
@@ -476,4 +384,24 @@ extension TableRecord {
public static func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest<Self> {
return all().limit(limit, offset: offset)
}
/// Creates a request that allows you to define expressions that target
/// a specific database table.
///
/// In the example below, the "team.avgScore < player.score" condition in
/// the ON clause could be not achieved without table aliases.
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // SELECT player.*, team.*
/// // JOIN team ON ... AND team.avgScore < player.score
/// let playerAlias = TableAlias()
/// let request = Player
/// .aliased(playerAlias)
/// .including(required: Player.team.filter(Column("avgScore") < playerAlias[Column("score")])
public static func aliased(_ alias: TableAlias) -> QueryInterfaceRequest<Self> {
return all().aliased(alias)
}
}
+148 -28
View File
@@ -4,13 +4,13 @@
public protocol SelectionRequest {
/// Creates a request with a new net of selected columns.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// var request = Player.all()
/// request = request.select([Column("id"), Column("email")])
///
/// Any previous selection is replaced:
///
/// // SELECT email FROM players
/// // SELECT email FROM player
/// request
/// .select([Column("id")])
/// .select([Column("email")])
@@ -20,13 +20,13 @@ public protocol SelectionRequest {
extension SelectionRequest {
/// Creates a request with a new net of selected columns.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// var request = Player.all()
/// request = request.select(Column("id"), Column("email"))
///
/// Any previous selection is replaced:
///
/// // SELECT email FROM players
/// // SELECT email FROM player
/// request
/// .select(Column("id"))
/// .select(Column("email"))
@@ -36,13 +36,13 @@ extension SelectionRequest {
/// Creates a request with a new net of selected columns.
///
/// // SELECT id, email FROM players
/// // SELECT id, email FROM player
/// var request = Player.all()
/// request = request.select(sql: "id, email")
///
/// Any previous selection is replaced:
///
/// // SELECT email FROM players
/// // SELECT email FROM player
/// request
/// .select(sql: "id")
/// .select(sql: "email")
@@ -55,32 +55,151 @@ extension SelectionRequest {
/// The protocol for all requests that can be filtered.
public protocol FilteredRequest {
/// Creates a request with the provided *predicate* added to the
/// Creates a request with the provided *predicate promise* added to the
/// eventual set of already applied predicates.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE 1
/// var request = Player.all()
/// request = request.filter(Column("email") == "arthur@example.com")
func filter(_ predicate: SQLExpressible) -> Self
/// Creates a request that matches nothing.
///
/// // SELECT * FROM players WHERE 0
/// var request = Player.all()
/// request = request.none()
func none() -> Self
/// request = request.filter { db in true }
func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> Self
}
extension FilteredRequest {
/// Creates a request with the provided *predicate* added to the
/// eventual set of already applied predicates.
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com'
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
/// var request = Player.all()
/// request = request.filter(Column("email") == "arthur@example.com")
public func filter(_ predicate: SQLExpressible) -> Self {
return filter { _ in predicate }
}
/// Creates a request with the provided *predicate* added to the
/// eventual set of already applied predicates.
///
/// // SELECT * FROM player WHERE email = 'arthur@example.com'
/// var request = Player.all()
/// request = request.filter(sql: "email = ?", arguments: ["arthur@example.com"])
public func filter(sql: String, arguments: StatementArguments? = nil) -> Self {
return filter(SQLExpressionLiteral(sql, arguments: arguments))
}
/// Creates a request that matches nothing.
///
/// // SELECT * FROM player WHERE 0
/// var request = Player.all()
/// request = request.none()
public func none() -> Self {
return filter(false)
}
}
// MARK: - TableRequest {
/// The protocol for all requests that feed from a database table
public protocol TableRequest {
/// The name of the database table
var databaseTableName: String { get }
/// Creates a request that allows you to define expressions that target
/// a specific database table.
///
/// In the example below, the "team.avgScore < player.score" condition in
/// the ON clause could be not achieved without table aliases.
///
/// struct Player: TableRecord {
/// static let team = belongsTo(Team.self)
/// }
///
/// // SELECT player.*, team.*
/// // JOIN team ON ... AND team.avgScore < player.score
/// let playerAlias = TableAlias()
/// let request = Player
/// .all()
/// .aliased(playerAlias)
/// .including(required: Player.team.filter(Column("avgScore") < playerAlias[Column("score")])
func aliased(_ alias: TableAlias) -> Self
}
extension TableRequest where Self: FilteredRequest {
/// Creates a request with the provided primary key *predicate*.
public func filter<PrimaryKeyType: DatabaseValueConvertible>(key: PrimaryKeyType?) -> Self {
guard let key = key else {
return none()
}
return filter(keys: [key])
}
/// Creates a request with the provided primary key *predicate*.
public func filter<Sequence: Swift.Sequence>(keys: Sequence) -> Self where Sequence.Element: DatabaseValueConvertible {
let keys = Array(keys)
let makePredicate: (Column) -> SQLExpression
switch keys.count {
case 0:
return none()
case 1:
makePredicate = { $0 == keys[0] }
default:
makePredicate = { keys.contains($0) }
}
let databaseTableName = self.databaseTableName
return filter { db in
let primaryKey = try db.primaryKey(databaseTableName)
GRDBPrecondition(
primaryKey.columns.count == 1,
"Requesting by key requires a single-column primary key in the table \(databaseTableName)")
return makePredicate(Column(primaryKey.columns[0]))
}
}
/// Creates a request with the provided primary key *predicate*.
///
/// When executed, this request raises a fatal error if there is no unique
/// index on the key columns.
public func filter(key: [String: DatabaseValueConvertible?]?) -> Self {
guard let key = key else {
return none()
}
return filter(keys: [key])
}
/// Creates a request with the provided primary key *predicate*.
///
/// When executed, this request raises a fatal error if there is no unique
/// index on the key columns.
public func filter(keys: [[String: DatabaseValueConvertible?]]) -> Self {
guard !keys.isEmpty else {
return none()
}
let databaseTableName = self.databaseTableName
return filter { db in
try keys
.map { key in
// Prevent filter(keys: [["foo": 1, "bar": 2]]) where
// ("foo", "bar") is not a unique key (primary key or columns of a
// unique index)
guard let orderedColumns = try db.columnsForUniqueKey(key.keys, in: databaseTableName) else {
fatalError("table \(databaseTableName) has no unique index on column(s) \(key.keys.sorted().joined(separator: ", "))")
}
let lowercaseOrderedColumns = orderedColumns.map { $0.lowercased() }
return key
// Sort key columns in the same order as the unique index
.sorted { (kv1, kv2) in
let index1 = lowercaseOrderedColumns.index(of: kv1.key.lowercased())!
let index2 = lowercaseOrderedColumns.index(of: kv2.key.lowercased())!
return index1 < index2
}
.map { (column, value) in Column(column) == value }
.joined(operator: .and)
}
.joined(operator: .or)
}
}
}
// MARK: - AggregatingRequest
@@ -129,27 +248,28 @@ extension AggregatingRequest {
public protocol OrderedRequest {
/// Creates a request with the provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// var request = Player.all()
/// request = request.order([Column("name")])
///
/// Any previous ordering is replaced:
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// request
/// .order([Column("email")])
/// .reversed()
/// .order([Column("name")])
func order(_ orderings: [SQLOrderingTerm]) -> Self
/// Creates a request that reverses applied orderings. If no ordering
/// was applied, the returned request is identical.
/// Creates a request that reverses applied orderings.
///
/// // SELECT * FROM players ORDER BY name DESC
/// // SELECT * FROM player ORDER BY name DESC
/// var request = Player.all().order(Column("name"))
/// request = request.reversed()
///
/// // SELECT * FROM players
/// If no ordering was applied, the returned request is identical.
///
/// // SELECT * FROM player
/// var request = Player.all()
/// request = request.reversed()
func reversed() -> Self
@@ -158,13 +278,13 @@ public protocol OrderedRequest {
extension OrderedRequest {
/// Creates a request with the provided *orderings*.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// var request = Player.all()
/// request = request.order(Column("name"))
///
/// Any previous ordering is replaced:
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// request
/// .order(Column("email"))
/// .reversed()
@@ -175,13 +295,13 @@ extension OrderedRequest {
/// Creates a request with the provided *sql* used for sorting.
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// var request = Player.all()
/// request = request.order(sql: "name")
///
/// Any previous ordering is replaced:
///
/// // SELECT * FROM players ORDER BY name
/// // SELECT * FROM player ORDER BY name
/// request
/// .order(sql: "email")
/// .order(sql: "name")
@@ -5,8 +5,8 @@
///
/// let email: SQLCollatedExpression = Column("email").collating(.nocase)
///
/// // SELECT * FROM players WHERE email = 'arthur@example.com' COLLATE NOCASE
/// Players.filter(email == "arthur@example.com")
/// // SELECT * FROM player WHERE email = 'arthur@example.com' COLLATE NOCASE
/// Player.filter(email == "arthur@example.com")
public struct SQLCollatedExpression {
/// The tainted expression
public let expression: SQLExpression
@@ -18,8 +18,8 @@ public struct SQLCollatedExpression {
///
/// let email: SQLCollatedExpression = Column("email").collating(.nocase)
///
/// // SELECT * FROM players ORDER BY email COLLATE NOCASE ASC
/// Players.order(email.asc)
/// // SELECT * FROM player ORDER BY email COLLATE NOCASE ASC
/// Player.order(email.asc)
///
/// See https://github.com/groue/GRDB.swift/#the-query-interface
public var asc: SQLOrderingTerm {
@@ -30,8 +30,8 @@ public struct SQLCollatedExpression {
///
/// let email: SQLCollatedExpression = Column("email").collating(.nocase)
///
/// // SELECT * FROM players ORDER BY email COLLATE NOCASE DESC
/// Players.order(email.desc)
/// // SELECT * FROM player ORDER BY email COLLATE NOCASE DESC
/// Player.order(email.desc)
///
/// See https://github.com/groue/GRDB.swift/#the-query-interface
public var desc: SQLOrderingTerm {
@@ -58,7 +58,13 @@ extension SQLCollatedExpression : SQLOrderingTerm {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func orderingTermSQL(_ arguments: inout StatementArguments?) -> String {
return sqlExpression.orderingTermSQL(&arguments)
public func orderingTermSQL(_ context: inout SQLGenerationContext) -> String {
return sqlExpression.orderingTermSQL(&context)
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedOrdering(with alias: TableAlias) -> SQLOrderingTerm {
return SQLCollatedExpression(expression.qualifiedExpression(with: alias), collationName: collationName)
}
}
+3 -18
View File
@@ -9,22 +9,7 @@ public protocol SQLCollection {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// Returns an SQL string that represents the collection.
///
/// When the arguments parameter is nil, any value must be written down as
/// a literal in the returned SQL:
///
/// var arguments: StatementArguments? = nil
/// let collection = SQLExpressionsArray([1,2,3])
/// collection.collectionSQL(&arguments) // "1,2,3"
///
/// When the arguments parameter is not nil, then values may be replaced by
/// `?` or colon-prefixed tokens, and fed into arguments.
///
/// var arguments = StatementArguments()
/// let collection = SQLExpressionsArray([1,2,3])
/// collection.collectionSQL(&arguments) // "?,?,?"
/// arguments // [1,2,3]
func collectionSQL(_ arguments: inout StatementArguments?) -> String
func collectionSQL(_ context: inout SQLGenerationContext) -> String
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
@@ -58,8 +43,8 @@ struct SQLExpressionsArray : SQLCollection {
self.expressions = expressions.map { $0.sqlExpression }
}
func collectionSQL(_ arguments: inout StatementArguments?) -> String {
return (expressions.map { $0.expressionSQL(&arguments) } as [String]).joined(separator: ", ")
func collectionSQL(_ context: inout SQLGenerationContext) -> String {
return (expressions.map { $0.expressionSQL(&context) } as [String]).joined(separator: ", ")
}
func contains(_ value: SQLExpressible) -> SQLExpression {
+6 -6
View File
@@ -64,8 +64,8 @@ extension SQLExpressible where Self: SQLOrderingTerm {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func orderingTermSQL(_ arguments: inout StatementArguments?) -> String {
return sqlExpression.expressionSQL(&arguments)
public func orderingTermSQL(_ context: inout SQLGenerationContext) -> String {
return sqlExpression.expressionSQL(&context)
}
}
@@ -75,14 +75,14 @@ extension SQLExpressible where Self: SQLSelectable {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func resultColumnSQL(_ arguments: inout StatementArguments?) -> String {
return sqlExpression.expressionSQL(&arguments)
public func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
return sqlExpression.expressionSQL(&context)
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func countedSQL(_ arguments: inout StatementArguments?) -> String {
return sqlExpression.expressionSQL(&arguments)
public func countedSQL(_ context: inout SQLGenerationContext) -> String {
return sqlExpression.expressionSQL(&context)
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
@@ -8,17 +8,17 @@ extension SQLExpression {
///
/// :nodoc:
public var literal: SQLExpressionLiteral {
var arguments: StatementArguments? = []
let sql = expressionSQL(&arguments)
return SQLExpressionLiteral(sql, arguments: arguments)
var context = SQLGenerationContext.literalGenerationContext(withArguments: true)
let sql = expressionSQL(&context)
return SQLExpressionLiteral(sql, arguments: context.arguments)
}
/// The expression as a quoted SQL literal (not public in order to avoid abuses)
///
/// "foo'bar".databaseValue.sql // "'foo''bar'""
var sql: String {
var arguments: StatementArguments? = nil
return expressionSQL(&arguments)
var context = SQLGenerationContext.literalGenerationContext(withArguments: false)
return expressionSQL(&context)
}
}
@@ -66,14 +66,13 @@ public struct SQLExpressionLiteral : SQLExpression {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
if let literalArguments = self.arguments {
guard arguments != nil else {
public func expressionSQL(_ context: inout SQLGenerationContext) -> String {
if let arguments = arguments {
if context.appendArguments(arguments) == false {
// GRDB limitation: we don't know how to look for `?` in sql and
// replace them with with literals.
fatalError("Not implemented")
}
arguments! += literalArguments
}
if unsafeRaw {
return sql
@@ -84,7 +83,13 @@ public struct SQLExpressionLiteral : SQLExpression {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return self
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return self
}
}
@@ -137,8 +142,6 @@ public struct SQLUnaryOperator : Hashable {
/// SQLExpressionUnary is an expression made of an unary operator and
/// an operand expression.
///
/// SQLExpressionUnary(.not, Column("favorite"))
///
/// :nodoc:
public struct SQLExpressionUnary : SQLExpression {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
@@ -165,14 +168,20 @@ public struct SQLExpressionUnary : SQLExpression {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
return op.sql + (op.needsRightSpace ? " " : "") + expression.expressionSQL(&arguments)
public func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return op.sql + (op.needsRightSpace ? " " : "") + expression.expressionSQL(&context)
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionUnary(op, expression.qualifiedExpression(with: qualifier))
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionUnary(op, expression.qualifiedExpression(with: alias))
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionUnary(op, expression.resolvedExpression(inContext: context))
}
}
@@ -268,8 +277,8 @@ public struct SQLExpressionBinary : SQLExpression {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
return "(" + lhs.expressionSQL(&arguments) + " " + op.sql + " " + rhs.expressionSQL(&arguments) + ")"
public func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return "(" + lhs.expressionSQL(&context) + " " + op.sql + " " + rhs.expressionSQL(&context) + ")"
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
@@ -281,11 +290,157 @@ public struct SQLExpressionBinary : SQLExpression {
return SQLExpressionNot(self)
}
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionBinary(op, lhs.qualifiedExpression(with: alias), rhs.qualifiedExpression(with: alias))
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
// FIXME: this implementation ignores column qualifiers
public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionBinary(op, lhs.resolvedExpression(inContext: context), rhs.resolvedExpression(inContext: context))
}
}
// MARK: - SQLExpressionAnd
struct SQLExpressionAnd : SQLExpression {
let expressions: [SQLExpression]
init(_ expressions: [SQLExpression]) {
self.expressions = expressions
}
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
guard let first = expressions.first else {
// Ruby [].all? # => true
return true.sqlExpression.expressionSQL(&context)
}
if expressions.count == 1 {
return first.expressionSQL(&context)
}
let expressionSQLs = expressions.map { $0.expressionSQL(&context) }
return "(" + expressionSQLs.joined(separator: " AND ") + ")"
}
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionAnd(expressions.map { $0.qualifiedExpression(with: alias) })
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionAnd(expressions.map { $0.resolvedExpression(inContext: context) })
}
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
let matchedRowIds = expressions.compactMap {
$0.matchedRowIds(rowIdName: rowIdName)
}
guard let first = matchedRowIds.first else {
return nil
}
return matchedRowIds.suffix(from: 1).reduce(into: first) { $0.formIntersection($1) }
}
}
// MARK: - SQLExpressionOr
struct SQLExpressionOr : SQLExpression {
let expressions: [SQLExpression]
init(_ expressions: [SQLExpression]) {
self.expressions = expressions
}
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
guard let first = expressions.first else {
// Ruby [].any? # => false
return false.sqlExpression.expressionSQL(&context)
}
if expressions.count == 1 {
return first.expressionSQL(&context)
}
let expressionSQLs = expressions.map { $0.expressionSQL(&context) }
return "(" + expressionSQLs.joined(separator: " OR ") + ")"
}
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionOr(expressions.map { $0.qualifiedExpression(with: alias) })
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionOr(expressions.map { $0.resolvedExpression(inContext: context) })
}
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
if expressions.isEmpty {
return []
}
var result: Set<Int64> = []
for expr in expressions {
guard let matchedRowIds = expr.matchedRowIds(rowIdName: rowIdName) else {
return nil
}
result.formUnion(matchedRowIds)
}
return result
}
}
// MARK: - SQLExpressionEqual
struct SQLExpressionEqual: SQLExpression {
var lhs: SQLExpression
var rhs: SQLExpression
var op: Operator
init(_ op: Operator, _ lhs: SQLExpression, _ rhs: SQLExpression) {
self.lhs = lhs
self.rhs = rhs
self.op = op
}
enum Operator: String {
case equal = "="
case notEqual = "<>"
case `is` = "IS"
case isNot = "IS NOT"
var negated: Operator {
switch self {
case .equal: return .notEqual
case .notEqual: return .equal
case .is: return .isNot
case .isNot: return .is
}
}
}
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return "(" +
lhs.expressionSQL(&context) +
" " +
op.rawValue +
" " +
rhs.expressionSQL(&context) +
")"
}
var negated: SQLExpression {
return SQLExpressionEqual(op.negated, lhs, rhs)
}
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionEqual(op, lhs.qualifiedExpression(with: alias), rhs.qualifiedExpression(with: alias))
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionEqual(op, lhs.resolvedExpression(inContext: context), rhs.resolvedExpression(inContext: context))
}
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
// FIXME: this implementation ignores column aliases
switch op {
case .equal, .is:
// Look for `id ==/IS 1`, `rowid ==/IS 1`, `1 ==/IS id`, `1 ==/IS rowid`
@@ -312,92 +467,10 @@ public struct SQLExpressionBinary : SQLExpression {
return nil
}
default:
case .notEqual, .isNot:
return nil
}
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionBinary(op, lhs.qualifiedExpression(with: qualifier), rhs.qualifiedExpression(with: qualifier))
}
}
// MARK: - SQLExpressionAnd
struct SQLExpressionAnd : SQLExpression {
let expressions: [SQLExpression]
init(_ expressions: [SQLExpression]) {
self.expressions = expressions
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
guard let expression = expressions.first else {
// Ruby [].all? # => true
return true.sqlExpression.expressionSQL(&arguments)
}
if expressions.count == 1 {
return expression.expressionSQL(&arguments)
}
let expressionSQLs = expressions.map { $0.expressionSQL(&arguments) }
return "(" + expressionSQLs.joined(separator: " AND ") + ")"
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionAnd(expressions.map { $0.qualifiedExpression(with: qualifier) })
}
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
let matchedRowIds = expressions.compactMap {
$0.matchedRowIds(rowIdName: rowIdName)
}
guard let first = matchedRowIds.first else {
return nil
}
return matchedRowIds.suffix(from: 1).reduce(into: first) { $0.formIntersection($1) }
}
}
// MARK: - SQLExpressionOr
struct SQLExpressionOr : SQLExpression {
let expressions: [SQLExpression]
init(_ expressions: [SQLExpression]) {
self.expressions = expressions
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
guard let expression = expressions.first else {
// Ruby [].any? # => false
return false.sqlExpression.expressionSQL(&arguments)
}
if expressions.count == 1 {
return expression.expressionSQL(&arguments)
}
let expressionSQLs = expressions.map { $0.expressionSQL(&arguments) }
return "(" + expressionSQLs.joined(separator: " OR ") + ")"
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionOr(expressions.map { $0.qualifiedExpression(with: qualifier) })
}
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
if expressions.isEmpty {
return []
}
var result: Set<Int64> = []
for expr in expressions {
guard let matchedRowIds = expr.matchedRowIds(rowIdName: rowIdName) else {
return nil
}
result.formUnion(matchedRowIds)
}
return result
}
}
// MARK: - SQLExpressionContains
@@ -418,11 +491,11 @@ struct SQLExpressionContains : SQLExpression {
self.isNegated = negated
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return "(" +
expression.expressionSQL(&arguments) +
expression.expressionSQL(&context) +
(isNegated ? " NOT IN (" : " IN (") +
collection.collectionSQL(&arguments) +
collection.collectionSQL(&context) +
"))"
}
@@ -430,9 +503,16 @@ struct SQLExpressionContains : SQLExpression {
return SQLExpressionContains(expression, collection, negated: !isNegated)
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionContains(expression.qualifiedExpression(with: alias), collection, negated: isNegated)
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionContains(expression.resolvedExpression(inContext: context), collection, negated: isNegated)
}
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
// FIXME: this implementation ignores column qualifiers
// FIXME: this implementation ignores column aliases
// Look for `id IN (1, 2, 3)`
guard let column = expression as? ColumnExpression,
let array = collection as? SQLExpressionsArray else
@@ -444,7 +524,7 @@ struct SQLExpressionContains : SQLExpression {
if let rowIdName = rowIdName {
rowIdNames.append(rowIdName.lowercased())
}
guard rowIdNames.contains(column.name.lowercased()) else {
return nil
}
@@ -458,10 +538,6 @@ struct SQLExpressionContains : SQLExpression {
}
return rowIDs
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionContains(expression.qualifiedExpression(with: qualifier), collection, negated: isNegated)
}
}
// MARK: - SQLExpressionBetween
@@ -484,13 +560,13 @@ struct SQLExpressionBetween : SQLExpression {
self.isNegated = negated
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return "(" +
expression.expressionSQL(&arguments) +
expression.expressionSQL(&context) +
(isNegated ? " NOT BETWEEN " : " BETWEEN ") +
lowerBound.expressionSQL(&arguments) +
lowerBound.expressionSQL(&context) +
" AND " +
upperBound.expressionSQL(&arguments) +
upperBound.expressionSQL(&context) +
")"
}
@@ -498,11 +574,19 @@ struct SQLExpressionBetween : SQLExpression {
return SQLExpressionBetween(expression, lowerBound, upperBound, negated: !isNegated)
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionBetween(
expression.qualifiedExpression(with: qualifier),
lowerBound.qualifiedExpression(with: qualifier),
upperBound.qualifiedExpression(with: qualifier),
expression.qualifiedExpression(with: alias),
lowerBound.qualifiedExpression(with: alias),
upperBound.qualifiedExpression(with: alias),
negated: isNegated)
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionBetween(
expression.resolvedExpression(inContext: context),
lowerBound.resolvedExpression(inContext: context),
upperBound.resolvedExpression(inContext: context),
negated: isNegated)
}
}
@@ -518,7 +602,7 @@ public struct SQLFunctionName : Hashable {
/// The SQL function name
///
/// :nodoc:
public let sql: String
public var sql: String
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
@@ -530,22 +614,6 @@ public struct SQLFunctionName : Hashable {
public init(_ sql: String) {
self.sql = sql
}
#if !swift(>=4.1)
/// The hash value
///
/// :nodoc:
public var hashValue: Int {
return sql.hashValue
}
/// Equality operator
///
/// :nodoc:
public static func == (lhs: SQLFunctionName, rhs: SQLFunctionName) -> Bool {
return lhs.sql == rhs.sql
}
#endif
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
@@ -590,14 +658,20 @@ public struct SQLExpressionFunction : SQLExpression {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func expressionSQL(_ arguments: inout StatementArguments?) -> String {
return functionName.sql + "(" + (self.arguments.map { $0.expressionSQL(&arguments) } as [String]).joined(separator: ", ") + ")"
public func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return functionName.sql + "(" + (self.arguments.map { $0.expressionSQL(&context) } as [String]).joined(separator: ", ") + ")"
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionFunction(functionName, arguments: arguments.map { $0.qualifiedExpression(with: qualifier) })
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionFunction(functionName, arguments: arguments.map { $0.qualifiedExpression(with: alias) })
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionFunction(functionName, arguments: arguments.map { $0.resolvedExpression(inContext: context) })
}
}
@@ -615,12 +689,16 @@ struct SQLExpressionCount : SQLExpression {
self.counted = counted
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
return "COUNT(" + counted.countedSQL(&arguments) + ")"
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return "COUNT(" + counted.countedSQL(&context) + ")"
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionCount(counted.qualifiedSelectable(with: qualifier))
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionCount(counted.qualifiedSelectable(with: alias))
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return self
}
}
@@ -637,12 +715,39 @@ struct SQLExpressionCountDistinct : SQLExpression {
self.counted = counted
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
return "COUNT(DISTINCT " + counted.expressionSQL(&arguments) + ")"
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return "COUNT(DISTINCT " + counted.expressionSQL(&context) + ")"
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionCountDistinct(counted.qualifiedExpression(with: qualifier))
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionCountDistinct(counted.qualifiedExpression(with: alias))
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return self
}
}
// MARK: - TableMatchExpression
struct TableMatchExpression: SQLExpression {
var alias: TableAlias
var pattern: SQLExpression
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return "(" + context.resolvedName(for: alias).quotedDatabaseIdentifier + " MATCH " + pattern.expressionSQL(&context) + ")"
}
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return TableMatchExpression(
alias: self.alias,
pattern: pattern.qualifiedExpression(with: alias))
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return TableMatchExpression(
alias: alias,
pattern: pattern.resolvedExpression(inContext: context))
}
}
@@ -661,8 +766,8 @@ struct SQLExpressionCollate : SQLExpression {
self.collationName = collationName
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
let sql = expression.expressionSQL(&arguments)
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
let sql = expression.expressionSQL(&context)
if sql.last! == ")" {
return String(sql.prefix(upTo: sql.index(sql.endIndex, offsetBy: -1))) + " COLLATE " + collationName.rawValue + ")"
} else {
@@ -670,7 +775,11 @@ struct SQLExpressionCollate : SQLExpression {
}
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionCollate(expression.qualifiedExpression(with: qualifier), collationName: collationName)
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionCollate(expression.qualifiedExpression(with: alias), collationName: collationName)
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionCollate(expression.resolvedExpression(inContext: context), collationName: collationName)
}
}
+25 -24
View File
@@ -23,22 +23,7 @@ public protocol SQLExpression : SQLSpecificExpressible, SQLSelectable, SQLOrderi
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// Returns an SQL string that represents the expression.
///
/// When the arguments parameter is nil, any value must be written down as
/// a literal in the returned SQL:
///
/// var arguments: StatementArguments? = nil
/// let expression = "foo'bar".databaseValue
/// expression.expressionSQL(&arguments) // "'foo''bar'"
///
/// When the arguments parameter is not nil, then values may be replaced by
/// `?` or colon-prefixed tokens, and fed into arguments.
///
/// var arguments = StatementArguments()
/// let expression = "foo'bar".databaseValue
/// expression.expressionSQL(&arguments) // "?"
/// arguments // ["foo'bar"]
func expressionSQL(_ arguments: inout StatementArguments?) -> String
func expressionSQL(_ context: inout SQLGenerationContext) -> String
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
@@ -59,10 +44,13 @@ public protocol SQLExpression : SQLSpecificExpressible, SQLSelectable, SQLOrderi
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// Returns the rowIds matched by the expression.
func matchedRowIds(rowIdName: String?) -> Set<Int64>? // TODO: this method should take SQLTableQualifier in account
func matchedRowIds(rowIdName: String?) -> Set<Int64>? // FIXME: this method should take TableAlias in account
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression
func qualifiedExpression(with alias: TableAlias) -> SQLExpression
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression
}
extension SQLExpression {
@@ -93,8 +81,17 @@ extension SQLExpression {
/// The default implementation returns qualifiedExpression(with:)
///
/// :nodoc:
public func qualifiedSelectable(with qualifier: SQLTableQualifier) -> SQLSelectable {
return qualifiedExpression(with: qualifier)
public func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
return qualifiedExpression(with: alias)
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// The default implementation returns qualifiedExpression(with:)
///
/// :nodoc:
public func qualifiedOrdering(with alias: TableAlias) -> SQLOrderingTerm {
return qualifiedExpression(with: alias)
}
}
@@ -139,15 +136,19 @@ struct SQLExpressionNot : SQLExpression {
self.expression = expression
}
func expressionSQL(_ arguments: inout StatementArguments?) -> String {
return "NOT \(expression.expressionSQL(&arguments))"
func expressionSQL(_ context: inout SQLGenerationContext) -> String {
return "NOT \(expression.expressionSQL(&context))"
}
var negated: SQLExpression {
return expression
}
func qualifiedExpression(with qualifier: SQLTableQualifier) -> SQLExpression {
return SQLExpressionNot(expression.qualifiedExpression(with: qualifier))
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
return SQLExpressionNot(expression.qualifiedExpression(with: alias))
}
func resolvedExpression(inContext context: [TableAlias: PersistenceContainer]) -> SQLExpression {
return SQLExpressionNot(expression.resolvedExpression(inContext: context))
}
}
@@ -0,0 +1,265 @@
/// SQLGenerationContext is responsible for preventing SQL injection and
/// disambiguating table names when GRDB generates SQL queries.
public struct SQLGenerationContext {
private(set) var arguments: StatementArguments?
private var resolvedNames: [TableAlias: String]
private var qualifierNeeded: Bool
/// Used for SQLExpression -> SQLExpressionLiteral conversion
static func literalGenerationContext(withArguments: Bool) -> SQLGenerationContext {
return SQLGenerationContext(
arguments: withArguments ? [] : nil,
resolvedNames: [:],
qualifierNeeded: false)
}
/// Used for QueryInterfaceQuery.makeSelectStatement() and QueryInterfaceQuery.makeDeleteStatement()
static func queryGenerationContext(aliases: [TableAlias]) -> SQLGenerationContext {
return SQLGenerationContext(
arguments: [],
resolvedNames: aliases.resolvedNames,
qualifierNeeded: aliases.count > 1)
}
/// Used for TableRecord.selectionSQL
static func recordSelectionGenerationContext(alias: TableAlias) -> SQLGenerationContext {
return SQLGenerationContext(
arguments: nil,
resolvedNames: [:],
qualifierNeeded: true)
}
/// Returns whether arguments could be appended
mutating func appendArguments(_ newArguments: StatementArguments) -> Bool {
guard let arguments = arguments else {
return false
}
self.arguments = arguments + newArguments
return true
}
/// May be nil, when a qualifier is not needed:
///
/// WHERE <qualifier>.column == 1
/// SELECT <qualifier>.*
///
/// WHERE column == 1
/// SELECT *
func qualifier(for alias: TableAlias) -> String? {
if alias.hasUserName {
return alias.identityName
}
if qualifierNeeded == false {
return nil
}
return resolvedName(for: alias)
}
/// WHERE <resolvedName> MATCH pattern
func resolvedName(for alias: TableAlias) -> String {
return resolvedNames[alias.root] ?? alias.identityName
}
/// FROM tableName <alias>
func aliasName(for alias: TableAlias) -> String? {
let resolvedName = self.resolvedName(for: alias)
if resolvedName != alias.tableName {
return resolvedName
}
return nil
}
}
// MARK: - TableAlias
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
public class TableAlias: Hashable {
private enum Impl {
/// A TableAlias is undefined when it is created by the GRDB user:
///
/// let alias = TableAlias()
/// let alias = TableAlias(name: "player")
case undefined(userName: String?)
/// A TableAlias is a table when explicitly specified:
///
/// let alias = TableAlias(tableName: "player")
///
/// Or when it has been qualified by a request:
///
/// let alias = TableAlias()
/// let request = Player.all().aliased(alias)
case table(tableName: String, userName: String?)
case derived(TableAlias)
}
private var impl: Impl
// exposed for SQLGenerationContext and expression.resolvedExpression
var root: TableAlias {
if case .derived(let base) = impl {
return base.root
} else {
return self
}
}
// exposed to SQLGenerationContext
fileprivate var identityName: String {
return userName ?? tableName
}
// exposed to SQLGenerationContext
fileprivate var hasUserName: Bool {
return userName != nil
}
var tableName: String {
switch impl {
case .undefined:
fatalError("Undefined alias has no table name")
case .table(tableName: let tableName, userName: _):
return tableName
case .derived(let base):
return base.tableName
}
}
private var userName: String? {
switch impl {
case .undefined(let userName):
return userName
case .table(tableName: _, userName: let userName):
return userName
case .derived(let base):
return base.userName
}
}
public init(name: String? = nil) {
self.impl = .undefined(userName: name)
}
init(tableName: String, userName: String? = nil) {
self.impl = .table(tableName: tableName, userName: userName)
}
func rebase(on base: TableAlias) {
switch impl {
case .undefined(let userName):
if let userName = userName {
// rename
base.setUserName(userName)
}
self.impl = .derived(base)
default:
fatalError("Not implemented")
}
}
func setUserName(_ userName: String) {
switch impl {
case .undefined:
self.impl = .undefined(userName: userName)
case .table(tableName: let tableName, userName: _):
self.impl = .table(tableName: tableName, userName: userName)
case .derived(let base):
base.setUserName(userName)
}
}
func setTableName(_ tableName: String) {
switch impl {
case .undefined(let userName):
self.impl = .table(tableName: tableName, userName: userName)
case .table(tableName: let initialTableName, userName: _):
GRDBPrecondition(tableName.lowercased() == initialTableName.lowercased(), "Can't change table name of a table alias")
case .derived(let base):
base.setTableName(tableName)
}
}
/// Returns a qualified value that is able to resolve ambiguities in
/// joined queries.
public subscript(_ selectable: SQLSelectable) -> SQLSelectable {
return selectable.qualifiedSelectable(with: self)
}
/// Returns a qualified expression that is able to resolve ambiguities in
/// joined queries.
public subscript(_ expression: SQLExpression) -> SQLExpression {
return expression.qualifiedExpression(with: self)
}
/// :nodoc:
public var hashValue: Int {
if case .derived(let base) = impl {
return base.hashValue
} else {
return ObjectIdentifier(self).hashValue
}
}
/// :nodoc:
public static func == (lhs: TableAlias, rhs: TableAlias) -> Bool {
return ObjectIdentifier(lhs.root) == ObjectIdentifier(rhs.root)
}
}
extension Array where Element == TableAlias {
/// Resolve ambiguities in aliases' names.
fileprivate var resolvedNames: [TableAlias: String] {
let aliases = map { $0.root }
// It is a programmer error to reuse the same (===) TableAlias for
// multiple tables.
GRDBPrecondition(aliases.count == Set(aliases).count, "A TableAlias most not be used to refer to multiple tables")
let groups = Dictionary.init(grouping: aliases) {
$0.identityName.lowercased()
}
var uniqueLowercaseNames: Set<String> = []
var ambiguousGroups: [[TableAlias]] = []
for (lowercaseName, group) in groups {
if group.count > 1 {
// It is a programmer error to reuse the same alias for multiple tables
GRDBPrecondition(group.filter({ $0.hasUserName }).count < 2, "ambiguous alias: \(group[0].identityName)")
ambiguousGroups.append(group)
} else {
uniqueLowercaseNames.insert(lowercaseName)
}
}
var resolvedNames: [TableAlias: String] = [:]
for group in ambiguousGroups {
var index = 1
for alias in group {
if alias.hasUserName { continue }
let radical = alias.identityName.databaseQualifierRadical
var resolvedName: String
repeat {
resolvedName = "\(radical)\(index)"
index += 1
} while uniqueLowercaseNames.contains(resolvedName.lowercased())
uniqueLowercaseNames.insert(resolvedName.lowercased())
resolvedNames[alias] = resolvedName
}
}
return resolvedNames
}
}
extension String {
/// "bar" => "bar"
/// "foo12" => "foo"
var databaseQualifierRadical: String {
let digits: ClosedRange<Character> = "0"..."9"
let radicalEndIndex = self // "foo12"
.reversed() // "21oof"
.prefix(while: { digits.contains($0) }) // "21"
.endIndex // reversed(foo^12)
.base // foo^12
return String(prefix(upTo: radicalEndIndex))
}
}
+16 -19
View File
@@ -15,22 +15,10 @@ public protocol SQLOrderingTerm {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// Returns an SQL string that represents the ordering term.
///
/// When the arguments parameter is nil, any value must be written down as
/// a literal in the returned SQL:
///
/// var arguments: StatementArguments? = nil
/// let orderingTerm = Column("name") ?? "Anonymous"
/// orderingTerm.orderingTermSQL(&arguments) // "IFNULL(name, 'Anonymous')"
///
/// When the arguments parameter is not nil, then values may be replaced by
/// `?` or colon-prefixed tokens, and fed into arguments.
///
/// var arguments = StatementArguments()
/// let orderingTerm = Column("name") ?? "Anonymous"
/// orderingTerm.orderingTermSQL(&arguments) // "IFNULL(name, ?)"
/// arguments // ["Anonymous"]
func orderingTermSQL(_ arguments: inout StatementArguments?) -> String
func orderingTermSQL(_ context: inout SQLGenerationContext) -> String
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
func qualifiedOrdering(with alias: TableAlias) -> SQLOrderingTerm
}
// MARK: - SQLOrdering
@@ -48,12 +36,21 @@ enum SQLOrdering : SQLOrderingTerm {
}
}
func orderingTermSQL(_ arguments: inout StatementArguments?) -> String {
func orderingTermSQL(_ context: inout SQLGenerationContext) -> String {
switch self {
case .asc(let expression):
return expression.expressionSQL(&arguments) + " ASC"
return expression.expressionSQL(&context) + " ASC"
case .desc(let expression):
return expression.expressionSQL(&arguments) + " DESC"
return expression.expressionSQL(&context) + " DESC"
}
}
func qualifiedOrdering(with alias: TableAlias) -> SQLOrderingTerm {
switch self {
case .asc(let expression):
return SQLOrdering.asc(expression.qualifiedExpression(with: alias))
case .desc(let expression):
return SQLOrdering.desc(expression.qualifiedExpression(with: alias))
}
}
}
@@ -8,11 +8,11 @@
/// For example:
///
/// struct Player : TableRecord {
/// static var databaseTableName = "players"
/// static var databaseTableName = "player"
/// static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
/// }
///
/// // SELECT *, rowid FROM players
/// // SELECT *, rowid FROM player
/// let request = Player.all()
public struct AllColumns {
public init() { }
@@ -21,13 +21,13 @@ public struct AllColumns {
extension AllColumns : SQLSelectable {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func resultColumnSQL(_ arguments: inout StatementArguments?) -> String {
public func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
return "*"
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func countedSQL(_ arguments: inout StatementArguments?) -> String {
public func countedSQL(_ context: inout SQLGenerationContext) -> String {
return "*"
}
@@ -47,14 +47,14 @@ extension AllColumns : SQLSelectable {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func qualifiedSelectable(with qualifier: SQLTableQualifier) -> SQLSelectable {
return QualifiedAllColumns(qualifier: qualifier)
public func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
return QualifiedAllColumns(alias: alias)
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
/// :nodoc:
public func columnCount(_ db: Database) throws -> Int {
fatalError("Can't compute number of columns without a qualifier")
fatalError("Can't compute number of columns without an alias")
}
}
@@ -62,37 +62,40 @@ extension AllColumns : SQLSelectable {
/// QualifiedAllColumns is the `t.*` in `SELECT t.*`.
struct QualifiedAllColumns {
private let qualifier: SQLTableQualifier
private let alias: TableAlias
init(qualifier: SQLTableQualifier) {
self.qualifier = qualifier
init(alias: TableAlias) {
self.alias = alias
}
}
extension QualifiedAllColumns : SQLSelectable {
func resultColumnSQL(_ arguments: inout StatementArguments?) -> String {
if let qualifierName = qualifier.name {
return qualifierName.quotedDatabaseIdentifier + ".*"
func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
if let qualifier = context.qualifier(for: alias) {
return qualifier.quotedDatabaseIdentifier + ".*"
}
return "*"
}
func countedSQL(_ arguments: inout StatementArguments?) -> String {
// SELECT COUNT(t.*) is invalid SQL
fatalError("Not implemented, or invalid query")
func countedSQL(_ context: inout SQLGenerationContext) -> String {
if context.qualifier(for: alias) != nil {
// SELECT COUNT(t.*) is invalid SQL
fatalError("Not implemented, or invalid query")
}
return "*"
}
func count(distinct: Bool) -> SQLCount? {
return nil
}
func qualifiedSelectable(with qualifier: SQLTableQualifier) -> SQLSelectable {
func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
// Never requalify
return self
}
func columnCount(_ db: Database) throws -> Int {
return try db.columns(in: qualifier.tableName).count
return try db.columns(in: alias.tableName).count
}
}
@@ -100,27 +103,27 @@ extension QualifiedAllColumns : SQLSelectable {
struct SQLAliasedExpression : SQLSelectable {
let expression: SQLExpression
let alias: String
let name: String
init(_ expression: SQLExpression, alias: String) {
init(_ expression: SQLExpression, name: String) {
self.expression = expression
self.alias = alias
self.name = name
}
func resultColumnSQL(_ arguments: inout StatementArguments?) -> String {
return expression.resultColumnSQL(&arguments) + " AS " + alias.quotedDatabaseIdentifier
func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
return expression.resultColumnSQL(&context) + " AS " + name.quotedDatabaseIdentifier
}
func countedSQL(_ arguments: inout StatementArguments?) -> String {
return expression.countedSQL(&arguments)
func countedSQL(_ context: inout SQLGenerationContext) -> String {
return expression.countedSQL(&context)
}
func count(distinct: Bool) -> SQLCount? {
return expression.count(distinct: distinct)
}
func qualifiedSelectable(with qualifier: SQLTableQualifier) -> SQLSelectable {
return SQLAliasedExpression(expression.qualifiedExpression(with: qualifier), alias: alias)
func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
return SQLAliasedExpression(expression.qualifiedExpression(with: alias), name: name)
}
func columnCount(_ db: Database) throws -> Int {
+8 -28
View File
@@ -8,10 +8,10 @@
/// :nodoc:
public protocol SQLSelectable {
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
func resultColumnSQL(_ arguments: inout StatementArguments?) -> String
func resultColumnSQL(_ context: inout SQLGenerationContext) -> String
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
func countedSQL(_ arguments: inout StatementArguments?) -> String
func countedSQL(_ context: inout SQLGenerationContext) -> String
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
func count(distinct: Bool) -> SQLCount?
@@ -20,7 +20,7 @@ public protocol SQLSelectable {
func columnCount(_ db: Database) throws -> Int
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
func qualifiedSelectable(with qualifier: SQLTableQualifier) -> SQLSelectable
func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable
}
// MARK: - SQLSelectionLiteral
@@ -34,19 +34,18 @@ struct SQLSelectionLiteral : SQLSelectable {
self.arguments = arguments
}
func resultColumnSQL(_ arguments: inout StatementArguments?) -> String {
if let literalArguments = self.arguments {
guard arguments != nil else {
func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
if let arguments = arguments {
if context.appendArguments(arguments) == false {
// GRDB limitation: we don't know how to look for `?` in sql and
// replace them with with literals.
fatalError("Not implemented")
}
arguments! += literalArguments
}
return sql
}
func countedSQL(_ arguments: inout StatementArguments?) -> String {
func countedSQL(_ context: inout SQLGenerationContext) -> String {
fatalError("Selection literals can't be counted. To resolve this error, select one or several SQLExpressionLiteral instead.")
}
@@ -58,30 +57,11 @@ struct SQLSelectionLiteral : SQLSelectable {
fatalError("Selection literals don't known how many columns they contain. To resolve this error, select one or several SQLExpressionLiteral instead.")
}
func qualifiedSelectable(with qualifier: SQLTableQualifier) -> SQLSelectable {
func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
return self
}
}
// MARK: - SQLTableQualifier
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
/// :nodoc:
public class SQLTableQualifier {
var tableName: String
private var alias: String?
init(tableName: String, alias: String?) {
self.tableName = tableName
self.alias = alias
}
var name: String? {
return alias
}
}
// MARK: - Counting
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
@@ -25,8 +25,8 @@ extension SQLSpecificExpressible {
/// Returns a value that can be used as an argument to QueryInterfaceRequest.select()
///
/// See https://github.com/groue/GRDB.swift/#the-query-interface
public func aliased(_ alias: String) -> SQLSelectable {
return SQLAliasedExpression(sqlExpression, alias: alias)
public func aliased(_ name: String) -> SQLSelectable {
return SQLAliasedExpression(sqlExpression, name: name)
}
}
+16 -30
View File
@@ -1,38 +1,24 @@
// MARK: - Egality and Identity Operators (=, <>, IS, IS NOT)
extension SQLBinaryOperator {
/// The `=` binary operator
static let equal = SQLBinaryOperator("=", negated: "<>")
/// The `<>` binary operator
static let notEqual = SQLBinaryOperator("<>", negated: "=")
/// The `IS` binary operator
static let `is` = SQLBinaryOperator("IS", negated: "IS NOT")
/// The `IS NOT` binary operator
static let isNot = SQLBinaryOperator("IS NOT", negated: "IS")
}
// Outputs "x = y" or "x IS NULL"
private func isEqual(_ lhs: SQLExpression, _ rhs: SQLExpression) -> SQLExpression {
switch (lhs, rhs) {
case (let lhs, let rhs as DatabaseValue):
switch rhs.storage {
case .null:
return SQLExpressionBinary(.is, lhs, DatabaseValue.null)
return SQLExpressionEqual(.is, lhs, rhs)
default:
return SQLExpressionBinary(.equal, lhs, rhs)
return SQLExpressionEqual(.equal, lhs, rhs)
}
case (let lhs as DatabaseValue, let rhs):
switch lhs.storage {
case .null:
return SQLExpressionBinary(.is, rhs, DatabaseValue.null)
return SQLExpressionEqual(.is, rhs, lhs)
default:
return SQLExpressionBinary(.equal, lhs, rhs)
return SQLExpressionEqual(.equal, lhs, rhs)
}
default:
return SQLExpressionBinary(.equal, lhs, rhs)
return SQLExpressionEqual(.equal, lhs, rhs)
}
}
@@ -229,7 +215,7 @@ public func != (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQL
/// // name IS 'Arthur'
/// Column("name") === "Arthur"
public func === (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpression {
return SQLExpressionBinary(.is, lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
return SQLExpressionEqual(.is, lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
}
/// An SQL expression that compares two expressions with the `IS` SQL operator.
@@ -246,9 +232,9 @@ public func === (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpress
/// "Arthur" === Column("name")
public func === (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpression {
if let lhs = lhs {
return SQLExpressionBinary(.is, lhs.sqlExpression, rhs.sqlExpression)
return SQLExpressionEqual(.is, lhs.sqlExpression, rhs.sqlExpression)
} else {
return SQLExpressionBinary(.is, rhs.sqlExpression, DatabaseValue.null)
return SQLExpressionEqual(.is, rhs.sqlExpression, DatabaseValue.null)
}
}
@@ -265,7 +251,7 @@ public func === (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpress
/// // email IS login
/// Column("email") === Column("login")
public func === (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
return SQLExpressionBinary(.is, lhs.sqlExpression, rhs.sqlExpression)
return SQLExpressionEqual(.is, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
@@ -273,7 +259,7 @@ public func === (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQ
/// // name IS NOT 'Arthur'
/// Column("name") !== "Arthur"
public func !== (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpression {
return SQLExpressionBinary(.isNot, lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
return SQLExpressionEqual(.isNot, lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
}
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
@@ -290,9 +276,9 @@ public func !== (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpress
/// "Arthur" !== Column("name")
public func !== (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpression {
if let lhs = lhs {
return SQLExpressionBinary(.isNot, lhs.sqlExpression, rhs.sqlExpression)
return SQLExpressionEqual(.isNot, lhs.sqlExpression, rhs.sqlExpression)
} else {
return SQLExpressionBinary(.isNot, rhs.sqlExpression, DatabaseValue.null)
return SQLExpressionEqual(.isNot, rhs.sqlExpression, DatabaseValue.null)
}
}
@@ -309,7 +295,7 @@ public func !== (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpress
/// // email IS NOT login
/// Column("email") !== Column("login")
public func !== (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
return SQLExpressionBinary(.isNot, lhs.sqlExpression, rhs.sqlExpression)
return SQLExpressionEqual(.isNot, lhs.sqlExpression, rhs.sqlExpression)
}
@@ -768,7 +754,7 @@ extension Sequence where Element == SQLExpression {
///
/// For example:
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// // WHERE (registered
/// // AND (score >= 1000)
/// // AND (name IS NOT NULL))
@@ -781,10 +767,10 @@ extension Sequence where Element == SQLExpression {
/// When the sequence is empty, `joined(operator: .and)` returns true,
/// and `joined(operator: .or)` returns false:
///
/// // SELECT * FROM players WHERE 1
/// // SELECT * FROM player WHERE 1
/// Player.filter([].joined(operator: .and))
///
/// // SELECT * FROM players WHERE 0
/// // SELECT * FROM player WHERE 0
/// Player.filter([].joined(operator: .or))
public func joined(operator: SQLLogicalBinaryOperator) -> SQLExpression {
let expressions = Array(self)
+28 -28
View File
@@ -5,7 +5,7 @@ extension Database {
#if GRDBCUSTOMSQLITE || GRDBCIPHER
/// Creates a database table.
///
/// try db.create(table: "pointOfInterests") { t in
/// try db.create(table: "place") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// t.column("favorite", .boolean).notNull().default(false)
@@ -34,7 +34,7 @@ extension Database {
#else
/// Creates a database table.
///
/// try db.create(table: "pointOfInterests") { t in
/// try db.create(table: "place") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// t.column("favorite", .boolean).notNull().default(false)
@@ -66,7 +66,7 @@ extension Database {
/// Creates a database table.
///
/// try db.create(table: "pointOfInterests") { t in
/// try db.create(table: "place") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("title", .text)
/// t.column("favorite", .boolean).notNull().default(false)
@@ -103,7 +103,7 @@ extension Database {
/// Modifies a database table.
///
/// try db.alter(table: "players") { t in
/// try db.alter(table: "player") { t in
/// t.add(column: "url", .text)
/// }
///
@@ -223,7 +223,7 @@ extension Database {
/// You don't create instances of this class. Instead, you use the Database
/// `create(table:)` method:
///
/// try db.create(table: "players") { t in // t is TableDefinition
/// try db.create(table: "player") { t in // t is TableDefinition
/// t.column(...)
/// }
///
@@ -250,7 +250,7 @@ public final class TableDefinition {
/// Defines the auto-incremented primary key.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// }
///
@@ -282,7 +282,7 @@ public final class TableDefinition {
/// Appends a table column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text)
/// }
///
@@ -301,7 +301,7 @@ public final class TableDefinition {
/// Defines the table primary key.
///
/// try db.create(table: "citizenships") { t in
/// try db.create(table: "citizenship") { t in
/// t.column("citizenID", .integer)
/// t.column("countryCode", .text)
/// t.primaryKey(["citizenID", "countryCode"])
@@ -323,7 +323,7 @@ public final class TableDefinition {
/// Adds a unique key.
///
/// try db.create(table: "pointOfInterests") { t in
/// try db.create(table: "place") { t in
/// t.column("latitude", .double)
/// t.column("longitude", .double)
/// t.uniqueKey(["latitude", "longitude"])
@@ -344,7 +344,7 @@ public final class TableDefinition {
/// t.column("issueDate", .date)
/// t.column("citizenID", .integer)
/// t.column("countryCode", .text)
/// t.foreignKey(["citizenID", "countryCode"], references: "citizenships", onDelete: .cascade)
/// t.foreignKey(["citizenID", "countryCode"], references: "citizenship", onDelete: .cascade)
/// }
///
/// See https://www.sqlite.org/foreignkeys.html
@@ -365,7 +365,7 @@ public final class TableDefinition {
/// Adds a CHECK constraint.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("personalPhone", .text)
/// t.column("workPhone", .text)
/// let personalPhone = Column("personalPhone")
@@ -382,7 +382,7 @@ public final class TableDefinition {
/// Adds a CHECK constraint.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("personalPhone", .text)
/// t.column("workPhone", .text)
/// t.check(sql: "personalPhone IS NOT NULL OR workPhone IS NOT NULL")
@@ -509,7 +509,7 @@ public final class TableDefinition {
/// You don't create instances of this class. Instead, you use the Database
/// `alter(table:)` method:
///
/// try db.alter(table: "players") { t in // t is TableAlteration
/// try db.alter(table: "player") { t in // t is TableAlteration
/// t.add(column: ...)
/// }
///
@@ -524,7 +524,7 @@ public final class TableAlteration {
/// Appends a column to the table.
///
/// try db.alter(table: "players") { t in
/// try db.alter(table: "player") { t in
/// t.add(column: "url", .text)
/// }
///
@@ -566,11 +566,11 @@ public final class TableAlteration {
///
/// You get instances of this class when you create or alter a database table:
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column(...) // ColumnDefinition
/// }
///
/// try db.alter(table: "players") { t in
/// try db.alter(table: "player") { t in
/// t.add(column: ...) // ColumnDefinition
/// }
///
@@ -599,7 +599,7 @@ public final class ColumnDefinition {
/// Adds a primary key constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("id", .integer).primaryKey()
/// }
///
@@ -619,7 +619,7 @@ public final class ColumnDefinition {
/// Adds a NOT NULL constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).notNull()
/// }
///
@@ -636,7 +636,7 @@ public final class ColumnDefinition {
/// Adds a UNIQUE constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("email", .text).unique()
/// }
///
@@ -653,7 +653,7 @@ public final class ColumnDefinition {
/// Adds an index of the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("email", .text).indexed()
/// }
///
@@ -670,7 +670,7 @@ public final class ColumnDefinition {
/// Adds a CHECK constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).check { length($0) > 0 }
/// }
///
@@ -687,7 +687,7 @@ public final class ColumnDefinition {
/// Adds a CHECK constraint on the column.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).check(sql: "LENGTH(name) > 0")
/// }
///
@@ -705,7 +705,7 @@ public final class ColumnDefinition {
/// Defines the default column value.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).defaults(to: "Anonymous")
/// }
///
@@ -721,7 +721,7 @@ public final class ColumnDefinition {
/// Defines the default column value.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("creationDate", .DateTime).defaults(sql: "CURRENT_TIMESTAMP")
/// }
///
@@ -739,7 +739,7 @@ public final class ColumnDefinition {
// Defines the default column collation.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("email", .text).collate(.nocase)
/// }
///
@@ -755,7 +755,7 @@ public final class ColumnDefinition {
// Defines the default column collation.
///
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.column("name", .text).collate(.localizedCaseInsensitiveCompare)
/// }
///
@@ -771,8 +771,8 @@ public final class ColumnDefinition {
/// Defines a foreign key.
///
/// try db.create(table: "books") { t in
/// t.column("authorId", .integer).references("authors", onDelete: .cascade)
/// try db.create(table: "book") { t in
/// t.column("authorId", .integer).references("author", onDelete: .cascade)
/// }
///
/// See https://www.sqlite.org/foreignkeys.html
+5 -5
View File
@@ -2,7 +2,7 @@
/// the `Database.create(virtualTable:using:)` method:
///
/// let module = ...
/// try db.create(virtualTable: "items", using: module) { t in
/// try db.create(virtualTable: "item", using: module) { t in
/// ...
/// }
///
@@ -13,7 +13,7 @@ public protocol VirtualTableModule {
/// The type of the closure argument in the
/// `Database.create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "items", using: module) { t in
/// try db.create(virtualTable: "item", using: module) { t in
/// // t is TableDefinition
/// }
associatedtype TableDefinition
@@ -24,7 +24,7 @@ public protocol VirtualTableModule {
/// Returns a table definition that is passed as the closure argument in the
/// `Database.create(virtualTable:using:)` method:
///
/// try db.create(virtualTable: "items", using: module) { t in
/// try db.create(virtualTable: "item", using: module) { t in
/// // t is the result of makeTableDefinition()
/// }
func makeTableDefinition() -> TableDefinition
@@ -70,7 +70,7 @@ extension Database {
/// Creates a virtual database table.
///
/// let module = ...
/// try db.create(virtualTable: "pointOfInterests", using: module) { t in
/// try db.create(virtualTable: "book", using: module) { t in
/// ...
/// }
///
@@ -80,7 +80,7 @@ extension Database {
/// Use this method to create full-text tables using the FTS3, FTS4, or
/// FTS5 modules:
///
/// try db.create(virtualTable: "books", using: FTS4()) { t in
/// try db.create(virtualTable: "book", using: FTS4()) { t in
/// t.column("title")
/// t.column("author")
/// t.column("body")
@@ -273,4 +273,3 @@ extension FetchableRecord where Self: Decodable {
try! self.init(from: RowDecoder(row: row, codingPath: []))
}
}
@@ -4,7 +4,7 @@ extension FetchableRecord where Self: TableRecord {
/// A cursor over all records fetched from the database.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// let players = try Player.fetchCursor(db) // Cursor of Player
/// while let player = try players.next() { // Player
/// ...
@@ -30,7 +30,7 @@ extension FetchableRecord where Self: TableRecord {
/// An array of all records fetched from the database.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// let players = try Player.fetchAll(db) // [Player]
///
/// The selection defaults to all columns. This default can be changed for
@@ -45,7 +45,7 @@ extension FetchableRecord where Self: TableRecord {
/// The first found record.
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// let player = try Player.fetchOne(db) // Player?
///
/// The selection defaults to all columns. This default can be changed for
+7 -7
View File
@@ -36,7 +36,7 @@ public protocol FetchableRecord {
///
/// struct Player : FetchableRecord { ... }
/// try dbQueue.read { db in
/// let players: RecordCursor<Player> = try Player.fetchCursor(db, "SELECT * FROM players")
/// let players: RecordCursor<Player> = try Player.fetchCursor(db, "SELECT * FROM player")
/// }
public final class RecordCursor<Record: FetchableRecord> : Cursor {
private let statement: SelectStatement
@@ -73,7 +73,7 @@ extension FetchableRecord {
/// A cursor over records fetched from a prepared statement.
///
/// let statement = try db.makeSelectStatement("SELECT * FROM players")
/// let statement = try db.makeSelectStatement("SELECT * FROM player")
/// let players = try Player.fetchCursor(statement) // Cursor of Player
/// while let player = try players.next() { // Player
/// ...
@@ -96,7 +96,7 @@ extension FetchableRecord {
/// Returns an array of records fetched from a prepared statement.
///
/// let statement = try db.makeSelectStatement("SELECT * FROM players")
/// let statement = try db.makeSelectStatement("SELECT * FROM player")
/// let players = try Player.fetchAll(statement) // [Player]
///
/// - parameters:
@@ -111,7 +111,7 @@ extension FetchableRecord {
/// Returns a single record fetched from a prepared statement.
///
/// let statement = try db.makeSelectStatement("SELECT * FROM players")
/// let statement = try db.makeSelectStatement("SELECT * FROM player")
/// let player = try Player.fetchOne(statement) // Player?
///
/// - parameters:
@@ -131,7 +131,7 @@ extension FetchableRecord {
/// Returns a cursor over records fetched from an SQL query.
///
/// let players = try Player.fetchCursor(db, "SELECT * FROM players") // Cursor of Player
/// let players = try Player.fetchCursor(db, "SELECT * FROM player") // Cursor of Player
/// while let player = try players.next() { // Player
/// ...
/// }
@@ -154,7 +154,7 @@ extension FetchableRecord {
/// Returns an array of records fetched from an SQL query.
///
/// let players = try Player.fetchAll(db, "SELECT * FROM players") // [Player]
/// let players = try Player.fetchAll(db, "SELECT * FROM player") // [Player]
///
/// - parameters:
/// - db: A database connection.
@@ -169,7 +169,7 @@ extension FetchableRecord {
/// Returns a single record fetched from an SQL query.
///
/// let player = try Player.fetchOne(db, "SELECT * FROM players") // Player?
/// let player = try Player.fetchOne(db, "SELECT * FROM player") // Player?
///
/// - parameters:
/// - db: A database connection.
+5 -6
View File
@@ -18,7 +18,7 @@ public final class FetchedRecordsController<Record: FetchableRecord> {
///
/// let controller = FetchedRecordsController<Wine>(
/// dbQueue,
/// sql: "SELECT * FROM wines WHERE color = ? ORDER BY name",
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
/// arguments: [Color.red],
/// isSameRecord: { (wine1, wine2) in wine1.id == wine2.id })
///
@@ -402,17 +402,17 @@ extension FetchedRecordsController where Record: TableRecord {
///
/// let controller = FetchedRecordsController<Wine>(
/// dbQueue,
/// sql: "SELECT * FROM wines WHERE color = ? ORDER BY name",
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
/// arguments: [Color.red])
///
/// The records are compared by primary key (single-column primary key,
/// compound primary key, or implicit rowid). For a database table which
/// has an `id` primary key, this initializer is equivalent to:
///
/// // Assuming the wines table has an `id` primary key:
/// // Assuming the wine table has an `id` primary key:
/// let controller = FetchedRecordsController<Wine>(
/// dbQueue,
/// sql: "SELECT * FROM wines WHERE color = ? ORDER BY name",
/// sql: "SELECT * FROM wine WHERE color = ? ORDER BY name",
/// arguments: [Color.red],
/// isSameRecord: { (wine1, wine2) in wine1.id == wine2.id })
///
@@ -451,7 +451,7 @@ extension FetchedRecordsController where Record: TableRecord {
/// compound primary key, or implicit rowid). For a database table which
/// has an `id` primary key, this initializer is equivalent to:
///
/// // Assuming the wines table has an `id` primary key:
/// // Assuming the wine table has an `id` primary key:
/// let controller = FetchedRecordsController<Wine>(
/// dbQueue,
/// request: request,
@@ -1049,4 +1049,3 @@ private final class Item<T: FetchableRecord> : FetchableRecord, Equatable {
return lhs.row == rhs.row
}
}
+17 -25
View File
@@ -126,6 +126,15 @@ public struct PersistenceContainer {
}
}
// Returns nil if column is not defined
func value(forCaseInsensitiveColumn column: String) -> DatabaseValue? {
let lowercaseColumn = column.lowercased()
for (key, value) in storage where key.lowercased() == lowercaseColumn {
return value?.databaseValue ?? .null
}
return nil
}
var isEmpty: Bool {
return storage.isEmpty
}
@@ -614,16 +623,16 @@ extension MutablePersistableRecord {
/// Delete records identified by their primary keys; returns the number of
/// deleted rows.
///
/// // DELETE FROM players WHERE id IN (1, 2, 3)
/// // DELETE FROM player WHERE id IN (1, 2, 3)
/// try Player.deleteAll(db, keys: [1, 2, 3])
///
/// // DELETE FROM countries WHERE code IN ('FR', 'US', 'DE')
/// // DELETE FROM country WHERE code IN ('FR', 'US', 'DE')
/// try Country.deleteAll(db, keys: ["FR", "US", "DE"])
///
/// When the table has no explicit primary key, GRDB uses the hidden
/// "rowid" column:
///
/// // DELETE FROM documents WHERE rowid IN (1, 2, 3)
/// // DELETE FROM document WHERE rowid IN (1, 2, 3)
/// try Document.deleteAll(db, keys: [1, 2, 3])
///
/// - parameters:
@@ -643,16 +652,16 @@ extension MutablePersistableRecord {
/// Delete a record, identified by its primary key; returns whether a
/// database row was deleted.
///
/// // DELETE FROM players WHERE id = 123
/// // DELETE FROM player WHERE id = 123
/// try Player.deleteOne(db, key: 123)
///
/// // DELETE FROM countries WHERE code = 'FR'
/// // DELETE FROM country WHERE code = 'FR'
/// try Country.deleteOne(db, key: "FR")
///
/// When the table has no explicit primary key, GRDB uses the hidden
/// "rowid" column:
///
/// // DELETE FROM documents WHERE rowid = 1
/// // DELETE FROM document WHERE rowid = 1
/// try Document.deleteOne(db, key: 1)
///
/// - parameters:
@@ -982,16 +991,8 @@ private struct InsertQuery: Hashable {
let tableName: String
let insertedColumns: [String]
// Not generated by Swift 4.1
// TODO: remove when Swift can generate it
var hashValue: Int { return tableName.hashValue }
#if !swift(>=4.1)
static func == (lhs: InsertQuery, rhs: InsertQuery) -> Bool {
if lhs.tableName != rhs.tableName { return false }
if lhs.onConflict != rhs.onConflict { return false }
return lhs.insertedColumns == rhs.insertedColumns
}
#endif
}
extension InsertQuery {
@@ -1023,17 +1024,8 @@ private struct UpdateQuery: Hashable {
let updatedColumns: [String]
let conditionColumns: [String]
// Not generated by Swift 4.1
// TODO: remove when Swift can generate it
var hashValue: Int { return tableName.hashValue }
#if !swift(>=4.1)
static func == (lhs: UpdateQuery, rhs: UpdateQuery) -> Bool {
if lhs.tableName != rhs.tableName { return false }
if lhs.onConflict != rhs.onConflict { return false }
if lhs.updatedColumns != rhs.updatedColumns { return false }
return lhs.conditionColumns == rhs.conditionColumns
}
#endif
}
extension UpdateQuery {
+4 -4
View File
@@ -32,7 +32,7 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord {
///
/// class Player : Record {
/// override class var databaseTableName: String {
/// return "players"
/// return "player"
/// }
/// }
///
@@ -64,7 +64,7 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord {
///
/// Unless this method is overriden, requests select all columns:
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// try Player.fetchAll(db)
///
/// You can override this property and provide an explicit list
@@ -76,7 +76,7 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord {
/// }
/// }
///
/// // SELECT id, name FROM players
/// // SELECT id, name FROM player
/// try RestrictedPlayer.fetchAll(db)
///
/// You can also add extra columns such as the `rowid` column:
@@ -87,7 +87,7 @@ open class Record : FetchableRecord, TableRecord, PersistableRecord {
/// }
/// }
///
/// // SELECT *, rowid FROM players
/// // SELECT *, rowid FROM player
/// try ExtendedPlayer.fetchAll(db)
open class var databaseSelection: [SQLSelectable] {
return [AllColumns()]
+20 -21
View File
@@ -12,10 +12,10 @@ public protocol TableRecord {
/// The name of the database table used to build requests.
///
/// struct Player : TableRecord {
/// static var databaseTableName = "players"
/// static var databaseTableName = "player"
/// }
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// try Player.fetchAll(db)
static var databaseTableName: String { get }
@@ -23,28 +23,28 @@ public protocol TableRecord {
///
/// Unless said otherwise, requests select all columns:
///
/// // SELECT * FROM players
/// // SELECT * FROM player
/// try Player.fetchAll(db)
///
/// You can provide a custom implementation and provide an explicit list
/// of columns:
///
/// struct RestrictedPlayer : TableRecord {
/// static var databaseTableName = "players"
/// static var databaseTableName = "player"
/// static var databaseSelection = [Column("id"), Column("name")]
/// }
///
/// // SELECT id, name FROM players
/// // SELECT id, name FROM player
/// try RestrictedPlayer.fetchAll(db)
///
/// You can also add extra columns such as the `rowid` column:
///
/// struct ExtendedPlayer : TableRecord {
/// static var databaseTableName = "players"
/// static var databaseTableName = "player"
/// static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
/// }
///
/// // SELECT *, rowid FROM players
/// // SELECT *, rowid FROM player
/// try ExtendedPlayer.fetchAll(db)
static var databaseSelection: [SQLSelectable] { get }
}
@@ -77,20 +77,20 @@ extension TableRecord {
/// For example:
///
/// struct Player: TableRecord {
/// static let databaseTableName = "players"
/// static let databaseTableName = "player"
/// }
///
/// // SELECT "players".* FROM players
/// let sql = "SELECT \(Player.selectionSQL()) FROM players"
/// // SELECT "player".* FROM player
/// let sql = "SELECT \(Player.selectionSQL()) FROM player"
///
/// // SELECT "p".* FROM players AS p
/// let sql = "SELECT \(Player.selectionSQL(alias: "p")) FROM players AS p"
/// // SELECT "p".* FROM player AS p
/// let sql = "SELECT \(Player.selectionSQL(alias: "p")) FROM player p"
public static func selectionSQL(alias: String? = nil) -> String {
let qualifier = SQLTableQualifier(tableName: databaseTableName, alias: alias ?? databaseTableName)
let selection = databaseSelection.map { $0.qualifiedSelectable(with: qualifier) }
var arguments: StatementArguments? = nil
let alias = TableAlias(tableName: databaseTableName, userName: alias)
let selection = databaseSelection.map { $0.qualifiedSelectable(with: alias) }
var context = SQLGenerationContext.recordSelectionGenerationContext(alias: alias)
return selection
.map { $0.resultColumnSQL(&arguments) }
.map { $0.resultColumnSQL(&context) }
.joined(separator: ", ")
}
@@ -99,11 +99,11 @@ extension TableRecord {
/// For example:
///
/// struct Player: TableRecord {
/// static let databaseTableName = "players"
/// static let databaseTableName = "player"
/// }
///
/// try dbQueue.write { db in
/// try db.create(table: "players") { t in
/// try db.create(table: "player") { t in
/// t.autoIncrementedPrimaryKey("id")
/// t.column("name", .text)
/// t.column("score", .integer)
@@ -113,10 +113,9 @@ extension TableRecord {
/// try Player.numberOfSelectedColumns(db)
/// }
public static func numberOfSelectedColumns(_ db: Database) throws -> Int {
let qualifier = SQLTableQualifier(tableName: databaseTableName, alias: nil)
let alias = TableAlias(tableName: databaseTableName)
return try databaseSelection
.map { try $0.qualifiedSelectable(with: qualifier).columnCount(db) }
.map { try $0.qualifiedSelectable(with: alias).columnCount(db) }
.reduce(0, +)
}
}
+222 -12
View File
@@ -195,6 +195,84 @@
564F9C241F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */; };
564F9C2F1F07611400877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
564F9C321F07611700877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
5653EB8F20961FC000F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8520961FBF00F46237 /* BelongsToAssociation.swift */; };
5653EB9020961FC000F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8520961FBF00F46237 /* BelongsToAssociation.swift */; };
5653EB9120961FC000F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8620961FBF00F46237 /* HasOneAssociation.swift */; };
5653EB9220961FC000F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8620961FBF00F46237 /* HasOneAssociation.swift */; };
5653EB9320961FC000F46237 /* AssociationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8720961FBF00F46237 /* AssociationQuery.swift */; };
5653EB9420961FC000F46237 /* AssociationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8720961FBF00F46237 /* AssociationQuery.swift */; };
5653EB9520961FC000F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8820961FBF00F46237 /* HasManyAssociation.swift */; };
5653EB9620961FC000F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8820961FBF00F46237 /* HasManyAssociation.swift */; };
5653EB9720961FC000F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8920961FBF00F46237 /* ForeignKey.swift */; };
5653EB9820961FC000F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8920961FBF00F46237 /* ForeignKey.swift */; };
5653EB9920961FC000F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8A20961FBF00F46237 /* ForeignKeyRequest.swift */; };
5653EB9A20961FC000F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8A20961FBF00F46237 /* ForeignKeyRequest.swift */; };
5653EB9B20961FC000F46237 /* AssociationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8B20961FBF00F46237 /* AssociationRequest.swift */; };
5653EB9C20961FC000F46237 /* AssociationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8B20961FBF00F46237 /* AssociationRequest.swift */; };
5653EB9D20961FC000F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8C20961FBF00F46237 /* Association.swift */; };
5653EB9E20961FC000F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB8C20961FBF00F46237 /* Association.swift */; };
5653EBA220961FCA00F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA120961FCA00F46237 /* QueryInterfaceRequest+Association.swift */; };
5653EBA320961FCA00F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA120961FCA00F46237 /* QueryInterfaceRequest+Association.swift */; };
5653EBB820961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */; };
5653EBB920961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */; };
5653EBBA20961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */; };
5653EBBB20961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */; };
5653EBBC20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */; };
5653EBBD20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */; };
5653EBBE20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */; };
5653EBBF20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */; };
5653EBC020961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */; };
5653EBC120961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */; };
5653EBC220961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */; };
5653EBC320961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */; };
5653EBC420961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */; };
5653EBC520961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */; };
5653EBC620961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */; };
5653EBC720961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */; };
5653EBC820961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */; };
5653EBC920961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */; };
5653EBCA20961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */; };
5653EBCB20961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */; };
5653EBCC20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */; };
5653EBCD20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */; };
5653EBCE20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */; };
5653EBCF20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */; };
5653EBD020961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */; };
5653EBD120961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */; };
5653EBD220961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */; };
5653EBD320961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */; };
5653EBD420961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */; };
5653EBD520961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */; };
5653EBD620961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */; };
5653EBD720961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */; };
5653EBD820961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */; };
5653EBD920961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */; };
5653EBDA20961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */; };
5653EBDB20961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */; };
5653EBDC20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */; };
5653EBDD20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */; };
5653EBDE20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */; };
5653EBDF20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */; };
5653EBE020961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */; };
5653EBE120961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */; };
5653EBE220961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */; };
5653EBE320961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */; };
5653EBE420961FE800F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */; };
5653EBE520961FE800F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */; };
5653EBE620961FE800F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */; };
5653EBE720961FE800F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */; };
5653EBE820961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */; };
5653EBE920961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */; };
5653EBEA20961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */; };
5653EBEB20961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */; };
5653EBEC20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */; };
5653EBED20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */; };
5653EBEE20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */; };
5653EBEF20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */; };
5653EC17209873A400F46237 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC15209873A400F46237 /* SQLExpression+QueryInterface.swift */; };
5653EC18209873A400F46237 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC15209873A400F46237 /* SQLExpression+QueryInterface.swift */; };
5653EC1A209873E600F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC19209873E600F46237 /* SQLGenerationContext.swift */; };
5653EC1B209873E600F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC19209873E600F46237 /* SQLGenerationContext.swift */; };
5657AABA1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; };
5657AABD1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; };
5657AB101D10899D006283EF /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB0E1D10899D006283EF /* URL.swift */; };
@@ -478,8 +556,6 @@
5698AD391DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
569A98FC2039B72D008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */; };
569A98FD2039B72D008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */; };
569B7FA8201C904C0069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA6201C904C0069DE70 /* Swift4.1.swift */; };
569B7FA9201C904C0069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA6201C904C0069DE70 /* Swift4.1.swift */; };
569C1EB31CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; };
569C1EB41CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; };
569C1EB61CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; };
@@ -755,8 +831,6 @@
56F3E74F1E66F83A00BF0F01 /* ResultCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */; };
56F3E7641E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; };
56F3E7671E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */; };
56FC98791D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */; };
56FC987C1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */; };
56FEE7FC1F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; };
56FEE7FD1F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; };
56FEE8001F47253700D930EA /* TableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FEE7FA1F47253700D930EA /* TableRecordTests.swift */; };
@@ -885,6 +959,31 @@
564E73EB203DA29B000C443C /* JoinSupportTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = "<group>"; };
564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAggregateTests.swift; sourceTree = "<group>"; };
564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunction.swift; sourceTree = "<group>"; };
5653EB8520961FBF00F46237 /* BelongsToAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BelongsToAssociation.swift; sourceTree = "<group>"; };
5653EB8620961FBF00F46237 /* HasOneAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasOneAssociation.swift; sourceTree = "<group>"; };
5653EB8720961FBF00F46237 /* AssociationQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationQuery.swift; sourceTree = "<group>"; };
5653EB8820961FBF00F46237 /* HasManyAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyAssociation.swift; sourceTree = "<group>"; };
5653EB8920961FBF00F46237 /* ForeignKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKey.swift; sourceTree = "<group>"; };
5653EB8A20961FBF00F46237 /* ForeignKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyRequest.swift; sourceTree = "<group>"; };
5653EB8B20961FBF00F46237 /* AssociationRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRequest.swift; sourceTree = "<group>"; };
5653EB8C20961FBF00F46237 /* Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Association.swift; sourceTree = "<group>"; };
5653EBA120961FCA00F46237 /* QueryInterfaceRequest+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "QueryInterfaceRequest+Association.swift"; sourceTree = "<group>"; };
5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelSQLTests.swift; sourceTree = "<group>"; };
5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToFetchableRecordTests.swift; sourceTree = "<group>"; };
5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelDecodableRecordTests.swift; sourceTree = "<group>"; };
5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLDerivationTests.swift; sourceTree = "<group>"; };
5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationTableAliasTestsSQLTests.swift; sourceTree = "<group>"; };
5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLTests.swift; sourceTree = "<group>"; };
5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRowScopeSearchTests.swift; sourceTree = "<group>"; };
5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLDerivationTests.swift; sourceTree = "<group>"; };
5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainRowScopesTests.swift; sourceTree = "<group>"; };
5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelRowScopesTests.swift; sourceTree = "<group>"; };
5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLTests.swift; sourceTree = "<group>"; };
5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainSQLTests.swift; sourceTree = "<group>"; };
5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToDecodableRecordTests.swift; sourceTree = "<group>"; };
5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToRowScopeTests.swift; sourceTree = "<group>"; };
5653EC15209873A400F46237 /* SQLExpression+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLExpression+QueryInterface.swift"; sourceTree = "<group>"; };
5653EC19209873E600F46237 /* SQLGenerationContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLGenerationContext.swift; sourceTree = "<group>"; };
5657AAB81D107001006283EF /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = "<group>"; };
5657AB0E1D10899D006283EF /* URL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDataTests.swift; sourceTree = "<group>"; };
@@ -976,7 +1075,6 @@
5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = "<group>"; };
5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = "<group>"; };
569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = "<group>"; };
569B7FA6201C904C0069DE70 /* Swift4.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swift4.1.swift; sourceTree = "<group>"; };
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = "<group>"; };
569EF0E8200D387000A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = "<group>"; };
56A238131B9C74A90082EB20 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = "<group>"; };
@@ -1074,7 +1172,6 @@
56F0B98E1B6001C600A2F135 /* FoundationNSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationNSDateTests.swift; sourceTree = "<group>"; };
56F3E7481E66F83A00BF0F01 /* ResultCodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultCodeTests.swift; sourceTree = "<group>"; };
56F3E7621E67F8C100BF0F01 /* Fixits-0.101.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-0.101.1.swift"; sourceTree = "<group>"; };
56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SQLExpression+QueryInterface.swift"; sourceTree = "<group>"; };
56FDECE11BB32DFD009AD709 /* RowFromStatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromStatementTests.swift; sourceTree = "<group>"; };
56FEE7FA1F47253700D930EA /* TableRecordTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableRecordTests.swift; sourceTree = "<group>"; };
56FF453F1D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordDeleteTests.swift; sourceTree = "<group>"; };
@@ -1317,6 +1414,7 @@
56300B5C1C53C38F005A543B /* QueryInterface */ = {
isa = PBXGroup;
children = (
5653EBA420961FD300F46237 /* Association */,
56B6EF62208CB762002F0ACB /* ColumnExpressionTests.swift */,
56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */,
56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */,
@@ -1333,17 +1431,20 @@
56300B6D1C53F592005A543B /* QueryInterface */ = {
isa = PBXGroup;
children = (
5653EB8420961FBF00F46237 /* Association */,
56CEB5401EAA359A00BFAF62 /* Column.swift */,
56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */,
56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */,
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */,
56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */,
5653EBA120961FCA00F46237 /* QueryInterfaceRequest+Association.swift */,
5616AAF8207CD5A900AC3664 /* RequestProtocols.swift */,
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */,
566475991D97D8A000FF74B8 /* SQLCollection.swift */,
56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */,
56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */,
56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */,
5653EC15209873A400F46237 /* SQLExpression+QueryInterface.swift */,
5653EC19209873E600F46237 /* SQLGenerationContext.swift */,
56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */,
56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */,
566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */,
@@ -1368,6 +1469,42 @@
name = DatabaseQueue;
sourceTree = "<group>";
};
5653EB8420961FBF00F46237 /* Association */ = {
isa = PBXGroup;
children = (
5653EB8C20961FBF00F46237 /* Association.swift */,
5653EB8720961FBF00F46237 /* AssociationQuery.swift */,
5653EB8B20961FBF00F46237 /* AssociationRequest.swift */,
5653EB8520961FBF00F46237 /* BelongsToAssociation.swift */,
5653EB8920961FBF00F46237 /* ForeignKey.swift */,
5653EB8A20961FBF00F46237 /* ForeignKeyRequest.swift */,
5653EB8820961FBF00F46237 /* HasManyAssociation.swift */,
5653EB8620961FBF00F46237 /* HasOneAssociation.swift */,
);
path = Association;
sourceTree = "<group>";
};
5653EBA420961FD300F46237 /* Association */ = {
isa = PBXGroup;
children = (
5653EBB220961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift */,
5653EBA720961FE600F46237 /* AssociationBelongsToFetchableRecordTests.swift */,
5653EBB320961FE800F46237 /* AssociationBelongsToRowScopeTests.swift */,
5653EBA920961FE700F46237 /* AssociationBelongsToSQLDerivationTests.swift */,
5653EBB020961FE700F46237 /* AssociationBelongsToSQLTests.swift */,
5653EBAE20961FE700F46237 /* AssociationChainRowScopesTests.swift */,
5653EBB120961FE800F46237 /* AssociationChainSQLTests.swift */,
5653EBAD20961FE700F46237 /* AssociationHasOneSQLDerivationTests.swift */,
5653EBAB20961FE700F46237 /* AssociationHasOneSQLTests.swift */,
5653EBA820961FE600F46237 /* AssociationParallelDecodableRecordTests.swift */,
5653EBAF20961FE700F46237 /* AssociationParallelRowScopesTests.swift */,
5653EBA620961FE600F46237 /* AssociationParallelSQLTests.swift */,
5653EBAC20961FE700F46237 /* AssociationRowScopeSearchTests.swift */,
5653EBAA20961FE700F46237 /* AssociationTableAliasTestsSQLTests.swift */,
);
name = Association;
sourceTree = "<group>";
};
5659F4861EA8D94E004A4992 /* Utils */ = {
isa = PBXGroup;
children = (
@@ -1613,7 +1750,6 @@
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */,
569B7FA6201C904C0069DE70 /* Swift4.1.swift */,
);
path = Legacy;
sourceTree = "<group>";
@@ -1996,21 +2132,25 @@
56BB6EAA1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */,
566B910A1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
566B91241FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
5653EB9B20961FC000F46237 /* AssociationRequest.swift in Sources */,
56CEB5121EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */,
5659F4911EA8D964004A4992 /* ReadWriteBox.swift in Sources */,
566A842920413D6F00E50BFD /* DatabaseSnapshot.swift in Sources */,
56CEB4F21EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */,
560FC51C1CB003810014AA8E /* QueryInterfaceRequest.swift in Sources */,
560FC51D1CB003810014AA8E /* SQLCollatedExpression.swift in Sources */,
5653EB9920961FC000F46237 /* ForeignKeyRequest.swift in Sources */,
566B91341FA4D3810012D5B0 /* TransactionObserver.swift in Sources */,
56D1215B1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */,
566475D41D981D5E00FF74B8 /* SQLOperators.swift in Sources */,
5653EB9120961FC000F46237 /* HasOneAssociation.swift in Sources */,
56CEB5621EAA359A00BFAF62 /* SQLSelectable.swift in Sources */,
56CEB4FB1EAA2F4D00BFAF62 /* FTS3.swift in Sources */,
5698AD361DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */,
566B91141FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */,
560FC51F1CB003810014AA8E /* CGFloat.swift in Sources */,
5674A7091F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */,
5653EC17209873A400F46237 /* SQLExpression+QueryInterface.swift in Sources */,
5659F4A11EA8D997004A4992 /* Result.swift in Sources */,
560FC5201CB003810014AA8E /* Date.swift in Sources */,
560FC5221CB003810014AA8E /* DatabaseValueConvertible+RawRepresentable.swift in Sources */,
@@ -2020,13 +2160,14 @@
5698AC381D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
564F9C2F1F07611400877A00 /* DatabaseFunction.swift in Sources */,
5659F4991EA8D989004A4992 /* Pool.swift in Sources */,
569B7FA8201C904C0069DE70 /* Swift4.1.swift in Sources */,
5653EB8F20961FC000F46237 /* BelongsToAssociation.swift in Sources */,
5674A6FA1F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */,
56CEB54D1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
5664759B1D97D8A000FF74B8 /* SQLCollection.swift in Sources */,
567404891CEF84C8003ED5CC /* RowAdapter.swift in Sources */,
56E06F131E859068008AE2A4 /* Fixits-0.102.0.swift in Sources */,
560FC5241CB003810014AA8E /* DatabaseWriter.swift in Sources */,
5653EBA220961FCA00F46237 /* QueryInterfaceRequest+Association.swift in Sources */,
5698AD191DAAD17B0056AF8C /* FTS5Tokenizer.swift in Sources */,
56F3E7641E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */,
56B964B21DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */,
@@ -2053,9 +2194,9 @@
560FC5341CB003810014AA8E /* QueryInterfaceQuery.swift in Sources */,
566B912C1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
560FC5351CB003810014AA8E /* Statement.swift in Sources */,
5653EB9320961FC000F46237 /* AssociationQuery.swift in Sources */,
5690C3411D23E82A00E59934 /* Data.swift in Sources */,
5659F4891EA8D94E004A4992 /* Utils.swift in Sources */,
56FC98791D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */,
560FC5361CB003810014AA8E /* DatabaseMigrator.swift in Sources */,
560FC5371CB003810014AA8E /* DatabaseSchemaCache.swift in Sources */,
560FC5381CB003810014AA8E /* DatabaseDateComponents.swift in Sources */,
@@ -2071,14 +2212,18 @@
566AD8B31D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
5698AD221DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
560FC53C1CB003810014AA8E /* DatabaseQueue.swift in Sources */,
5653EB9720961FC000F46237 /* ForeignKey.swift in Sources */,
569A98FC2039B72D008D7DBF /* Fixits-3.0.swift in Sources */,
5653EB9520961FC000F46237 /* HasManyAssociation.swift in Sources */,
560FC53D1CB003810014AA8E /* NSNumber.swift in Sources */,
567071F8208A00D4006AD95A /* SQLiteDateParser.swift in Sources */,
560FC53F1CB003810014AA8E /* Row.swift in Sources */,
560FC5401CB003810014AA8E /* StandardLibrary.swift in Sources */,
5653EC1A209873E600F46237 /* SQLGenerationContext.swift in Sources */,
560FC5411CB003810014AA8E /* PersistableRecord.swift in Sources */,
566475A31D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */,
5674A6EA1F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */,
5653EB9D20961FC000F46237 /* Association.swift in Sources */,
5657AABA1D107001006283EF /* NSData.swift in Sources */,
560FC5421CB003810014AA8E /* StatementColumnConvertible.swift in Sources */,
56CEB5541EAA359A00BFAF62 /* SQLExpression.swift in Sources */,
@@ -2097,6 +2242,7 @@
5698ACD81DA925420056AF8C /* RowTestCase.swift in Sources */,
56A8C2411D1918EE0096E9D4 /* FoundationNSUUIDTests.swift in Sources */,
562EA8301F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */,
5653EBC020961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
562206031E420EA3005860AC /* DatabasePoolBackupTests.swift in Sources */,
5657AB571D108BA9006283EF /* FoundationNSStringTests.swift in Sources */,
564448841EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */,
@@ -2115,6 +2261,7 @@
562393191DECC02000A6B01F /* RowFetchTests.swift in Sources */,
560FC56B1CB00B880014AA8E /* DatabaseCollationTests.swift in Sources */,
560FC56C1CB00B880014AA8E /* UpdateStatementTests.swift in Sources */,
5653EBE020961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */,
560FC56D1CB00B880014AA8E /* DatabaseMigratorTests.swift in Sources */,
560FC5701CB00B880014AA8E /* DatabasePoolCollationTests.swift in Sources */,
560FC5711CB00B880014AA8E /* RecordPrimaryKeySingleTests.swift in Sources */,
@@ -2123,11 +2270,14 @@
56B021CA1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */,
562205F61E420E48005860AC /* DatabaseQueueReleaseMemoryTests.swift in Sources */,
560FC5741CB00B880014AA8E /* DatabasePoolFunctionTests.swift in Sources */,
5653EBDC20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */,
560FC5761CB00B880014AA8E /* RowCopiedFromStatementTests.swift in Sources */,
560FC5771CB00B880014AA8E /* DatabaseQueueSchemaCacheTests.swift in Sources */,
5653EBCC20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */,
562756441E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */,
56AF746C1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */,
56B14E801D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */,
5653EBE420961FE800F46237 /* AssociationChainSQLTests.swift in Sources */,
562206051E420EA3005860AC /* DatabasePoolReadOnlyTests.swift in Sources */,
562206041E420EA3005860AC /* DatabasePoolConcurrencyTests.swift in Sources */,
56176C611EACCCC7000F3F2B /* FTS5RecordTests.swift in Sources */,
@@ -2155,6 +2305,7 @@
560FC57F1CB00B880014AA8E /* FetchableRecord+QueryInterfaceRequestTests.swift in Sources */,
5698ACB71DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */,
5672DE5A1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */,
5653EBE820961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */,
56176C601EACCCC7000F3F2B /* FTS5PatternTests.swift in Sources */,
564E73EF203DA2A2000C443C /* JoinSupportTests.swift in Sources */,
5674A7111F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */,
@@ -2165,8 +2316,10 @@
567E55ED1D2BDD3D00CC6F79 /* EncryptionTests.swift in Sources */,
56741EA91E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
56176C641EACCCC7000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
5653EBB820961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */,
560FC5841CB00B880014AA8E /* PersistableRecordTests.swift in Sources */,
560FC5871CB00B880014AA8E /* RecordSubClassTests.swift in Sources */,
5653EBBC20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */,
560FC5891CB00B880014AA8E /* TransactionObserverTests.swift in Sources */,
5674A72C1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */,
56C3F7541CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */,
@@ -2179,8 +2332,10 @@
56071A4E1DB54ED200CA6E47 /* FetchedRecordsControllerTests.swift in Sources */,
56A4CDB11D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */,
567156141CB141D0007DC145 /* DatabaseQueueInMemoryTests.swift in Sources */,
5653EBEC20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */,
560FC58E1CB00B880014AA8E /* RecordPrimaryKeyRowIDTests.swift in Sources */,
560FC58F1CB00B880014AA8E /* DatabaseReaderTests.swift in Sources */,
5653EBD020961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */,
560FC5901CB00B880014AA8E /* RecordEditedTests.swift in Sources */,
560FC5911CB00B880014AA8E /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */,
56CC924C201E059100CB597E /* DropFirstCursorTests.swift in Sources */,
@@ -2188,9 +2343,12 @@
560FC5921CB00B880014AA8E /* FetchableRecordTests.swift in Sources */,
56A5EF101EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */,
5657AB371D108BA9006283EF /* FoundationDataTests.swift in Sources */,
5653EBD820961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */,
560FC5941CB00B880014AA8E /* DatabaseValueConvertibleSubclassTests.swift in Sources */,
5653EBC820961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */,
565EFAEF1D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */,
560FC5961CB00B880014AA8E /* DatabaseValueConvertibleFetchTests.swift in Sources */,
5653EBC420961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */,
560FC5971CB00B880014AA8E /* DatabaseErrorTests.swift in Sources */,
560FC5991CB00B880014AA8E /* RecordMinimalPrimaryKeySingleTests.swift in Sources */,
564F9C1F1F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */,
@@ -2222,6 +2380,7 @@
5698AC8A1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */,
5698AC041D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */,
5690C3381D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
5653EBD420961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */,
6340BF811E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */,
5622060B1E420EB3005860AC /* DatabaseQueueConcurrencyTests.swift in Sources */,
562205F41E420E48005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */,
@@ -2244,6 +2403,7 @@
5698ACD91DA925420056AF8C /* RowTestCase.swift in Sources */,
567156221CB16729007DC145 /* StatementColumnConvertibleFetchTests.swift in Sources */,
562EA8311F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */,
5653EBC120961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
562206001E420EA3005860AC /* DatabasePoolBackupTests.swift in Sources */,
567156231CB16729007DC145 /* RecordPrimaryKeyNoneTests.swift in Sources */,
564448851EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */,
@@ -2262,6 +2422,7 @@
5623931A1DECC02000A6B01F /* RowFetchTests.swift in Sources */,
5671562E1CB16729007DC145 /* DatabasePoolCollationTests.swift in Sources */,
5671562F1CB16729007DC145 /* RecordPrimaryKeySingleTests.swift in Sources */,
5653EBE120961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */,
567156301CB16729007DC145 /* StatementColumnConvertibleTests.swift in Sources */,
56C3F7551CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */,
5672DE5B1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */,
@@ -2270,11 +2431,14 @@
56B14E811D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */,
562205F91E420E49005860AC /* DatabaseQueueReleaseMemoryTests.swift in Sources */,
566AD8C81D531BEB002EC1A8 /* TableDefinitionTests.swift in Sources */,
5653EBDD20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */,
567156321CB16729007DC145 /* DatabasePoolFunctionTests.swift in Sources */,
567156341CB16729007DC145 /* RowCopiedFromStatementTests.swift in Sources */,
5653EBCD20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */,
562756451E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */,
569C1EB41CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */,
56AF746D1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */,
5653EBE520961FE800F46237 /* AssociationChainSQLTests.swift in Sources */,
562206021E420EA3005860AC /* DatabasePoolReadOnlyTests.swift in Sources */,
562206011E420EA3005860AC /* DatabasePoolConcurrencyTests.swift in Sources */,
56176C671EACCCC8000F3F2B /* FTS5RecordTests.swift in Sources */,
@@ -2302,6 +2466,7 @@
5671563F1CB16729007DC145 /* RecordCopyTests.swift in Sources */,
5698ACB81DA6285E0056AF8C /* FTS3TokenizerTests.swift in Sources */,
567156401CB16729007DC145 /* RawRepresentable+DatabaseValueConvertibleTests.swift in Sources */,
5653EBE920961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */,
56176C661EACCCC8000F3F2B /* FTS5PatternTests.swift in Sources */,
564E73F0203DA2A3000C443C /* JoinSupportTests.swift in Sources */,
5674A7131F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */,
@@ -2312,8 +2477,10 @@
5690C3391D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
56741EAA1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
56176C6A1EACCCC8000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
5653EBB920961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */,
567156461CB16729007DC145 /* TransactionObserverTests.swift in Sources */,
567A80551D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
5653EBBD20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */,
567156481CB16729007DC145 /* DatabaseValueTests.swift in Sources */,
5674A72E1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */,
5671564A1CB16729007DC145 /* DatabaseQueueReadOnlyTests.swift in Sources */,
@@ -2326,8 +2493,10 @@
56071A4F1DB54ED300CA6E47 /* FetchedRecordsControllerTests.swift in Sources */,
5671564D1CB16729007DC145 /* RecordPrimaryKeyRowIDTests.swift in Sources */,
5671564E1CB16729007DC145 /* DatabaseReaderTests.swift in Sources */,
5653EBED20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */,
5671564F1CB16729007DC145 /* RecordEditedTests.swift in Sources */,
567156501CB16729007DC145 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */,
5653EBD120961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */,
567156511CB16729007DC145 /* FetchableRecordTests.swift in Sources */,
56A8C2441D1918EE0096E9D4 /* FoundationUUIDTests.swift in Sources */,
56CC924D201E059100CB597E /* DropFirstCursorTests.swift in Sources */,
@@ -2335,9 +2504,12 @@
567156531CB16729007DC145 /* DatabaseValueConvertibleSubclassTests.swift in Sources */,
56A5EF111EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */,
5690C3281D23E6D800E59934 /* FoundationDateComponentsTests.swift in Sources */,
5653EBD920961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */,
5657AB381D108BA9006283EF /* FoundationDataTests.swift in Sources */,
5653EBC920961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */,
561667031D08A49900ADD404 /* FoundationNSDecimalNumberTests.swift in Sources */,
565EFAF01D0436CE00A8FA9D /* NumericOverflowTests.swift in Sources */,
5653EBC520961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */,
567156551CB16729007DC145 /* DatabaseValueConvertibleFetchTests.swift in Sources */,
567156561CB16729007DC145 /* DatabaseErrorTests.swift in Sources */,
564F9C201F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */,
@@ -2369,6 +2541,7 @@
5698AC8B1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */,
5698AC051D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */,
567156621CB16729007DC145 /* CGFloatTests.swift in Sources */,
5653EBD520961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */,
6340BF821E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */,
5622060A1E420EB2005860AC /* DatabaseQueueConcurrencyTests.swift in Sources */,
562205F71E420E49005860AC /* DatabasePoolReleaseMemoryTests.swift in Sources */,
@@ -2391,21 +2564,25 @@
56BB6EAD1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */,
566B910D1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
566B91271FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
5653EB9C20961FC000F46237 /* AssociationRequest.swift in Sources */,
56CEB5151EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */,
5659F4941EA8D964004A4992 /* ReadWriteBox.swift in Sources */,
566A842A20413D8500E50BFD /* DatabaseSnapshot.swift in Sources */,
56CEB4F51EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */,
56AFC9F11CB1A8BB00F48B96 /* QueryInterfaceRequest.swift in Sources */,
56AFC9F21CB1A8BB00F48B96 /* SQLCollatedExpression.swift in Sources */,
5653EB9A20961FC000F46237 /* ForeignKeyRequest.swift in Sources */,
566B91371FA4D3810012D5B0 /* TransactionObserver.swift in Sources */,
56D1215E1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */,
566475D71D981D5E00FF74B8 /* SQLOperators.swift in Sources */,
5653EB9220961FC000F46237 /* HasOneAssociation.swift in Sources */,
56CEB5651EAA359A00BFAF62 /* SQLSelectable.swift in Sources */,
56CEB4FE1EAA2F4D00BFAF62 /* FTS3.swift in Sources */,
5698AD391DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */,
566B91171FA4C3F50012D5B0 /* DatabaseCollation.swift in Sources */,
56AFC9F31CB1A8BB00F48B96 /* Database.swift in Sources */,
5674A7061F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */,
5653EC18209873A400F46237 /* SQLExpression+QueryInterface.swift in Sources */,
5659F4A41EA8D997004A4992 /* Result.swift in Sources */,
56AFC9F41CB1A8BB00F48B96 /* CGFloat.swift in Sources */,
56AFC9F51CB1A8BB00F48B96 /* Date.swift in Sources */,
@@ -2415,13 +2592,14 @@
5698AC3B1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
564F9C321F07611700877A00 /* DatabaseFunction.swift in Sources */,
5659F49C1EA8D989004A4992 /* Pool.swift in Sources */,
569B7FA9201C904C0069DE70 /* Swift4.1.swift in Sources */,
5653EB9020961FC000F46237 /* BelongsToAssociation.swift in Sources */,
5674A6F71F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */,
56CEB5501EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
5664759E1D97D8A000FF74B8 /* SQLCollection.swift in Sources */,
5674048B1CEF84C8003ED5CC /* RowAdapter.swift in Sources */,
56E06F161E85906C008AE2A4 /* Fixits-0.102.0.swift in Sources */,
56AFC9F91CB1A8BB00F48B96 /* DatabaseWriter.swift in Sources */,
5653EBA320961FCA00F46237 /* QueryInterfaceRequest+Association.swift in Sources */,
5698AD1A1DAAD17C0056AF8C /* FTS5Tokenizer.swift in Sources */,
56F3E7671E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */,
56B964B51DA51D010002DA19 /* FTS5TokenizerDescriptor.swift in Sources */,
@@ -2448,9 +2626,9 @@
56AFCA091CB1A8BB00F48B96 /* QueryInterfaceQuery.swift in Sources */,
566B912F1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
56AFCA0A1CB1A8BB00F48B96 /* Migration.swift in Sources */,
5653EB9420961FC000F46237 /* AssociationQuery.swift in Sources */,
5690C3441D23E82A00E59934 /* Data.swift in Sources */,
5659F48C1EA8D94E004A4992 /* Utils.swift in Sources */,
56FC987C1D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */,
56AFCA0B1CB1A8BB00F48B96 /* Row.swift in Sources */,
56AFCA0C1CB1A8BB00F48B96 /* DatabaseSchemaCache.swift in Sources */,
56AFCA0D1CB1A8BB00F48B96 /* DatabaseDateComponents.swift in Sources */,
@@ -2466,14 +2644,18 @@
566AD8B61D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
5698AD251DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
56AFCA121CB1A8BB00F48B96 /* NSNumber.swift in Sources */,
5653EB9820961FC000F46237 /* ForeignKey.swift in Sources */,
569A98FD2039B72D008D7DBF /* Fixits-3.0.swift in Sources */,
5653EB9620961FC000F46237 /* HasManyAssociation.swift in Sources */,
56AFCA141CB1A8BB00F48B96 /* StandardLibrary.swift in Sources */,
56AFCA151CB1A8BB00F48B96 /* PersistableRecord.swift in Sources */,
567071F9208A00D4006AD95A /* SQLiteDateParser.swift in Sources */,
56AFCA161CB1A8BB00F48B96 /* StatementColumnConvertible.swift in Sources */,
5653EC1B209873E600F46237 /* SQLGenerationContext.swift in Sources */,
566475A61D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */,
5657AABD1D107001006283EF /* NSData.swift in Sources */,
5674A6E71F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */,
5653EB9E20961FC000F46237 /* Association.swift in Sources */,
56AFCA181CB1A8BB00F48B96 /* FetchedRecordsController.swift in Sources */,
56AFCA191CB1A8BB00F48B96 /* DatabaseValue.swift in Sources */,
56CEB5571EAA359A00BFAF62 /* SQLExpression.swift in Sources */,
@@ -2492,6 +2674,7 @@
56AFCA311CB1AA9900F48B96 /* RecordPrimaryKeyNoneTests.swift in Sources */,
56AFCA321CB1AA9900F48B96 /* DatabaseQueueConcurrencyTests.swift in Sources */,
562EA8341F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */,
5653EBC220961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
5698ACD31DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */,
56AFCA331CB1AA9900F48B96 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */,
564448881EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */,
@@ -2510,6 +2693,7 @@
56AFCA3B1CB1AA9900F48B96 /* DatabaseMigratorTests.swift in Sources */,
5657AB4B1D108BA9006283EF /* FoundationNSNullTests.swift in Sources */,
56AFCA3E1CB1AA9900F48B96 /* DatabasePoolCollationTests.swift in Sources */,
5653EBE220961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */,
56FF455B1D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */,
56AFCA3F1CB1AA9900F48B96 /* RecordPrimaryKeySingleTests.swift in Sources */,
56AFCA411CB1AA9900F48B96 /* StatementColumnConvertibleTests.swift in Sources */,
@@ -2518,11 +2702,14 @@
56AFCA441CB1AA9900F48B96 /* RowCopiedFromStatementTests.swift in Sources */,
56C3F7571CF9F12400F6A361 /* DatabaseSavepointTests.swift in Sources */,
562393351DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */,
5653EBDE20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */,
5698ACDC1DA925430056AF8C /* RowTestCase.swift in Sources */,
56AFCA451CB1AA9900F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */,
5653EBCE20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */,
562756481E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */,
56AFCA461CB1AA9900F48B96 /* RecordPrimaryKeyMultipleTests.swift in Sources */,
56AFCA471CB1AA9900F48B96 /* RowFromStatementTests.swift in Sources */,
5653EBE620961FE800F46237 /* AssociationChainSQLTests.swift in Sources */,
56AFCA491CB1AA9900F48B96 /* StatementArgumentsTests.swift in Sources */,
5672DE6B1CDB751D0022BA81 /* DatabasePoolBackupTests.swift in Sources */,
56176C731EACCCCA000F3F2B /* FTS5RecordTests.swift in Sources */,
@@ -2550,6 +2737,7 @@
56AFCA521CB1AA9900F48B96 /* PersistableRecordTests.swift in Sources */,
56AFCA531CB1AA9900F48B96 /* DatabaseValueConversionTests.swift in Sources */,
5657AB531D108BA9006283EF /* FoundationNSNumberTests.swift in Sources */,
5653EBEA20961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */,
5698AC9B1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */,
56176C721EACCCCA000F3F2B /* FTS5PatternTests.swift in Sources */,
564E73F1203DA2A3000C443C /* JoinSupportTests.swift in Sources */,
@@ -2560,8 +2748,10 @@
56AFCA561CB1AA9900F48B96 /* DatabasePoolConcurrencyTests.swift in Sources */,
56AFCA571CB1AA9900F48B96 /* TransactionObserverTests.swift in Sources */,
56741EAD1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
5653EBBA20961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */,
56176C761EACCCCA000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
5623935C1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
5653EBBE20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */,
5698AC851DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */,
5698AC451DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */,
5674A72B1F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */,
@@ -2574,8 +2764,10 @@
56A4CDB51D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */,
56AFCA5B1CB1AA9900F48B96 /* DatabaseValueTests.swift in Sources */,
56AFCA5C1CB1AA9900F48B96 /* DatabaseQueueReadOnlyTests.swift in Sources */,
5653EBEE20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */,
56AFCA5D1CB1AA9900F48B96 /* DatabaseReaderTests.swift in Sources */,
56A8C2491D1918F10096E9D4 /* FoundationNSUUIDTests.swift in Sources */,
5653EBD220961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */,
56AFCA5E1CB1AA9900F48B96 /* FetchableRecordTests.swift in Sources */,
56AFCA5F1CB1AA9900F48B96 /* DatabaseValueConvertibleFetchTests.swift in Sources */,
56AFCA601CB1AA9900F48B96 /* RecordPrimaryKeyRowIDTests.swift in Sources */,
@@ -2583,9 +2775,12 @@
56AFCA611CB1AA9900F48B96 /* RecordEditedTests.swift in Sources */,
56AFCA621CB1AA9900F48B96 /* DatabasePoolSchemaCacheTests.swift in Sources */,
56A5EF141EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */,
5653EBDA20961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */,
5623931D1DECC02000A6B01F /* RowFetchTests.swift in Sources */,
5653EBCA20961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */,
56AFCA631CB1AA9900F48B96 /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */,
5698AC8E1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */,
5653EBC620961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */,
56AFCA641CB1AA9900F48B96 /* DatabaseValueConvertibleSubclassTests.swift in Sources */,
56A8C24A1D1918F10096E9D4 /* FoundationUUIDTests.swift in Sources */,
56AFCA651CB1AA9900F48B96 /* DatabaseErrorTests.swift in Sources */,
@@ -2617,6 +2812,7 @@
56AFCA731CB1AA9900F48B96 /* DatabaseQueueInMemoryTests.swift in Sources */,
56AFCA741CB1AA9900F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */,
567A80581D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
5653EBD620961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */,
6340BF851E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */,
56AFCA751CB1AA9900F48B96 /* CGFloatTests.swift in Sources */,
562393531DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */,
@@ -2639,6 +2835,7 @@
56AFCA8A1CB1ABC800F48B96 /* RecordPrimaryKeyNoneTests.swift in Sources */,
56AFCA8B1CB1ABC800F48B96 /* DatabaseQueueConcurrencyTests.swift in Sources */,
562EA8351F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */,
5653EBC320961FE800F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
5698ACD41DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */,
56AFCA8C1CB1ABC800F48B96 /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */,
564448891EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */,
@@ -2657,6 +2854,7 @@
56AFCA911CB1ABC800F48B96 /* QueryInterfaceExpressionsTests.swift in Sources */,
56AFCA921CB1ABC800F48B96 /* SelectStatementTests.swift in Sources */,
56AFCA931CB1ABC800F48B96 /* UpdateStatementTests.swift in Sources */,
5653EBE320961FE800F46237 /* AssociationBelongsToSQLTests.swift in Sources */,
56AFCA941CB1ABC800F48B96 /* DatabaseMigratorTests.swift in Sources */,
5657AB641D108BA9006283EF /* FoundationNSURLTests.swift in Sources */,
56FF455C1D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */,
@@ -2665,11 +2863,14 @@
5657AB5C1D108BA9006283EF /* FoundationNSStringTests.swift in Sources */,
56AFCA981CB1ABC800F48B96 /* RecordPrimaryKeySingleTests.swift in Sources */,
562393361DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */,
5653EBDF20961FE800F46237 /* AssociationParallelRowScopesTests.swift in Sources */,
5698ACDD1DA925430056AF8C /* RowTestCase.swift in Sources */,
56AFCA9A1CB1ABC800F48B96 /* StatementColumnConvertibleTests.swift in Sources */,
5653EBCF20961FE800F46237 /* AssociationHasOneSQLTests.swift in Sources */,
562756491E963AAC0035B653 /* DatabaseWriterTests.swift in Sources */,
56AFCA9B1CB1ABC800F48B96 /* DatabasePoolFunctionTests.swift in Sources */,
5672DE5E1CDB72520022BA81 /* DatabaseQueueBackupTests.swift in Sources */,
5653EBE720961FE800F46237 /* AssociationChainSQLTests.swift in Sources */,
56AFCA9D1CB1ABC800F48B96 /* RowCopiedFromStatementTests.swift in Sources */,
56AFCA9E1CB1ABC800F48B96 /* DatabaseQueueSchemaCacheTests.swift in Sources */,
56176C791EACCCCB000F3F2B /* FTS5RecordTests.swift in Sources */,
@@ -2697,6 +2898,7 @@
56A8C24B1D1918F10096E9D4 /* FoundationNSUUIDTests.swift in Sources */,
56AFCAAB1CB1ABC800F48B96 /* PersistableRecordTests.swift in Sources */,
56FF45461D2C23BA00F21EF9 /* MutablePersistableRecordDeleteTests.swift in Sources */,
5653EBEB20961FE800F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */,
5698AC9C1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */,
56176C781EACCCCB000F3F2B /* FTS5PatternTests.swift in Sources */,
564E73F2203DA2A4000C443C /* JoinSupportTests.swift in Sources */,
@@ -2707,8 +2909,10 @@
5657AB441D108BA9006283EF /* FoundationNSDataTests.swift in Sources */,
5623935D1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
56741EAE1E66A8B3003E422D /* FetchRequestTests.swift in Sources */,
5653EBBB20961FE800F46237 /* AssociationParallelSQLTests.swift in Sources */,
56176C7C1EACCCCB000F3F2B /* FTS5WrapperTokenizerTests.swift in Sources */,
5698AC861DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */,
5653EBBF20961FE800F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */,
5698AC461DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */,
56AF74711D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */,
5674A7281F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */,
@@ -2721,8 +2925,10 @@
56A4CDB61D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */,
5657AB4C1D108BA9006283EF /* FoundationNSNullTests.swift in Sources */,
56AFCAB31CB1ABC800F48B96 /* RecordSubClassTests.swift in Sources */,
5653EBEF20961FE800F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */,
56AFCAB41CB1ABC800F48B96 /* DatabaseValueTests.swift in Sources */,
5657AB3C1D108BA9006283EF /* FoundationDataTests.swift in Sources */,
5653EBD320961FE800F46237 /* AssociationRowScopeSearchTests.swift in Sources */,
5634B10C1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */,
56AFCAB51CB1ABC800F48B96 /* DatabaseQueueReadOnlyTests.swift in Sources */,
56AFCAB61CB1ABC800F48B96 /* DatabaseReaderTests.swift in Sources */,
@@ -2730,9 +2936,12 @@
56AFCAB71CB1ABC800F48B96 /* FetchableRecordTests.swift in Sources */,
56B15D0D1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift in Sources */,
56A5EF151EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */,
5653EBDB20961FE800F46237 /* AssociationChainRowScopesTests.swift in Sources */,
5623931E1DECC02000A6B01F /* RowFetchTests.swift in Sources */,
5653EBCB20961FE800F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */,
56AFCAB81CB1ABC800F48B96 /* DatabaseValueConvertibleFetchTests.swift in Sources */,
5698AC8F1DA389380056AF8C /* FTS3TableBuilderTests.swift in Sources */,
5653EBC720961FE800F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */,
56AFCAB91CB1ABC800F48B96 /* RecordPrimaryKeyRowIDTests.swift in Sources */,
56AFCABA1CB1ABC800F48B96 /* RecordEditedTests.swift in Sources */,
56AFCABB1CB1ABC800F48B96 /* DatabasePoolSchemaCacheTests.swift in Sources */,
@@ -2764,6 +2973,7 @@
56AFCACC1CB1ABC800F48B96 /* DatabaseQueueInMemoryTests.swift in Sources */,
56AFCACD1CB1ABC800F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */,
56AFCACE1CB1ABC800F48B96 /* CGFloatTests.swift in Sources */,
5653EBD720961FE800F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */,
6340BF861E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */,
567A80591D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
562393541DEDFEFB00A6B01F /* EnumeratedCursorTests.swift in Sources */,
+160 -6
View File
@@ -51,6 +51,54 @@
564F9C251F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */; };
564F9C301F07611500877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
564F9C331F07611800877A00 /* DatabaseFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */; };
5653EB4120961F6100F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3720961F6000F46237 /* BelongsToAssociation.swift */; };
5653EB4220961F6100F46237 /* BelongsToAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3720961F6000F46237 /* BelongsToAssociation.swift */; };
5653EB4320961F6100F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3820961F6000F46237 /* HasOneAssociation.swift */; };
5653EB4420961F6100F46237 /* HasOneAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3820961F6000F46237 /* HasOneAssociation.swift */; };
5653EB4520961F6100F46237 /* AssociationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3920961F6000F46237 /* AssociationQuery.swift */; };
5653EB4620961F6100F46237 /* AssociationQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3920961F6000F46237 /* AssociationQuery.swift */; };
5653EB4720961F6100F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3A20961F6000F46237 /* HasManyAssociation.swift */; };
5653EB4820961F6100F46237 /* HasManyAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3A20961F6000F46237 /* HasManyAssociation.swift */; };
5653EB4920961F6100F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3B20961F6000F46237 /* ForeignKey.swift */; };
5653EB4A20961F6100F46237 /* ForeignKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3B20961F6000F46237 /* ForeignKey.swift */; };
5653EB4B20961F6100F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3C20961F6000F46237 /* ForeignKeyRequest.swift */; };
5653EB4C20961F6100F46237 /* ForeignKeyRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3C20961F6000F46237 /* ForeignKeyRequest.swift */; };
5653EB4D20961F6100F46237 /* AssociationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3D20961F6100F46237 /* AssociationRequest.swift */; };
5653EB4E20961F6100F46237 /* AssociationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3D20961F6100F46237 /* AssociationRequest.swift */; };
5653EB4F20961F6100F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3E20961F6100F46237 /* Association.swift */; };
5653EB5020961F6100F46237 /* Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB3E20961F6100F46237 /* Association.swift */; };
5653EB5420961F7D00F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5320961F7D00F46237 /* QueryInterfaceRequest+Association.swift */; };
5653EB5520961F7D00F46237 /* QueryInterfaceRequest+Association.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5320961F7D00F46237 /* QueryInterfaceRequest+Association.swift */; };
5653EB6820961FB200F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5820961FB000F46237 /* AssociationParallelSQLTests.swift */; };
5653EB6920961FB200F46237 /* AssociationParallelSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5820961FB000F46237 /* AssociationParallelSQLTests.swift */; };
5653EB6A20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5920961FB100F46237 /* AssociationBelongsToFetchableRecordTests.swift */; };
5653EB6B20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5920961FB100F46237 /* AssociationBelongsToFetchableRecordTests.swift */; };
5653EB6C20961FB200F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5A20961FB100F46237 /* AssociationParallelDecodableRecordTests.swift */; };
5653EB6D20961FB200F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5A20961FB100F46237 /* AssociationParallelDecodableRecordTests.swift */; };
5653EB6E20961FB200F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5B20961FB100F46237 /* AssociationBelongsToSQLDerivationTests.swift */; };
5653EB6F20961FB200F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5B20961FB100F46237 /* AssociationBelongsToSQLDerivationTests.swift */; };
5653EB7020961FB200F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5C20961FB100F46237 /* AssociationTableAliasTestsSQLTests.swift */; };
5653EB7120961FB200F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5C20961FB100F46237 /* AssociationTableAliasTestsSQLTests.swift */; };
5653EB7220961FB200F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5D20961FB100F46237 /* AssociationHasOneSQLTests.swift */; };
5653EB7320961FB200F46237 /* AssociationHasOneSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5D20961FB100F46237 /* AssociationHasOneSQLTests.swift */; };
5653EB7420961FB200F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5E20961FB100F46237 /* AssociationRowScopeSearchTests.swift */; };
5653EB7520961FB200F46237 /* AssociationRowScopeSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5E20961FB100F46237 /* AssociationRowScopeSearchTests.swift */; };
5653EB7620961FB200F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5F20961FB100F46237 /* AssociationHasOneSQLDerivationTests.swift */; };
5653EB7720961FB200F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB5F20961FB100F46237 /* AssociationHasOneSQLDerivationTests.swift */; };
5653EB7820961FB200F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6020961FB100F46237 /* AssociationChainRowScopesTests.swift */; };
5653EB7920961FB200F46237 /* AssociationChainRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6020961FB100F46237 /* AssociationChainRowScopesTests.swift */; };
5653EB7A20961FB200F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6120961FB100F46237 /* AssociationParallelRowScopesTests.swift */; };
5653EB7B20961FB200F46237 /* AssociationParallelRowScopesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6120961FB100F46237 /* AssociationParallelRowScopesTests.swift */; };
5653EB7C20961FB200F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6220961FB200F46237 /* AssociationBelongsToSQLTests.swift */; };
5653EB7D20961FB200F46237 /* AssociationBelongsToSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6220961FB200F46237 /* AssociationBelongsToSQLTests.swift */; };
5653EB7E20961FB200F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6320961FB200F46237 /* AssociationChainSQLTests.swift */; };
5653EB7F20961FB200F46237 /* AssociationChainSQLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6320961FB200F46237 /* AssociationChainSQLTests.swift */; };
5653EB8020961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6420961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift */; };
5653EB8120961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6420961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift */; };
5653EB8220961FB200F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6520961FB200F46237 /* AssociationBelongsToRowScopeTests.swift */; };
5653EB8320961FB200F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EB6520961FB200F46237 /* AssociationBelongsToRowScopeTests.swift */; };
5653EC082098737400F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC072098737400F46237 /* SQLGenerationContext.swift */; };
5653EC092098737400F46237 /* SQLGenerationContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5653EC072098737400F46237 /* SQLGenerationContext.swift */; };
5657AABB1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; };
5657AABE1D107001006283EF /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AAB81D107001006283EF /* NSData.swift */; };
5657AB111D10899D006283EF /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5657AB0E1D10899D006283EF /* URL.swift */; };
@@ -189,8 +237,6 @@
5698AD3A1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
569A98F82039B716008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98F62039B716008D7DBF /* Fixits-3.0.swift */; };
569A98F92039B716008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98F62039B716008D7DBF /* Fixits-3.0.swift */; };
569B7FA4201C90430069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA2201C90430069DE70 /* Swift4.1.swift */; };
569B7FA5201C90430069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA2201C90430069DE70 /* Swift4.1.swift */; };
569EF0E6200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */; };
569EF0E7200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */; };
56A4CDB31D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */; };
@@ -586,6 +632,30 @@
564E73E7203DA278000C443C /* JoinSupportTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinSupportTests.swift; sourceTree = "<group>"; };
564F9C1D1F069B4E00877A00 /* DatabaseAggregateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseAggregateTests.swift; sourceTree = "<group>"; };
564F9C2C1F075DD200877A00 /* DatabaseFunction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFunction.swift; sourceTree = "<group>"; };
5653EB3720961F6000F46237 /* BelongsToAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BelongsToAssociation.swift; sourceTree = "<group>"; };
5653EB3820961F6000F46237 /* HasOneAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasOneAssociation.swift; sourceTree = "<group>"; };
5653EB3920961F6000F46237 /* AssociationQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationQuery.swift; sourceTree = "<group>"; };
5653EB3A20961F6000F46237 /* HasManyAssociation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasManyAssociation.swift; sourceTree = "<group>"; };
5653EB3B20961F6000F46237 /* ForeignKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKey.swift; sourceTree = "<group>"; };
5653EB3C20961F6000F46237 /* ForeignKeyRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForeignKeyRequest.swift; sourceTree = "<group>"; };
5653EB3D20961F6100F46237 /* AssociationRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRequest.swift; sourceTree = "<group>"; };
5653EB3E20961F6100F46237 /* Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Association.swift; sourceTree = "<group>"; };
5653EB5320961F7D00F46237 /* QueryInterfaceRequest+Association.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "QueryInterfaceRequest+Association.swift"; sourceTree = "<group>"; };
5653EB5820961FB000F46237 /* AssociationParallelSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelSQLTests.swift; sourceTree = "<group>"; };
5653EB5920961FB100F46237 /* AssociationBelongsToFetchableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToFetchableRecordTests.swift; sourceTree = "<group>"; };
5653EB5A20961FB100F46237 /* AssociationParallelDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelDecodableRecordTests.swift; sourceTree = "<group>"; };
5653EB5B20961FB100F46237 /* AssociationBelongsToSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLDerivationTests.swift; sourceTree = "<group>"; };
5653EB5C20961FB100F46237 /* AssociationTableAliasTestsSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationTableAliasTestsSQLTests.swift; sourceTree = "<group>"; };
5653EB5D20961FB100F46237 /* AssociationHasOneSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLTests.swift; sourceTree = "<group>"; };
5653EB5E20961FB100F46237 /* AssociationRowScopeSearchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationRowScopeSearchTests.swift; sourceTree = "<group>"; };
5653EB5F20961FB100F46237 /* AssociationHasOneSQLDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationHasOneSQLDerivationTests.swift; sourceTree = "<group>"; };
5653EB6020961FB100F46237 /* AssociationChainRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainRowScopesTests.swift; sourceTree = "<group>"; };
5653EB6120961FB100F46237 /* AssociationParallelRowScopesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationParallelRowScopesTests.swift; sourceTree = "<group>"; };
5653EB6220961FB200F46237 /* AssociationBelongsToSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToSQLTests.swift; sourceTree = "<group>"; };
5653EB6320961FB200F46237 /* AssociationChainSQLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationChainSQLTests.swift; sourceTree = "<group>"; };
5653EB6420961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToDecodableRecordTests.swift; sourceTree = "<group>"; };
5653EB6520961FB200F46237 /* AssociationBelongsToRowScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AssociationBelongsToRowScopeTests.swift; sourceTree = "<group>"; };
5653EC072098737400F46237 /* SQLGenerationContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLGenerationContext.swift; sourceTree = "<group>"; };
5657AAB81D107001006283EF /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = "<group>"; };
5657AB0E1D10899D006283EF /* URL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
5657AB2F1D108BA9006283EF /* FoundationDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationDataTests.swift; sourceTree = "<group>"; };
@@ -671,7 +741,6 @@
5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = "<group>"; };
5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = "<group>"; };
569A98F62039B716008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = "<group>"; };
569B7FA2201C90430069DE70 /* Swift4.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swift4.1.swift; sourceTree = "<group>"; };
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = "<group>"; };
569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = "<group>"; };
56A238131B9C74A90082EB20 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = "<group>"; };
@@ -991,6 +1060,7 @@
56300B5C1C53C38F005A543B /* QueryInterface */ = {
isa = PBXGroup;
children = (
5653EB5620961F8900F46237 /* Association */,
56B6EF5E208CB746002F0ACB /* ColumnExpressionTests.swift */,
56300B601C53C42C005A543B /* FetchableRecord+QueryInterfaceRequestTests.swift */,
56300B671C53D25E005A543B /* QueryInterfaceExpressionsTests.swift */,
@@ -1007,17 +1077,20 @@
56300B6D1C53F592005A543B /* QueryInterface */ = {
isa = PBXGroup;
children = (
5653EB3620961F6000F46237 /* Association */,
56CEB5401EAA359A00BFAF62 /* Column.swift */,
56CEB5101EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift */,
56CEB5181EAA328900BFAF62 /* FTS5+QueryInterface.swift */,
5605F18C1C6B1A8700235C62 /* QueryInterfaceQuery.swift */,
56300B6F1C53F592005A543B /* QueryInterfaceRequest.swift */,
5653EB5320961F7D00F46237 /* QueryInterfaceRequest+Association.swift */,
5616AAF4207CD59300AC3664 /* RequestProtocols.swift */,
5605F1891C6B1A8700235C62 /* SQLCollatedExpression.swift */,
566475991D97D8A000FF74B8 /* SQLCollection.swift */,
56CEB5411EAA359A00BFAF62 /* SQLExpressible.swift */,
56CEB5421EAA359A00BFAF62 /* SQLExpression.swift */,
56FC98771D969DEF00E3C842 /* SQLExpression+QueryInterface.swift */,
5653EC072098737400F46237 /* SQLGenerationContext.swift */,
56CEB5431EAA359A00BFAF62 /* SQLOrdering.swift */,
56CEB5441EAA359A00BFAF62 /* SQLSelectable.swift */,
566475A11D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift */,
@@ -1042,6 +1115,42 @@
name = DatabaseQueue;
sourceTree = "<group>";
};
5653EB3620961F6000F46237 /* Association */ = {
isa = PBXGroup;
children = (
5653EB3E20961F6100F46237 /* Association.swift */,
5653EB3920961F6000F46237 /* AssociationQuery.swift */,
5653EB3D20961F6100F46237 /* AssociationRequest.swift */,
5653EB3720961F6000F46237 /* BelongsToAssociation.swift */,
5653EB3B20961F6000F46237 /* ForeignKey.swift */,
5653EB3C20961F6000F46237 /* ForeignKeyRequest.swift */,
5653EB3A20961F6000F46237 /* HasManyAssociation.swift */,
5653EB3820961F6000F46237 /* HasOneAssociation.swift */,
);
path = Association;
sourceTree = "<group>";
};
5653EB5620961F8900F46237 /* Association */ = {
isa = PBXGroup;
children = (
5653EB6420961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift */,
5653EB5920961FB100F46237 /* AssociationBelongsToFetchableRecordTests.swift */,
5653EB6520961FB200F46237 /* AssociationBelongsToRowScopeTests.swift */,
5653EB5B20961FB100F46237 /* AssociationBelongsToSQLDerivationTests.swift */,
5653EB6220961FB200F46237 /* AssociationBelongsToSQLTests.swift */,
5653EB6020961FB100F46237 /* AssociationChainRowScopesTests.swift */,
5653EB6320961FB200F46237 /* AssociationChainSQLTests.swift */,
5653EB5F20961FB100F46237 /* AssociationHasOneSQLDerivationTests.swift */,
5653EB5D20961FB100F46237 /* AssociationHasOneSQLTests.swift */,
5653EB5A20961FB100F46237 /* AssociationParallelDecodableRecordTests.swift */,
5653EB6120961FB100F46237 /* AssociationParallelRowScopesTests.swift */,
5653EB5820961FB000F46237 /* AssociationParallelSQLTests.swift */,
5653EB5E20961FB100F46237 /* AssociationRowScopeSearchTests.swift */,
5653EB5C20961FB100F46237 /* AssociationTableAliasTestsSQLTests.swift */,
);
name = Association;
sourceTree = "<group>";
};
5659F4861EA8D94E004A4992 /* Utils */ = {
isa = PBXGroup;
children = (
@@ -1287,7 +1396,6 @@
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
569A98F62039B716008D7DBF /* Fixits-3.0.swift */,
569B7FA2201C90430069DE70 /* Swift4.1.swift */,
);
path = Legacy;
sourceTree = "<group>";
@@ -1699,15 +1807,18 @@
F3BA801B1CFB2886003DC1BA /* CGFloat.swift in Sources */,
566B910E1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
566B91281FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
5653EB4E20961F6100F46237 /* AssociationRequest.swift in Sources */,
56CEB5161EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */,
5659F4951EA8D964004A4992 /* ReadWriteBox.swift in Sources */,
566A842E20413D9A00E50BFD /* DatabaseSnapshot.swift in Sources */,
56CEB4F61EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */,
56BB6EAE1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */,
F3BA801A1CFB2876003DC1BA /* StatementColumnConvertible.swift in Sources */,
5653EB4C20961F6100F46237 /* ForeignKeyRequest.swift in Sources */,
566B91381FA4D3810012D5B0 /* TransactionObserver.swift in Sources */,
56D1215F1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */,
566475D81D981D5E00FF74B8 /* SQLOperators.swift in Sources */,
5653EB4420961F6100F46237 /* HasOneAssociation.swift in Sources */,
56CEB5661EAA359A00BFAF62 /* SQLSelectable.swift in Sources */,
56CEB4FF1EAA2F4D00BFAF62 /* FTS3.swift in Sources */,
5698AD3A1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */,
@@ -1723,13 +1834,14 @@
F3BA80101CFB2876003DC1BA /* DatabaseReader.swift in Sources */,
564F9C331F07611800877A00 /* DatabaseFunction.swift in Sources */,
5659F49D1EA8D989004A4992 /* Pool.swift in Sources */,
569B7FA5201C90430069DE70 /* Swift4.1.swift in Sources */,
5653EB4220961F6100F46237 /* BelongsToAssociation.swift in Sources */,
5674A6F61F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */,
56CEB5511EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
5698AC3C1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
566475D11D981D5E00FF74B8 /* SQLFunctions.swift in Sources */,
5664759F1D97D8A000FF74B8 /* SQLCollection.swift in Sources */,
56E06F171E85906D008AE2A4 /* Fixits-0.102.0.swift in Sources */,
5653EB5520961F7D00F46237 /* QueryInterfaceRequest+Association.swift in Sources */,
F3BA802B1CFB289B003DC1BA /* QueryInterfaceRequest.swift in Sources */,
5698AD171DAAD16F0056AF8C /* FTS5Tokenizer.swift in Sources */,
56F3E7681E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */,
@@ -1756,6 +1868,7 @@
F3BA800C1CFB286F003DC1BA /* DatabaseError.swift in Sources */,
566B91301FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
F3BA80221CFB288C003DC1BA /* NSNumber.swift in Sources */,
5653EB4620961F6100F46237 /* AssociationQuery.swift in Sources */,
F3BA80321CFB28A4003DC1BA /* FetchedRecordsController.swift in Sources */,
5659F48D1EA8D94E004A4992 /* Utils.swift in Sources */,
F3BA80231CFB288C003DC1BA /* NSString.swift in Sources */,
@@ -1774,14 +1887,18 @@
566AD8B71D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
5698AD261DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
F3BA802C1CFB289B003DC1BA /* SQLCollatedExpression.swift in Sources */,
5653EB4A20961F6100F46237 /* ForeignKey.swift in Sources */,
569A98F92039B716008D7DBF /* Fixits-3.0.swift in Sources */,
5653EB4820961F6100F46237 /* HasManyAssociation.swift in Sources */,
F3BA80301CFB289F003DC1BA /* DatabaseMigrator.swift in Sources */,
F3BA80361CFB28A4003DC1BA /* TableRecord.swift in Sources */,
567071F5208A00BE006AD95A /* SQLiteDateParser.swift in Sources */,
F3BA80271CFB2891003DC1BA /* DatabaseValueConvertible+RawRepresentable.swift in Sources */,
5653EC092098737400F46237 /* SQLGenerationContext.swift in Sources */,
566475A71D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */,
5657AABE1D107001006283EF /* NSData.swift in Sources */,
5674A6E61F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */,
5653EB5020961F6100F46237 /* Association.swift in Sources */,
F3BA800E1CFB2876003DC1BA /* DatabaseQueue.swift in Sources */,
F3BA80191CFB2876003DC1BA /* Statement.swift in Sources */,
56CEB5581EAA359A00BFAF62 /* SQLExpression.swift in Sources */,
@@ -1800,6 +1917,7 @@
F3BA80B91CFB2FD1003DC1BA /* DatabasePoolBackupTests.swift in Sources */,
F3BA811E1CFB3063003DC1BA /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */,
562EA8361F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */,
5653EB6D20961FB200F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
F3BA80DD1CFB300E003DC1BA /* DatabaseValueConvertibleSubclassTests.swift in Sources */,
5644488A1EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */,
F3BA80521CFB2B59003DC1BA /* DatabaseQueueSchemaCacheTests.swift in Sources */,
@@ -1818,6 +1936,7 @@
F3BA80511CFB2B59003DC1BA /* DatabaseQueueReleaseMemoryTests.swift in Sources */,
F3BA81221CFB3063003DC1BA /* RecordPrimaryKeyRowIDTests.swift in Sources */,
F3BA80F81CFB3021003DC1BA /* StatementArgumentsTests.swift in Sources */,
5653EB7D20961FB200F46237 /* AssociationBelongsToSQLTests.swift in Sources */,
5698AC0A1D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */,
F3BA80E91CFB3016003DC1BA /* RowAdapterTests.swift in Sources */,
562393371DEDFC5700A6B01F /* AnyCursorTests.swift in Sources */,
@@ -1826,11 +1945,14 @@
5623935E1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
56B14E861D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */,
566AD8CD1D531BEE002EC1A8 /* TableDefinitionTests.swift in Sources */,
5653EB7B20961FB200F46237 /* AssociationParallelRowScopesTests.swift in Sources */,
5698AC871DA380A20056AF8C /* VirtualTableModuleTests.swift in Sources */,
F3BA80D11CFB2FF3003DC1BA /* MutablePersistableRecordTests.swift in Sources */,
5653EB7320961FB200F46237 /* AssociationHasOneSQLTests.swift in Sources */,
F3BA80CF1CFB2FEA003DC1BA /* SchedulingWatchdogTests.swift in Sources */,
F3BA80E71CFB3016003DC1BA /* RowCopiedFromStatementTests.swift in Sources */,
F3BA812A1CFB3063003DC1BA /* RecordSubClassTests.swift in Sources */,
5653EB7F20961FB200F46237 /* AssociationChainSQLTests.swift in Sources */,
6340BF871E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */,
56AF74721D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */,
F3BA80D21CFB2FF3003DC1BA /* PersistableRecordTests.swift in Sources */,
@@ -1858,6 +1980,7 @@
F3BA81151CFB305E003DC1BA /* Record+QueryInterfaceRequestTests.swift in Sources */,
F3BA80DC1CFB300E003DC1BA /* DatabaseValueConvertibleFetchTests.swift in Sources */,
5698AD021DAA8ACB0056AF8C /* FTS5CustomTokenizerTests.swift in Sources */,
5653EB8120961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */,
56B964CA1DA521450002DA19 /* FTS5PatternTests.swift in Sources */,
564E73F4203DA2AD000C443C /* JoinSupportTests.swift in Sources */,
5674A70E1F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */,
@@ -1868,8 +1991,10 @@
F3BA80F11CFB3019003DC1BA /* DatabaseSavepointTests.swift in Sources */,
56ED8A801DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift in Sources */,
F3BA81031CFB303D003DC1BA /* FetchedRecordsControllerTests.swift in Sources */,
5653EB6920961FB200F46237 /* AssociationParallelSQLTests.swift in Sources */,
F3BA80B71CFB2FCD003DC1BA /* DatabaseErrorTests.swift in Sources */,
5698ACCC1DA62A2D0056AF8C /* FTS5TokenizerTests.swift in Sources */,
5653EB6B20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */,
5690C33E1D23E7D200E59934 /* FoundationDateTests.swift in Sources */,
567A805A1D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
5674A7291F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */,
@@ -1882,8 +2007,10 @@
F3BA80BD1CFB2FD1003DC1BA /* DatabasePoolFunctionTests.swift in Sources */,
F3BA81261CFB3063003DC1BA /* RecordCopyTests.swift in Sources */,
56A8C24D1D1918F30096E9D4 /* FoundationNSUUIDTests.swift in Sources */,
5653EB8320961FB200F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */,
5698AC471DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */,
F3BA80D61CFB2FFD003DC1BA /* DatabaseReaderTests.swift in Sources */,
5653EB7520961FB200F46237 /* AssociationRowScopeSearchTests.swift in Sources */,
5698AC9D1DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */,
56A4CDB71D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */,
56CC924A201E058900CB597E /* DropFirstCursorTests.swift in Sources */,
@@ -1891,9 +2018,12 @@
F3BA80F91CFB3021003DC1BA /* UpdateStatementTests.swift in Sources */,
56A5EF161EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */,
F3BA80DA1CFB300E003DC1BA /* DatabaseTimestampTests.swift in Sources */,
5653EB7920961FB200F46237 /* AssociationChainRowScopesTests.swift in Sources */,
F3BA81201CFB3063003DC1BA /* RecordPrimaryKeyMultipleTests.swift in Sources */,
5653EB7120961FB200F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */,
F3BA812B1CFB3063003DC1BA /* RecordWithColumnNameManglingTests.swift in Sources */,
5698ACA51DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */,
5653EB6F20961FB200F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */,
F3BA80B11CFB2FC4003DC1BA /* DatabaseTests.swift in Sources */,
56A8C24E1D1918F30096E9D4 /* FoundationUUIDTests.swift in Sources */,
564F9C251F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */,
@@ -1925,6 +2055,7 @@
F3BA80501CFB2B59003DC1BA /* DatabasePoolSchemaCacheTests.swift in Sources */,
F3BA80BB1CFB2FD1003DC1BA /* DatabasePoolConcurrencyTests.swift in Sources */,
F3BA81141CFB305E003DC1BA /* QueryInterfaceRequestTests.swift in Sources */,
5653EB7720961FB200F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */,
F3BA81271CFB3063003DC1BA /* RecordEditedTests.swift in Sources */,
56FF455D1D2CDA5200F21EF9 /* RecordUniqueIndexTests.swift in Sources */,
F3BA80C51CFB2FD8003DC1BA /* DatabaseQueueBackupTests.swift in Sources */,
@@ -1947,15 +2078,18 @@
F3BA80771CFB2E5C003DC1BA /* CGFloat.swift in Sources */,
566B910B1FA4C3970012D5B0 /* Database+Statements.swift in Sources */,
566B91251FA4CF810012D5B0 /* Database+Schema.swift in Sources */,
5653EB4D20961F6100F46237 /* AssociationRequest.swift in Sources */,
56CEB5131EAA324B00BFAF62 /* FTS3+QueryInterfaceRequest.swift in Sources */,
5659F4921EA8D964004A4992 /* ReadWriteBox.swift in Sources */,
566A842D20413D9A00E50BFD /* DatabaseSnapshot.swift in Sources */,
56CEB4F31EAA2EFA00BFAF62 /* FetchableRecord.swift in Sources */,
56BB6EAB1D3009B100A1CA52 /* SchedulingWatchdog.swift in Sources */,
F3BA80761CFB2E55003DC1BA /* StatementColumnConvertible.swift in Sources */,
5653EB4B20961F6100F46237 /* ForeignKeyRequest.swift in Sources */,
566B91351FA4D3810012D5B0 /* TransactionObserver.swift in Sources */,
56D1215C1ED34978001347D2 /* Fixits-0.109.0.swift in Sources */,
566475D51D981D5E00FF74B8 /* SQLOperators.swift in Sources */,
5653EB4320961F6100F46237 /* HasOneAssociation.swift in Sources */,
56CEB5631EAA359A00BFAF62 /* SQLSelectable.swift in Sources */,
56CEB4FC1EAA2F4D00BFAF62 /* FTS3.swift in Sources */,
5698AD371DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */,
@@ -1971,13 +2105,14 @@
F3BA806C1CFB2E55003DC1BA /* DatabaseReader.swift in Sources */,
564F9C301F07611500877A00 /* DatabaseFunction.swift in Sources */,
5659F49A1EA8D989004A4992 /* Pool.swift in Sources */,
569B7FA4201C90430069DE70 /* Swift4.1.swift in Sources */,
5653EB4120961F6100F46237 /* BelongsToAssociation.swift in Sources */,
5674A6F51F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */,
56CEB54E1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
5698AC391D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
566475CE1D981D5E00FF74B8 /* SQLFunctions.swift in Sources */,
5664759C1D97D8A000FF74B8 /* SQLCollection.swift in Sources */,
56E06F141E859069008AE2A4 /* Fixits-0.102.0.swift in Sources */,
5653EB5420961F7D00F46237 /* QueryInterfaceRequest+Association.swift in Sources */,
F3BA80871CFB2E70003DC1BA /* QueryInterfaceRequest.swift in Sources */,
5698AD161DAAD16F0056AF8C /* FTS5Tokenizer.swift in Sources */,
56F3E7651E67F8C100BF0F01 /* Fixits-0.101.1.swift in Sources */,
@@ -2004,6 +2139,7 @@
F3BA80681CFB2E55003DC1BA /* DatabaseError.swift in Sources */,
566B912D1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
F3BA807E1CFB2E61003DC1BA /* NSNumber.swift in Sources */,
5653EB4520961F6100F46237 /* AssociationQuery.swift in Sources */,
F3BA808E1CFB2E7A003DC1BA /* FetchedRecordsController.swift in Sources */,
5659F48A1EA8D94E004A4992 /* Utils.swift in Sources */,
F3BA807F1CFB2E61003DC1BA /* NSString.swift in Sources */,
@@ -2022,14 +2158,18 @@
566AD8B41D5318F4002EC1A8 /* TableDefinition.swift in Sources */,
5698AD231DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift in Sources */,
F3BA80881CFB2E70003DC1BA /* SQLCollatedExpression.swift in Sources */,
5653EB4920961F6100F46237 /* ForeignKey.swift in Sources */,
569A98F82039B716008D7DBF /* Fixits-3.0.swift in Sources */,
5653EB4720961F6100F46237 /* HasManyAssociation.swift in Sources */,
F3BA808C1CFB2E75003DC1BA /* DatabaseMigrator.swift in Sources */,
F3BA80921CFB2E7A003DC1BA /* TableRecord.swift in Sources */,
567071F4208A00BE006AD95A /* SQLiteDateParser.swift in Sources */,
F3BA80831CFB2E67003DC1BA /* DatabaseValueConvertible+RawRepresentable.swift in Sources */,
5653EC082098737400F46237 /* SQLGenerationContext.swift in Sources */,
566475A41D9810A400FF74B8 /* SQLSelectable+QueryInterface.swift in Sources */,
5657AABB1D107001006283EF /* NSData.swift in Sources */,
5674A6E51F307F0E0095F066 /* DatabaseValueConvertible+Decodable.swift in Sources */,
5653EB4F20961F6100F46237 /* Association.swift in Sources */,
F3BA806A1CFB2E55003DC1BA /* DatabaseQueue.swift in Sources */,
F3BA80751CFB2E55003DC1BA /* Statement.swift in Sources */,
56CEB5551EAA359A00BFAF62 /* SQLExpression.swift in Sources */,
@@ -2048,6 +2188,7 @@
F3BA812C1CFB3064003DC1BA /* RecordMinimalPrimaryKeyRowIDTests.swift in Sources */,
5698AC991DA4B0430056AF8C /* FTS4RecordTests.swift in Sources */,
562EA8321F17B9EB00FA528C /* CompilationSubClassTests.swift in Sources */,
5653EB6C20961FB200F46237 /* AssociationParallelDecodableRecordTests.swift in Sources */,
56A8C2451D1918EF0096E9D4 /* FoundationNSUUIDTests.swift in Sources */,
5657AB591D108BA9006283EF /* FoundationNSStringTests.swift in Sources */,
564448861EF56B1B00DD2861 /* DatabaseAfterNextTransactionCommitTests.swift in Sources */,
@@ -2066,6 +2207,7 @@
56A8C2461D1918EF0096E9D4 /* FoundationUUIDTests.swift in Sources */,
F3BA80F61CFB301E003DC1BA /* StatementColumnConvertibleFetchTests.swift in Sources */,
F3BA80E61CFB3012003DC1BA /* DatabaseFunctionTests.swift in Sources */,
5653EB7C20961FB200F46237 /* AssociationBelongsToSQLTests.swift in Sources */,
5698ACDA1DA925430056AF8C /* RowTestCase.swift in Sources */,
F3BA811D1CFB305F003DC1BA /* TableRecord+QueryInterfaceRequestTests.swift in Sources */,
F3BA80AD1CFB2FA6003DC1BA /* DataMemoryTests.swift in Sources */,
@@ -2074,11 +2216,14 @@
567A80561D41350C00C7DCEC /* IndexInfoTests.swift in Sources */,
F3BA81301CFB3064003DC1BA /* RecordPrimaryKeyRowIDTests.swift in Sources */,
56DAA2D51DE99DAB006E10C8 /* DatabaseCursorTests.swift in Sources */,
5653EB7A20961FB200F46237 /* AssociationParallelRowScopesTests.swift in Sources */,
F3BA80FB1CFB3021003DC1BA /* StatementArgumentsTests.swift in Sources */,
F3BA80EE1CFB3017003DC1BA /* RowAdapterTests.swift in Sources */,
5653EB7220961FB200F46237 /* AssociationHasOneSQLTests.swift in Sources */,
F3BA80D31CFB2FF4003DC1BA /* MutablePersistableRecordTests.swift in Sources */,
562393751DEE104400A6B01F /* MapCursorTests.swift in Sources */,
F3BA80D01CFB2FEC003DC1BA /* SchedulingWatchdogTests.swift in Sources */,
5653EB7E20961FB200F46237 /* AssociationChainSQLTests.swift in Sources */,
F3BA80EC1CFB3017003DC1BA /* RowCopiedFromStatementTests.swift in Sources */,
F3BA80D41CFB2FF4003DC1BA /* PersistableRecordTests.swift in Sources */,
6340BF831E5E3F7900832805 /* RecordPersistenceConflictPolicy.swift in Sources */,
@@ -2106,6 +2251,7 @@
F3BA811C1CFB305F003DC1BA /* QueryInterfaceExpressionsTests.swift in Sources */,
5698ACD11DA8C2620056AF8C /* RecordPrimaryKeyHiddenRowIDTests.swift in Sources */,
562205FB1E420E49005860AC /* DatabasePoolSchemaCacheTests.swift in Sources */,
5653EB8020961FB200F46237 /* AssociationBelongsToDecodableRecordTests.swift in Sources */,
5657AB611D108BA9006283EF /* FoundationNSURLTests.swift in Sources */,
564E73F3203DA2AC000C443C /* JoinSupportTests.swift in Sources */,
5674A70C1F3087710095F066 /* DatabaseValueConvertibleEncodableTests.swift in Sources */,
@@ -2116,8 +2262,10 @@
F3BA80F01CFB3017003DC1BA /* FetchableRecordTests.swift in Sources */,
5657AB491D108BA9006283EF /* FoundationNSNullTests.swift in Sources */,
F3BA80E21CFB300F003DC1BA /* DatabaseValueConvertibleFetchTests.swift in Sources */,
5653EB6820961FB200F46237 /* AssociationParallelSQLTests.swift in Sources */,
F3BA80F21CFB301A003DC1BA /* DatabaseSavepointTests.swift in Sources */,
F3BA80B81CFB2FCD003DC1BA /* DatabaseErrorTests.swift in Sources */,
5653EB6A20961FB200F46237 /* AssociationBelongsToFetchableRecordTests.swift in Sources */,
5698AC061D9B9FCF0056AF8C /* QueryInterfaceExtensibilityTests.swift in Sources */,
F3BA80FA1CFB3021003DC1BA /* SelectStatementTests.swift in Sources */,
5674A7271F30A9090095F066 /* FetchableRecordDecodableTests.swift in Sources */,
@@ -2130,8 +2278,10 @@
F3BA80C01CFB2FD2003DC1BA /* DatabasePoolCollationTests.swift in Sources */,
5698ACA11DA4B0430056AF8C /* FTS4TableBuilderTests.swift in Sources */,
F3BA80C31CFB2FD2003DC1BA /* DatabasePoolFunctionTests.swift in Sources */,
5653EB8220961FB200F46237 /* AssociationBelongsToRowScopeTests.swift in Sources */,
F3BA80D51CFB2FFB003DC1BA /* DatabaseReaderTests.swift in Sources */,
F3BA81321CFB3064003DC1BA /* RecordPrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */,
5653EB7420961FB200F46237 /* AssociationRowScopeSearchTests.swift in Sources */,
5623935A1DEE013C00A6B01F /* FilterCursorTests.swift in Sources */,
F3BA80FC1CFB3021003DC1BA /* UpdateStatementTests.swift in Sources */,
56CC9249201E058900CB597E /* DropFirstCursorTests.swift in Sources */,
@@ -2139,9 +2289,12 @@
F3BA80E01CFB300F003DC1BA /* DatabaseTimestampTests.swift in Sources */,
56A5EF121EF7F20B00F03071 /* ForeignKeyInfoTests.swift in Sources */,
F3BA80B21CFB2FC5003DC1BA /* DatabaseTests.swift in Sources */,
5653EB7820961FB200F46237 /* AssociationChainRowScopesTests.swift in Sources */,
F3BA80AE1CFB2FA6003DC1BA /* DatabaseRegionTests.swift in Sources */,
5653EB7020961FB200F46237 /* AssociationTableAliasTestsSQLTests.swift in Sources */,
F3BA81311CFB3064003DC1BA /* RecordPrimaryKeySingleTests.swift in Sources */,
5698AC431DA2BED90056AF8C /* FTS3PatternTests.swift in Sources */,
5653EB6E20961FB200F46237 /* AssociationBelongsToSQLDerivationTests.swift in Sources */,
F3BA80E11CFB300F003DC1BA /* DatabaseValueConversionTests.swift in Sources */,
5623931B1DECC02000A6B01F /* RowFetchTests.swift in Sources */,
564F9C211F069B4E00877A00 /* DatabaseAggregateTests.swift in Sources */,
@@ -2173,6 +2326,7 @@
F3BA811A1CFB305F003DC1BA /* Record+QueryInterfaceRequestTests.swift in Sources */,
F3BA81111CFB3057003DC1BA /* StatementArguments+FoundationTests.swift in Sources */,
F3BA81371CFB3064003DC1BA /* RecordInitializersTests.swift in Sources */,
5653EB7620961FB200F46237 /* AssociationHasOneSQLDerivationTests.swift in Sources */,
F3BA80C91CFB2FD8003DC1BA /* DatabaseQueueBackupTests.swift in Sources */,
56AF746E1D41FB9C005E9FF3 /* DatabaseValueConvertibleEscapingTests.swift in Sources */,
56ED8A7F1DAB8D6800BD0ABC /* FTS5WrapperTokenizerTests.swift in Sources */,
+2 -16
View File
@@ -44,26 +44,12 @@ XCPRETTY_PATH := $(shell command -v xcpretty 2> /dev/null)
# xcodebuild actions to run test targets
TEST_ACTIONS = clean build build-for-testing test-without-building
# xcodebuild destination to run tests on iOS 8.1 (requires a pre-installed simulator)
MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=8.1"
# When adding support for an Xcode version, look for available devices with `instruments -s devices`
ifeq ($(XCODEVERSION),9.3)
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.3"
else ifeq ($(XCODEVERSION),9.2)
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.2"
else ifeq ($(XCODEVERSION),9.1)
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.1"
else ifeq ($(XCODEVERSION),9.0)
ifeq ($(XCODEVERSION_PATCH),1)
# Xcode 9.0.1: @groue's personal computer
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.0.1"
else
# Xcode 9.0: Travis https://docs.travis-ci.com/user/reference/osx/#Xcode-9.0
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.0"
endif
MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=9.0"
else
# Xcode < 9.0 is not supported
# Swift 4.1 required: Xcode < 9.3 is not supported
endif
# If xcpretty is available, use it for xcodebuild output
+352 -354
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -27,6 +27,9 @@ GRDB 3.0
- sync
- ?
- [ ] filter(rowid:), filter(rowids:)
- [ ] Fix matchingRowIds
- [ ] Simplify Range extensions for Swift 4.1
- [ ] https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/6
- [ ] hide ScopeAdapter(base, scopes), because base.addingScopes has a better implementation
Not sure
@@ -0,0 +1,111 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
private struct Team: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "teams"
var id: Int64
var name: String
}
private struct Player: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "players"
static let team = Player.belongsTo(Team.self)
var id: Int64
var teamId: Int64?
var name: String
}
private struct PlayerWithRequiredTeam: Decodable, FetchableRecord {
var player: Player
var team: Team
static let team = Player.team.forKey(CodingKeys.team)
}
private struct PlayerWithOptionalTeam: Decodable, FetchableRecord {
var player: Player
var team: Team?
static let team = Player.team.forKey(CodingKeys.team)
}
/// Test support for Decodable records
class AssociationBelongsToDecodableRecordTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "teams") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
}
try db.create(table: "players") { t in
t.column("id", .integer).primaryKey()
t.column("teamId", .integer).references("teams")
t.column("name", .text)
}
try Team(id: 1, name: "Reds").insert(db)
try Player(id: 1, teamId: 1, name: "Arthur").insert(db)
try Player(id: 2, teamId: nil, name: "Barbara").insert(db)
}
}
func testIncludingRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player
.including(required: PlayerWithRequiredTeam.team)
.asRequest(of: PlayerWithRequiredTeam.self)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(records.count, 1)
XCTAssertEqual(records[0].player.id, 1)
XCTAssertEqual(records[0].player.teamId, 1)
XCTAssertEqual(records[0].player.name, "Arthur")
XCTAssertEqual(records[0].team.id, 1)
XCTAssertEqual(records[0].team.name, "Reds")
}
func testIncludingOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player
.including(optional: PlayerWithOptionalTeam.team)
.asRequest(of: PlayerWithOptionalTeam.self)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(records.count, 2)
XCTAssertEqual(records[0].player.id, 1)
XCTAssertEqual(records[0].player.teamId, 1)
XCTAssertEqual(records[0].player.name, "Arthur")
XCTAssertEqual(records[0].team!.id, 1)
XCTAssertEqual(records[0].team!.name, "Reds")
XCTAssertEqual(records[1].player.id, 2)
XCTAssertNil(records[1].player.teamId)
XCTAssertEqual(records[1].player.name, "Barbara")
XCTAssertNil(records[1].team)
}
func testJoiningRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.joining(required: Player.team)
let players = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(players.count, 1)
XCTAssertEqual(players[0].id, 1)
XCTAssertEqual(players[0].teamId, 1)
XCTAssertEqual(players[0].name, "Arthur")
}
func testJoiningsOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.joining(optional: Player.team)
let players = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(players.count, 2)
XCTAssertEqual(players[0].id, 1)
XCTAssertEqual(players[0].teamId, 1)
XCTAssertEqual(players[0].name, "Arthur")
XCTAssertEqual(players[1].id, 2)
XCTAssertNil(players[1].teamId)
XCTAssertEqual(players[1].name, "Barbara")
}
}
@@ -0,0 +1,120 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
private struct Team: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "teams"
var id: Int64
var name: String
}
private struct Player: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "players"
static let teamScope = "team"
static let team = Player.belongsTo(Team.self, key: teamScope)
var id: Int64
var teamId: Int64?
var name: String
}
private struct PlayerWithRequiredTeam: FetchableRecord {
var player: Player
var team: Team
init(row: Row) {
player = Player(row: row)
team = row[Player.teamScope]
}
}
private struct PlayerWithOptionalTeam: FetchableRecord {
var player: Player
var team: Team?
init(row: Row) {
player = Player(row: row)
team = row[Player.teamScope]
}
}
/// Test support for FetchableRecord records
class AssociationBelongsToFetchableRecordTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "teams") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
}
try db.create(table: "players") { t in
t.column("id", .integer).primaryKey()
t.column("teamId", .integer).references("teams")
t.column("name", .text)
}
try Team(id: 1, name: "Reds").insert(db)
try Player(id: 1, teamId: 1, name: "Arthur").insert(db)
try Player(id: 2, teamId: nil, name: "Barbara").insert(db)
}
}
func testIncludingRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player
.including(required: Player.team)
.asRequest(of: PlayerWithRequiredTeam.self)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(records.count, 1)
XCTAssertEqual(records[0].player.id, 1)
XCTAssertEqual(records[0].player.teamId, 1)
XCTAssertEqual(records[0].player.name, "Arthur")
XCTAssertEqual(records[0].team.id, 1)
XCTAssertEqual(records[0].team.name, "Reds")
}
func testIncludingOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player
.including(optional: Player.team)
.asRequest(of: PlayerWithOptionalTeam.self)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(records.count, 2)
XCTAssertEqual(records[0].player.id, 1)
XCTAssertEqual(records[0].player.teamId, 1)
XCTAssertEqual(records[0].player.name, "Arthur")
XCTAssertEqual(records[0].team!.id, 1)
XCTAssertEqual(records[0].team!.name, "Reds")
XCTAssertEqual(records[1].player.id, 2)
XCTAssertNil(records[1].player.teamId)
XCTAssertEqual(records[1].player.name, "Barbara")
XCTAssertNil(records[1].team)
}
func testJoiningRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.joining(required: Player.team)
let players = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(players.count, 1)
XCTAssertEqual(players[0].id, 1)
XCTAssertEqual(players[0].teamId, 1)
XCTAssertEqual(players[0].name, "Arthur")
}
func testJoiningsOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.joining(optional: Player.team)
let players = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(players.count, 2)
XCTAssertEqual(players[0].id, 1)
XCTAssertEqual(players[0].teamId, 1)
XCTAssertEqual(players[0].name, "Arthur")
XCTAssertEqual(players[1].id, 2)
XCTAssertNil(players[1].teamId)
XCTAssertEqual(players[1].name, "Barbara")
}
}
@@ -0,0 +1,131 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
private struct Team: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "teams"
var id: Int64
var name: String
}
private struct Player: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "players"
static let defaultTeam = belongsTo(Team.self)
static let customTeam = belongsTo(Team.self, key: "customTeam")
var id: Int64
var teamId: Int64?
var name: String
}
/// Test row scopes
class AssociationBelongsToRowScopeTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "teams") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
}
try db.create(table: "players") { t in
t.column("id", .integer).primaryKey()
t.column("teamId", .integer).references("teams")
t.column("name", .text)
}
try Team(id: 1, name: "Reds").insert(db)
try Player(id: 1, teamId: 1, name: "Arthur").insert(db)
try Player(id: 2, teamId: nil, name: "Barbara").insert(db)
}
}
func testDefaultScopeIncludingRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.including(required: Player.defaultTeam)
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"])
XCTAssertEqual(Set(rows[0].scopes.names), ["teams"])
XCTAssertEqual(rows[0].scopes["teams"]!, ["id":1, "name":"Reds"])
}
func testDefaultScopeIncludingOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.including(optional: Player.defaultTeam)
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"])
XCTAssertEqual(Set(rows[0].scopes.names), ["teams"])
XCTAssertEqual(rows[0].scopes["teams"]!, ["id":1, "name":"Reds"])
XCTAssertEqual(rows[1].unscoped, ["id":2, "teamId":nil, "name":"Barbara"])
XCTAssertEqual(Set(rows[1].scopes.names), ["teams"])
XCTAssertEqual(rows[1].scopes["teams"]!, ["id":nil, "name":nil])
}
func testDefaultScopeJoiningRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.joining(required: Player.defaultTeam)
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
}
func testDefaultScopeJoiningOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.joining(optional: Player.defaultTeam)
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
XCTAssertEqual(rows[1].unscoped, ["id":2, "teamId":nil, "name":"Barbara"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
}
func testCustomScopeIncludingRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.including(required: Player.customTeam)
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"])
XCTAssertEqual(Set(rows[0].scopes.names), ["customTeam"])
XCTAssertEqual(rows[0].scopes["customTeam"]!, ["id":1, "name":"Reds"])
}
func testCustomScopeIncludingOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.including(optional: Player.customTeam)
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"])
XCTAssertEqual(Set(rows[0].scopes.names), ["customTeam"])
XCTAssertEqual(rows[0].scopes["customTeam"]!, ["id":1, "name":"Reds"])
XCTAssertEqual(rows[1].unscoped, ["id":2, "teamId":nil, "name":"Barbara"])
XCTAssertEqual(Set(rows[1].scopes.names), ["customTeam"])
XCTAssertEqual(rows[1].scopes["customTeam"]!, ["id":nil, "name":nil])
}
func testCustomScopeJoiningRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.joining(required: Player.customTeam)
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
}
func testCustomScopeJoiningOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = Player.joining(optional: Player.customTeam)
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "teamId":1, "name":"Arthur"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
XCTAssertEqual(rows[1].unscoped, ["id":2, "teamId":nil, "name":"Barbara"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
}
}
@@ -0,0 +1,406 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
// A -> B
private struct A : TableRecord {
static let databaseTableName = "a"
static let b = belongsTo(B.self)
static let restrictedB = belongsTo(RestrictedB.self)
static let extendedB = belongsTo(ExtendedB.self)
}
private struct B : TableRecord {
static let a = hasOne(A.self)
static let databaseTableName = "b"
}
private struct RestrictedB : TableRecord {
static let databaseTableName = "b"
static let databaseSelection: [SQLSelectable] = [Column("name")]
}
private struct ExtendedB : TableRecord {
static let databaseTableName = "b"
static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
}
/// Test SQL generation
class AssociationBelongsToSQLDerivationTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "b") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
}
try db.create(table: "a") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
}
}
}
func testDefaultSelection() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid")
""")
try assertEqualSQL(db, A.including(required: A.restrictedB), """
SELECT "a".*, "b"."name" \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid")
""")
try assertEqualSQL(db, A.including(required: A.extendedB), """
SELECT "a".*, "b".*, "b"."rowid" \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid")
""")
}
}
func testCustomSelection() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
do {
let request = A.including(required: A.b
.select(Column("name")))
try assertEqualSQL(db, request, """
SELECT "a".*, "b"."name" \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid")
""")
}
do {
let request = A.including(required: A.b
.select(
AllColumns(),
Column.rowID))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".*, "b"."rowid" \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid")
""")
}
do {
let aAlias = TableAlias()
let request = A
.aliased(aAlias)
.including(required: A.b
.select(
Column("name"),
(Column("id") + aAlias[Column("id")]).aliased("foo")))
try assertEqualSQL(db, request, """
SELECT "a".*, "b"."name", ("b"."id" + "a"."id") AS "foo" \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid")
""")
}
}
}
func testFilteredAssociationImpactsJoinOnClause() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
do {
let request = A.including(required: A.b.filter(Column("name") != nil))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."id" = "a"."bid") AND ("b"."name" IS NOT NULL))
""")
}
do {
let request = A.including(required: A.b.filter(key: 1))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."id" = "a"."bid") AND ("b"."id" = 1))
""")
}
do {
let request = A.including(required: A.b.filter(keys: [1, 2, 3]))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."id" = "a"."bid") AND ("b"."id" IN (1, 2, 3)))
""")
}
do {
let request = A.including(required: A.b.filter(key: ["id": 1]))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."id" = "a"."bid") AND ("b"."id" = 1))
""")
}
do {
let request = A.including(required: A.b.filter(keys: [["id": 1], ["id": 2]]))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."id" = "a"."bid") AND (("b"."id" = 1) OR ("b"."id" = 2)))
""")
}
do {
let bAlias = TableAlias(name: "customB")
let request = A.including(required: A.b
.aliased(bAlias)
.filter(sql: "customB.name = ?", arguments: ["foo"]))
try assertEqualSQL(db, request, """
SELECT "a".*, "customB".* \
FROM "a" \
JOIN "b" "customB" ON (("customB"."id" = "a"."bid") AND (customB.name = 'foo'))
""")
}
}
}
func testFilterAssociationInWhereClause() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let bAlias = TableAlias()
let request = A
.including(required: A.b.aliased(bAlias))
.filter(bAlias[Column("name")] != nil)
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
WHERE ("b"."name" IS NOT NULL)
""")
}
}
func testAssociationOrderBubbleUp() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let aBase = A.all().aliased(TableAlias(name: "a"))
let abBase = A.b.aliased(TableAlias(name: "ab"))
let abaBase = B.a.aliased(TableAlias(name: "aba"))
let aTransforms = [
{ (r: QueryInterfaceRequest<A>) in return r },
{ (r: QueryInterfaceRequest<A>) in return r.order(Column("id")) },
{ (r: QueryInterfaceRequest<A>) in return r.order(Column("id")).reversed() },
]
let abTransforms = [
{ (r: BelongsToAssociation<A, B>) in return r },
{ (r: BelongsToAssociation<A, B>) in return r.order(Column("name"), Column("id").desc) },
{ (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).order(Column("id").desc) },
{ (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).reversed() },
{ (r: BelongsToAssociation<A, B>) in return r.reversed() },
]
let abaTransforms = [
{ (r: HasOneAssociation<B, A>) in return r },
{ (r: HasOneAssociation<B, A>) in return r.order(Column("id")) },
{ (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() },
]
var sqls: [String] = []
for aTransform in aTransforms {
for abTransform in abTransforms {
for abaTransform in abaTransforms {
let request = aTransform(aBase)
.including(required: abTransform(abBase)
.including(required: abaTransform(abaBase)))
let sqlRequest = try SQLRequest(db, request: request)
sqls.append(sqlRequest.sql)
}
}
}
let prefix = """
SELECT "a".*, "ab".*, "aba".* \
FROM "a" \
JOIN "b" "ab" ON ("ab"."id" = "a"."bid") \
JOIN "a" "aba" ON ("aba"."bid" = "ab"."id")
"""
let orderClauses = sqls.map { sql -> String in
let prefixEndIndex = sql.index(sql.startIndex, offsetBy: prefix.count)
return String(sql.suffix(from: prefixEndIndex))
}
XCTAssertEqual(orderClauses, [
// a: { (r: QueryInterfaceRequest<A>) in return r },
// ab: { (r: BelongsToAssociation<A, B>) in return r }
// aba: { (r: HasOneAssociation<B, A>) in return r }
"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name"), Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"ab\".\"name\", \"ab\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"ab\".\"name\", \"ab\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"ab\".\"name\", \"ab\".\"id\" DESC, \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).order(Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"ab\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"ab\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"ab\".\"id\" DESC, \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"ab\".\"name\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"ab\".\"name\" DESC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"ab\".\"name\" DESC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"aba\".\"id\"",
// a: { (r: QueryInterfaceRequest<A>) in return r.order(Column("id")) },
// ab: { (r: BelongsToAssociation<A, B>) in return r }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name"), Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\", \"ab\".\"name\", \"ab\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"ab\".\"name\", \"ab\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"ab\".\"name\", \"ab\".\"id\" DESC, \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).order(Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\", \"ab\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"ab\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"ab\".\"id\" DESC, \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\", \"ab\".\"name\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"ab\".\"name\" DESC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"ab\".\"name\" DESC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"aba\".\"id\"",
// a: { (r: QueryInterfaceRequest<A>) in return r.order(Column("id")).reversed() }
// ab: { (r: BelongsToAssociation<A, B>) in return r }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name"), Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\" DESC, \"ab\".\"id\" ASC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\" DESC, \"ab\".\"id\" ASC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\" DESC, \"ab\".\"id\" ASC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).order(Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"id\" ASC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"id\" ASC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"id\" ASC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\", \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\", \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"aba\".\"id\" DESC",
])
}
}
// TODO: Test if and only if we really want to build an association from any request
// func testAssociationFromRequest() throws {
// let dbQueue = try makeDatabaseQueue()
// try dbQueue.inDatabase { db in
// do {
// let bRequest = B
// .filter(Column("name") != nil)
// .order(Column("id"))
// let association = A.belongsTo(bRequest)
// let request = A.including(required: association)
// try assertEqualSQL(db, request, """
// SELECT "a".*, "b".* \
// FROM "a" \
// JOIN "b" ON (("b"."id" = "a"."bid") AND ("b"."name" IS NOT NULL)) \
// ORDER BY "b"."id"
// """)
// }
// do {
// let bRequest = RestrictedB
// .filter(Column("name") != nil)
// .order(Column("id"))
// let association = A.belongsTo(bRequest)
// let request = A.including(required: association)
// try assertEqualSQL(db, request, """
// SELECT "a".*, "b"."name" \
// FROM "a" \
// JOIN "b" ON (("b"."id" = "a"."bid") AND ("b"."name" IS NOT NULL)) \
// ORDER BY "b"."id"
// """)
// }
// do {
// let bRequest = ExtendedB
// .select([Column("name")])
// .filter(Column("name") != nil)
// .order(Column("id"))
// let association = A.belongsTo(bRequest)
// let request = A.including(required: association)
// try assertEqualSQL(db, request, """
// SELECT "a".*, "b"."name" \
// FROM "a" \
// JOIN "b" ON (("b"."id" = "a"."bid") AND ("b"."name" IS NOT NULL)) \
// ORDER BY "b"."id"
// """)
// }
// }
// }
}
@@ -0,0 +1,771 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
/// Test SQL generation
class AssociationBelongsToSQLTests: GRDBTestCase {
func testSingleColumnNoForeignKeyNoPrimaryKey() throws {
struct Child : TableRecord, MutablePersistableRecord {
static let databaseTableName = "children"
func encode(to container: inout PersistenceContainer) {
container["parentId"] = 1
}
}
struct Parent : TableRecord {
static let databaseTableName = "parents"
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("id", .integer)
}
try db.create(table: "children") { t in
t.column("parentId", .integer)
}
}
try dbQueue.inDatabase { db in
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentId")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."rowid" = "children"."parentId")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."rowid" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."rowid" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."rowid" = "children"."parentId")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"rowid\" = 1)")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentId")], to: [Column("id")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 1)")
}
}
}
func testSingleColumnNoForeignKey() throws {
struct Child : TableRecord, MutablePersistableRecord {
static let databaseTableName = "children"
func encode(to container: inout PersistenceContainer) {
container["parentId"] = 1
}
}
struct Parent : TableRecord {
static let databaseTableName = "parents"
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "children") { t in
t.column("parentId", .integer)
}
}
try dbQueue.inDatabase { db in
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentId")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 1)")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentId")], to: [Column("id")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 1)")
}
}
}
func testSingleColumnSingleForeignKey() throws {
struct Child : TableRecord, MutablePersistableRecord {
static let databaseTableName = "children"
func encode(to container: inout PersistenceContainer) {
container["parentId"] = 1
}
}
struct Parent : TableRecord {
static let databaseTableName = "parents"
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "children") { t in
t.column("parentId", .integer).references("parents")
}
}
try dbQueue.inDatabase { db in
do {
let association = Child.belongsTo(Parent.self)
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 1)")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentId")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 1)")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentId")], to: [Column("id")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parentId")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 1)")
}
}
}
func testSingleColumnSeveralForeignKeys() throws {
struct Child : TableRecord, MutablePersistableRecord {
static let databaseTableName = "children"
func encode(to container: inout PersistenceContainer) {
container["parent1Id"] = 1
container["parent2Id"] = 2
}
}
struct Parent : TableRecord {
static let databaseTableName = "parents"
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "children") { t in
t.column("parent1Id", .integer).references("parents")
t.column("parent2Id", .integer).references("parents")
}
}
try dbQueue.inDatabase { db in
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parent1Id")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parent1Id")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parent1Id")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parent1Id")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parent1Id")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 1)")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parent1Id")], to: [Column("id")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parent1Id")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parent1Id")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parent1Id")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parent1Id")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 1)")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parent2Id")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parent2Id")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parent2Id")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parent2Id")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parent2Id")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 2)")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parent2Id")], to: [Column("id")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parent2Id")
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parent2Id")
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON ("parents"."id" = "children"."parent2Id")
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON ("parents"."id" = "children"."parent2Id")
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE (\"id\" = 2)")
}
}
}
func testCompoundColumnNoForeignKeyNoPrimaryKey() throws {
struct Child : TableRecord, MutablePersistableRecord {
static let databaseTableName = "children"
func encode(to container: inout PersistenceContainer) {
container["parentA"] = 1
container["parentB"] = 2
}
}
struct Parent : TableRecord {
static let databaseTableName = "parents"
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("a", .integer)
t.column("b", .integer)
}
try db.create(table: "children") { t in
t.column("parentA", .integer)
t.column("parentB", .integer)
}
}
try dbQueue.inDatabase { db in
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 1) AND (\"b\" = 2))")
}
}
}
func testCompoundColumnNoForeignKey() throws {
struct Child : TableRecord, MutablePersistableRecord {
static let databaseTableName = "children"
func encode(to container: inout PersistenceContainer) {
container["parentA"] = 1
container["parentB"] = 2
}
}
struct Parent : TableRecord {
static let databaseTableName = "parents"
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("a", .integer)
t.column("b", .integer)
t.primaryKey(["a", "b"])
}
try db.create(table: "children") { t in
t.column("parentA", .integer)
t.column("parentB", .integer)
}
}
try dbQueue.inDatabase { db in
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentA"), Column("parentB")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children\".\"parentB\"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children\".\"parentB\"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 1) AND (\"b\" = 2))")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 1) AND (\"b\" = 2))")
}
}
}
func testCompoundColumnSingleForeignKey() throws {
struct Child : TableRecord, MutablePersistableRecord {
static let databaseTableName = "children"
func encode(to container: inout PersistenceContainer) {
container["parentA"] = 1
container["parentB"] = 2
}
}
struct Parent : TableRecord {
static let databaseTableName = "parents"
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("a", .integer)
t.column("b", .integer)
t.primaryKey(["a", "b"])
}
try db.create(table: "children") { t in
t.column("parentA", .integer)
t.column("parentB", .integer)
t.foreignKey(["parentA", "parentB"], references: "parents")
}
}
try dbQueue.inDatabase { db in
do {
let association = Child.belongsTo(Parent.self)
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 1) AND (\"b\" = 2))")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentA"), Column("parentB")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 1) AND (\"b\" = 2))")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parentA") AND ("parents"."b" = "children"."parentB"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 1) AND (\"b\" = 2))")
}
}
}
func testCompoundColumnSeveralForeignKeys() throws {
struct Child : TableRecord, MutablePersistableRecord {
static let databaseTableName = "children"
func encode(to container: inout PersistenceContainer) {
container["parent1A"] = 1
container["parent1B"] = 2
container["parent2A"] = 3
container["parent2B"] = 4
}
}
struct Parent : TableRecord {
static let databaseTableName = "parents"
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("a", .integer)
t.column("b", .integer)
t.primaryKey(["a", "b"])
}
try db.create(table: "children") { t in
t.column("parent1A", .integer)
t.column("parent1B", .integer)
t.column("parent2A", .integer)
t.column("parent2B", .integer)
t.foreignKey(["parent1A", "parent1B"], references: "parents")
t.foreignKey(["parent2A", "parent2B"], references: "parents")
}
}
try dbQueue.inDatabase { db in
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parent1A"), Column("parent1B")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parent1A") AND ("parents"."b" = "children"."parent1B"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parent1A") AND ("parents"."b" = "children"."parent1B"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parent1A") AND ("parents"."b" = "children"."parent1B"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parent1A") AND ("parents"."b" = "children"."parent1B"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 1) AND (\"b\" = 2))")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parent1A"), Column("parent1B")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parent1A") AND ("parents"."b" = "children"."parent1B"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parent1A") AND ("parents"."b" = "children"."parent1B"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parent1A") AND ("parents"."b" = "children"."parent1B"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parent1A") AND ("parents"."b" = "children"."parent1B"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 1) AND (\"b\" = 2))")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parent2A"), Column("parent2B")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parent2A") AND ("parents"."b" = "children"."parent2B"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parent2A") AND ("parents"."b" = "children"."parent2B"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parent2A") AND ("parents"."b" = "children"."parent2B"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parent2A") AND ("parents"."b" = "children"."parent2B"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 3) AND (\"b\" = 4))")
}
do {
let association = Child.belongsTo(Parent.self, using: ForeignKey([Column("parent2A"), Column("parent2B")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Child.including(required: association), """
SELECT "children".*, "parents".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parent2A") AND ("parents"."b" = "children"."parent2B"))
""")
try assertEqualSQL(db, Child.including(optional: association), """
SELECT "children".*, "parents".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parent2A") AND ("parents"."b" = "children"."parent2B"))
""")
try assertEqualSQL(db, Child.joining(required: association), """
SELECT "children".* \
FROM "children" \
JOIN "parents" ON (("parents"."a" = "children"."parent2A") AND ("parents"."b" = "children"."parent2B"))
""")
try assertEqualSQL(db, Child.joining(optional: association), """
SELECT "children".* \
FROM "children" \
LEFT JOIN "parents" ON (("parents"."a" = "children"."parent2A") AND ("parents"."b" = "children"."parent2B"))
""")
try assertEqualSQL(db, Child().request(for: association), "SELECT * FROM \"parents\" WHERE ((\"a\" = 3) AND (\"b\" = 4))")
}
}
}
func testForeignKeyDefinitionFromColumn() {
// This test pass if code compiles
struct Parent : TableRecord {
static let databaseTableName = "parents"
enum Columns {
static let id = Column("id")
}
}
struct Child : TableRecord {
static let databaseTableName = "children"
enum Columns {
static let parentId = Column("parentId")
}
enum ForeignKeys {
static let parent1 = ForeignKey([Columns.parentId])
static let parent2 = ForeignKey([Columns.parentId], to: [Parent.Columns.id])
}
static let parent1 = belongsTo(Parent.self, using: ForeignKeys.parent1)
static let parent2 = belongsTo(Parent.self, using: ForeignKeys.parent2)
}
}
}
@@ -0,0 +1,694 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
// A -> B <- C -> D
private struct A: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "a"
static let defaultB = belongsTo(B.self)
var id: Int64
var bid: Int64?
var name: String
}
private struct B: Codable, FetchableRecord, PersistableRecord {
static let defaultC = hasOne(C.self)
static let databaseTableName = "b"
var id: Int64
var name: String
}
private struct C: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "c"
static let defaultD = belongsTo(D.self)
var id: Int64
var bid: Int64?
var did: Int64?
var name: String
}
private struct D: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "d"
var id: Int64
var name: String
}
/// Test row scopes
class AssociationChainRowScopesTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "b") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
}
try db.create(table: "d") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
}
try db.create(table: "a") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
t.column("name", .text)
}
try db.create(table: "c") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
t.column("did", .integer).references("d")
t.column("name", .text)
}
try B(id: 1, name: "b1").insert(db)
try B(id: 2, name: "b2").insert(db)
try A(id: 1, bid: 1, name: "a1").insert(db)
try A(id: 2, bid: 2, name: "a2").insert(db)
try A(id: 3, bid: nil, name: "a3").insert(db)
try D(id: 1, name: "d1").insert(db)
try C(id: 1, bid: 1, did: 1, name: "c1").insert(db)
try C(id: 2, bid: 1, did: nil, name: "c2").insert(db)
}
}
func testChainOfTwoIncludingIncluding() throws {
let dbQueue = try makeDatabaseQueue()
do {
let request = A.including(required: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
}
do {
let request = A.including(required: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 3)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
XCTAssertEqual(rows[2].unscoped, ["id":2, "bid":2, "name":"a2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["b"])
XCTAssertEqual(rows[2].scopes["b"]!.unscoped, ["id":2, "name":"b2"])
XCTAssertEqual(Set(rows[2].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[2].scopes["b"]!.scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
}
do {
// TODO: chainOptionalRequired
// let request = A.including(optional: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
}
do {
let request = A.including(optional: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 4)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
XCTAssertEqual(rows[2].unscoped, ["id":2, "bid":2, "name":"a2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["b"])
XCTAssertEqual(rows[2].scopes["b"]!.unscoped, ["id":2, "name":"b2"])
XCTAssertEqual(Set(rows[2].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[2].scopes["b"]!.scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
XCTAssertEqual(rows[3].unscoped, ["id":3, "bid":nil, "name":"a3"])
XCTAssertEqual(Set(rows[3].scopes.names), ["b"])
XCTAssertEqual(rows[3].scopes["b"]!.unscoped, ["id":nil, "name":nil])
XCTAssertEqual(Set(rows[3].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[3].scopes["b"]!.scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
}
do {
let request = B.including(required: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!.unscoped, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(Set(rows[0].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
}
do {
let request = B.including(required: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!.unscoped, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(Set(rows[0].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["c"]!.unscoped, ["id":2, "bid":1, "did":nil, "name":"c2"])
XCTAssertEqual(Set(rows[1].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[1].scopes["c"]!.scopes["d"]!, ["id":nil, "name":nil])
}
do {
// TODO: chainOptionalRequired
// let request = B.including(optional: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
}
do {
let request = B.including(optional: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 3)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!.unscoped, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(Set(rows[0].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["c"]!.unscoped, ["id":2, "bid":1, "did":nil, "name":"c2"])
XCTAssertEqual(Set(rows[1].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[1].scopes["c"]!.scopes["d"]!, ["id":nil, "name":nil])
XCTAssertEqual(rows[2].unscoped, ["id":2, "name":"b2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["c"])
XCTAssertEqual(rows[2].scopes["c"]!.unscoped, ["id":nil, "bid":nil, "did":nil, "name":nil])
XCTAssertEqual(Set(rows[2].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[2].scopes["c"]!.scopes["d"]!, ["id":nil, "name":nil])
}
}
func testChainOfTwoIncludingJoining() throws {
let dbQueue = try makeDatabaseQueue()
do {
let request = A.including(required: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!, ["id":1, "name":"b1"])
XCTAssertTrue(rows[0].scopes["b"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!, ["id":1, "name":"b1"])
XCTAssertTrue(rows[1].scopes["b"]!.scopes.names.isEmpty)
}
do {
let request = A.including(required: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 3)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!, ["id":1, "name":"b1"])
XCTAssertTrue(rows[0].scopes["b"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!, ["id":1, "name":"b1"])
XCTAssertTrue(rows[1].scopes["b"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[2].unscoped, ["id":2, "bid":2, "name":"a2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["b"])
XCTAssertEqual(rows[2].scopes["b"]!, ["id":2, "name":"b2"])
XCTAssertTrue(rows[2].scopes["b"]!.scopes.names.isEmpty)
}
do {
// TODO: chainOptionalRequired
// let request = A.including(optional: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
}
do {
let request = A.including(optional: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 4)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!, ["id":1, "name":"b1"])
XCTAssertTrue(rows[0].scopes["b"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!, ["id":1, "name":"b1"])
XCTAssertTrue(rows[1].scopes["b"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[2].unscoped, ["id":2, "bid":2, "name":"a2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["b"])
XCTAssertEqual(rows[2].scopes["b"]!, ["id":2, "name":"b2"])
XCTAssertTrue(rows[2].scopes["b"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[3].unscoped, ["id":3, "bid":nil, "name":"a3"])
XCTAssertEqual(Set(rows[3].scopes.names), ["b"])
XCTAssertEqual(rows[3].scopes["b"]!, ["id":nil, "name":nil])
XCTAssertTrue(rows[3].scopes["b"]!.scopes.names.isEmpty)
}
do {
let request = B.including(required: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertTrue(rows[0].scopes["c"]!.scopes.names.isEmpty)
}
do {
let request = B.including(required: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertTrue(rows[0].scopes["c"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[1].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
XCTAssertTrue(rows[1].scopes["c"]!.scopes.names.isEmpty)
}
do {
// TODO: chainOptionalRequired
// let request = B.including(optional: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
}
do {
let request = B.including(optional: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 3)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertTrue(rows[0].scopes["c"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[1].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
XCTAssertTrue(rows[1].scopes["c"]!.scopes.names.isEmpty)
XCTAssertEqual(rows[2].unscoped, ["id":2, "name":"b2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["c"])
XCTAssertEqual(rows[2].scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
XCTAssertTrue(rows[2].scopes["c"]!.scopes.names.isEmpty)
}
}
func testChainOfTwoJoiningIncluding() throws {
let dbQueue = try makeDatabaseQueue()
do {
let request = A.joining(required: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[1].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
}
do {
let request = A.joining(required: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 3)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[1].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
XCTAssertEqual(rows[2].unscoped, ["id":2, "bid":2, "name":"a2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["b"])
XCTAssertEqual(rows[2].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[2].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[2].scopes["b"]!.scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
}
do {
// TODO: chainOptionalRequired
// let request = A.joining(optional: A.defaultB.including(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
}
do {
let request = A.joining(optional: A.defaultB.including(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 4)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["b"])
XCTAssertEqual(rows[1].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[1].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["b"]!.scopes["c"]!, ["id":2, "bid":1, "did":nil, "name":"c2"])
XCTAssertEqual(rows[2].unscoped, ["id":2, "bid":2, "name":"a2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["b"])
XCTAssertEqual(rows[2].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[2].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[2].scopes["b"]!.scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
XCTAssertEqual(rows[3].unscoped, ["id":3, "bid":nil, "name":"a3"])
XCTAssertEqual(Set(rows[3].scopes.names), ["b"])
XCTAssertEqual(rows[3].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[3].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[3].scopes["b"]!.scopes["c"]!, ["id":nil, "bid":nil, "did":nil, "name":nil])
}
do {
let request = B.joining(required: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
}
do {
let request = B.joining(required: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["c"]!.unscoped, [:])
XCTAssertEqual(Set(rows[1].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[1].scopes["c"]!.scopes["d"]!, ["id":nil, "name":nil])
}
do {
// TODO: chainOptionalRequired
// let request = B.joining(optional: B.defaultC.including(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
}
do {
let request = B.joining(optional: B.defaultC.including(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 3)
XCTAssertEqual(rows[0].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["c"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
XCTAssertEqual(rows[1].unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[1].scopes.names), ["c"])
XCTAssertEqual(rows[1].scopes["c"]!.unscoped, [:])
XCTAssertEqual(Set(rows[1].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[1].scopes["c"]!.scopes["d"]!, ["id":nil, "name":nil])
XCTAssertEqual(rows[2].unscoped, ["id":2, "name":"b2"])
XCTAssertEqual(Set(rows[2].scopes.names), ["c"])
XCTAssertEqual(rows[2].scopes["c"]!.unscoped, [:])
XCTAssertEqual(Set(rows[2].scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[2].scopes["c"]!.scopes["d"]!, ["id":nil, "name":nil])
}
}
func testChainOfTwoJoiningJoining() throws {
let dbQueue = try makeDatabaseQueue()
do {
let request = A.joining(required: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0], ["id":1, "bid":1, "name":"a1"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
XCTAssertEqual(rows[1], ["id":1, "bid":1, "name":"a1"])
XCTAssertTrue(rows[1].scopes.names.isEmpty)
}
do {
let request = A.joining(required: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 3)
XCTAssertEqual(rows[0], ["id":1, "bid":1, "name":"a1"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
XCTAssertEqual(rows[1], ["id":1, "bid":1, "name":"a1"])
XCTAssertTrue(rows[1].scopes.names.isEmpty)
XCTAssertEqual(rows[2], ["id":2, "bid":2, "name":"a2"])
XCTAssertTrue(rows[2].scopes.names.isEmpty)
}
do {
// TODO: chainOptionalRequired
// let request = A.joining(optional: A.defaultB.joining(required: B.defaultC)).order(sql: "a.id, b.id, c.id")
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
}
do {
let request = A.joining(optional: A.defaultB.joining(optional: B.defaultC)).order(sql: "a.id, b.id, c.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 4)
XCTAssertEqual(rows[0], ["id":1, "bid":1, "name":"a1"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
XCTAssertEqual(rows[1], ["id":1, "bid":1, "name":"a1"])
XCTAssertTrue(rows[1].scopes.names.isEmpty)
XCTAssertEqual(rows[2], ["id":2, "bid":2, "name":"a2"])
XCTAssertTrue(rows[2].scopes.names.isEmpty)
XCTAssertEqual(rows[3], ["id":3, "bid":nil, "name":"a3"])
XCTAssertTrue(rows[3].scopes.names.isEmpty)
}
do {
let request = B.joining(required: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0], ["id":1, "name":"b1"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
}
do {
let request = B.joining(required: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 2)
XCTAssertEqual(rows[0], ["id":1, "name":"b1"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
XCTAssertEqual(rows[1], ["id":1, "name":"b1"])
XCTAssertTrue(rows[1].scopes.names.isEmpty)
}
do {
// TODO: chainOptionalRequired
// let request = B.joining(optional: B.defaultC.joining(required: C.defaultD)).order(sql: "b.id, c.id, d.id")
// let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
}
do {
let request = B.joining(optional: B.defaultC.joining(optional: C.defaultD)).order(sql: "b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 3)
XCTAssertEqual(rows[0], ["id":1, "name":"b1"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
XCTAssertEqual(rows[1], ["id":1, "name":"b1"])
XCTAssertTrue(rows[1].scopes.names.isEmpty)
XCTAssertEqual(rows[2], ["id":2, "name":"b2"])
XCTAssertTrue(rows[2].scopes.names.isEmpty)
}
}
func testChainOfThreeIncludingIncludingIncluding() throws {
let dbQueue = try makeDatabaseQueue()
let request = A.including(required: A.defaultB.including(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.unscoped, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
}
func testChainOfThreeIncludingIncludingJoining() throws {
let dbQueue = try makeDatabaseQueue()
let request = A.including(required: A.defaultB.including(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"], ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertTrue(rows[0].scopes["b"]!.scopes["c"]!.scopes.names.isEmpty)
}
func testChainOfThreeIncludingJoiningIncluding() throws {
let dbQueue = try makeDatabaseQueue()
let request = A.including(required: A.defaultB.joining(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
}
func testChainOfThreeIncludingJoiningJoining() throws {
let dbQueue = try makeDatabaseQueue()
let request = A.including(required: A.defaultB.joining(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, ["id":1, "name":"b1"])
XCTAssertTrue(rows[0].scopes["b"]!.scopes.names.isEmpty)
}
func testChainOfThreeJoiningIncludingIncluding() throws {
let dbQueue = try makeDatabaseQueue()
let request = A.joining(required: A.defaultB.including(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.unscoped, ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
}
func testChainOfThreeJoiningIncludingJoining() throws {
let dbQueue = try makeDatabaseQueue()
let request = A.joining(required: A.defaultB.including(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"], ["id":1, "bid":1, "did":1, "name":"c1"])
XCTAssertTrue(rows[0].scopes["b"]!.scopes["c"]!.scopes.names.isEmpty)
}
func testChainOfThreeJoiningJoiningIncluding() throws {
let dbQueue = try makeDatabaseQueue()
let request = A.joining(required: A.defaultB.joining(required: B.defaultC.including(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0].unscoped, ["id":1, "bid":1, "name":"a1"])
XCTAssertEqual(Set(rows[0].scopes.names), ["b"])
XCTAssertEqual(rows[0].scopes["b"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes.names), ["c"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.unscoped, [:])
XCTAssertEqual(Set(rows[0].scopes["b"]!.scopes["c"]!.scopes.names), ["d"])
XCTAssertEqual(rows[0].scopes["b"]!.scopes["c"]!.scopes["d"]!, ["id":1, "name":"d1"])
}
func testChainOfThreeJoiningJoiningJoining() throws {
let dbQueue = try makeDatabaseQueue()
let request = A.joining(required: A.defaultB.joining(required: B.defaultC.joining(required: C.defaultD))).order(sql: "a.id, b.id, c.id, d.id")
let rows = try dbQueue.inDatabase { try request.asRequest(of: Row.self).fetchAll($0) }
XCTAssertEqual(rows.count, 1)
XCTAssertEqual(rows[0], ["id":1, "bid":1, "name":"a1"])
XCTAssertTrue(rows[0].scopes.names.isEmpty)
}
}
@@ -0,0 +1,557 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
// A -> B <- C -> D
private struct A: TableRecord {
static let databaseTableName = "a"
static let b = belongsTo(B.self)
}
private struct B: TableRecord {
static let c = hasOne(C.self)
static let databaseTableName = "b"
}
private struct C: TableRecord {
static let databaseTableName = "c"
static let b = belongsTo(B.self)
static let d = belongsTo(D.self)
}
private struct D: TableRecord {
static let databaseTableName = "d"
}
/// Test SQL generation
class AssociationChainSQLTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "b") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "d") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "a") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
}
try db.create(table: "c") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
t.column("did", .integer).references("d")
}
}
}
func testChainOfTwoIncludingIncluding() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b.including(required: B.c)), """
SELECT "a".*, "b".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, A.including(required: A.b.including(optional: B.c)), """
SELECT "a".*, "b".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(optional: A.b.including(required: B.c)), "TODO")
try assertEqualSQL(db, A.including(optional: A.b.including(optional: B.c)), """
SELECT "a".*, "b".*, "c".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.including(required: B.c.including(required: C.d)), """
SELECT "b".*, "c".*, "d".* \
FROM "b" \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, B.including(required: B.c.including(optional: C.d)), """
SELECT "b".*, "c".*, "d".* \
FROM "b" \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, B.including(optional: B.c.including(required: C.d)), "TODO")
try assertEqualSQL(db, B.including(optional: B.c.including(optional: C.d)), """
SELECT "b".*, "c".*, "d".* \
FROM "b" \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfTwoIncludingJoining() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b.joining(required: B.c)), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, A.including(required: A.b.joining(optional: B.c)), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(optional: A.b.joining(required: B.c)), "")
try assertEqualSQL(db, A.including(optional: A.b.joining(optional: B.c)), """
SELECT "a".*, "b".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.including(required: B.c.joining(required: C.d)), """
SELECT "b".*, "c".* \
FROM "b" \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, B.including(required: B.c.joining(optional: C.d)), """
SELECT "b".*, "c".* \
FROM "b" \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, B.including(optional: B.c.joining(required: C.d)), "TODO")
try assertEqualSQL(db, B.including(optional: B.c.joining(optional: C.d)), """
SELECT "b".*, "c".* \
FROM "b" \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfTwoJoiningIncluding() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.joining(required: A.b.including(required: B.c)), """
SELECT "a".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, A.joining(required: A.b.including(optional: B.c)), """
SELECT "a".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(optional: A.b.including(required: B.c)), "TODO")
try assertEqualSQL(db, A.joining(optional: A.b.including(optional: B.c)), """
SELECT "a".*, "c".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.joining(required: B.c.including(required: C.d)), """
SELECT "b".*, "d".* \
FROM "b" \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, B.joining(required: B.c.including(optional: C.d)), """
SELECT "b".*, "d".* \
FROM "b" \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, B.joining(optional: B.c.including(required: C.d)), "TODO")
try assertEqualSQL(db, B.joining(optional: B.c.including(optional: C.d)), """
SELECT "b".*, "d".* \
FROM "b" \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfTwoJoiningJoining() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.joining(required: A.b.joining(required: B.c)), """
SELECT "a".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, A.joining(required: A.b.joining(optional: B.c)), """
SELECT "a".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(optional: A.b.joining(required: B.c)), "TODO")
try assertEqualSQL(db, A.joining(optional: A.b.joining(optional: B.c)), """
SELECT "a".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.joining(required: B.c.joining(required: C.d)), """
SELECT "b".* \
FROM "b" \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, B.joining(required: B.c.joining(optional: C.d)), """
SELECT "b".* \
FROM "b" \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, B.joining(optional: B.c.joining(required: C.d)), "TODO")
try assertEqualSQL(db, B.joining(optional: B.c.joining(optional: C.d)), """
SELECT "b".* \
FROM "b" \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfThreeIncludingIncludingIncluding() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b.including(required: B.c.including(required: C.d))), """
SELECT "a".*, "b".*, "c".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, A.including(required: A.b.including(required: B.c.including(optional: C.d))), """
SELECT "a".*, "b".*, "c".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(required: A.b.including(optional: B.c.including(required: C.d))), "TODO")
try assertEqualSQL(db, A.including(required: A.b.including(optional: B.c.including(optional: C.d))), """
SELECT "a".*, "b".*, "c".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(optional: A.b.including(required: B.c.including(required: C.d))), "TODO")
// try assertEqualSQL(db, A.including(optional: A.b.including(required: B.c.including(optional: C.d))), "TODO")
// try assertEqualSQL(db, A.including(optional: A.b.including(optional: B.c.including(required: C.d))), "TODO")
try assertEqualSQL(db, A.including(optional: A.b.including(optional: B.c.including(optional: C.d))), """
SELECT "a".*, "b".*, "c".*, "d".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfThreeIncludingIncludingJoining() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b.including(required: B.c.joining(required: C.d))), """
SELECT "a".*, "b".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, A.including(required: A.b.including(required: B.c.joining(optional: C.d))), """
SELECT "a".*, "b".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(required: A.b.including(optional: B.c.joining(required: C.d))), "TODO")
try assertEqualSQL(db, A.including(required: A.b.including(optional: B.c.joining(optional: C.d))), """
SELECT "a".*, "b".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(optional: A.b.including(required: B.c.joining(required: C.d))), "TODO")
// try assertEqualSQL(db, A.including(optional: A.b.including(required: B.c.joining(optional: C.d))), "TODO")
// try assertEqualSQL(db, A.including(optional: A.b.including(optional: B.c.joining(required: C.d))), "TODO")
try assertEqualSQL(db, A.including(optional: A.b.including(optional: B.c.joining(optional: C.d))), """
SELECT "a".*, "b".*, "c".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfThreeIncludingJoiningIncluding() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b.joining(required: B.c.including(required: C.d))), """
SELECT "a".*, "b".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, A.including(required: A.b.joining(required: B.c.including(optional: C.d))), """
SELECT "a".*, "b".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(required: A.b.joining(optional: B.c.including(required: C.d))), "TODO")
try assertEqualSQL(db, A.including(required: A.b.joining(optional: B.c.including(optional: C.d))), """
SELECT "a".*, "b".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(optional: A.b.joining(required: B.c.including(required: C.d))), "TODO")
// try assertEqualSQL(db, A.including(optional: A.b.joining(required: B.c.including(optional: C.d))), "TODO")
// try assertEqualSQL(db, A.including(optional: A.b.joining(optional: B.c.including(required: C.d))), "TODO")
try assertEqualSQL(db, A.including(optional: A.b.joining(optional: B.c.including(optional: C.d))), """
SELECT "a".*, "b".*, "d".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfThreeIncludingJoiningJoining() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b.joining(required: B.c.joining(required: C.d))), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, A.including(required: A.b.joining(required: B.c.joining(optional: C.d))), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(required: A.b.joining(optional: B.c.joining(required: C.d))), "TODO")
try assertEqualSQL(db, A.including(required: A.b.joining(optional: B.c.joining(optional: C.d))), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.including(optional: A.b.joining(required: B.c.joining(required: C.d))), "TODO")
// try assertEqualSQL(db, A.including(optional: A.b.joining(required: B.c.joining(optional: C.d))), "TODO")
// try assertEqualSQL(db, A.including(optional: A.b.joining(optional: B.c.joining(required: C.d))), "TODO")
try assertEqualSQL(db, A.including(optional: A.b.joining(optional: B.c.joining(optional: C.d))), """
SELECT "a".*, "b".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfThreeJoiningIncludingIncluding() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.joining(required: A.b.including(required: B.c.including(required: C.d))), """
SELECT "a".*, "c".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, A.joining(required: A.b.including(required: B.c.including(optional: C.d))), """
SELECT "a".*, "c".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(required: A.b.including(optional: B.c.including(required: C.d))), "TODO")
try assertEqualSQL(db, A.joining(required: A.b.including(optional: B.c.including(optional: C.d))), """
SELECT "a".*, "c".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(optional: A.b.including(required: B.c.including(required: C.d))), "TODO")
// try assertEqualSQL(db, A.joining(optional: A.b.including(required: B.c.including(optional: C.d))), "TODO")
// try assertEqualSQL(db, A.joining(optional: A.b.including(optional: B.c.including(required: C.d))), "TODO")
try assertEqualSQL(db, A.joining(optional: A.b.including(optional: B.c.including(optional: C.d))), """
SELECT "a".*, "c".*, "d".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfThreeJoiningIncludingJoining() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.joining(required: A.b.including(required: B.c.joining(required: C.d))), """
SELECT "a".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, A.joining(required: A.b.including(required: B.c.joining(optional: C.d))), """
SELECT "a".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(required: A.b.including(optional: B.c.joining(required: C.d))), "TODO")
try assertEqualSQL(db, A.joining(required: A.b.including(optional: B.c.joining(optional: C.d))), """
SELECT "a".*, "c".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(optional: A.b.including(required: B.c.joining(required: C.d))), "TODO")
// try assertEqualSQL(db, A.joining(optional: A.b.including(required: B.c.joining(optional: C.d))), "TODO")
// try assertEqualSQL(db, A.joining(optional: A.b.including(optional: B.c.joining(required: C.d))), "TODO")
try assertEqualSQL(db, A.joining(optional: A.b.including(optional: B.c.joining(optional: C.d))), """
SELECT "a".*, "c".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfThreeJoiningJoiningIncluding() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.joining(required: A.b.joining(required: B.c.including(required: C.d))), """
SELECT "a".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, A.joining(required: A.b.joining(required: B.c.including(optional: C.d))), """
SELECT "a".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(required: A.b.joining(optional: B.c.including(required: C.d))), "TODO")
try assertEqualSQL(db, A.joining(required: A.b.joining(optional: B.c.including(optional: C.d))), """
SELECT "a".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(optional: A.b.joining(required: B.c.including(required: C.d))), "TODO")
// try assertEqualSQL(db, A.joining(optional: A.b.joining(required: B.c.including(optional: C.d))), "TODO")
// try assertEqualSQL(db, A.joining(optional: A.b.joining(optional: B.c.including(required: C.d))), "TODO")
try assertEqualSQL(db, A.joining(optional: A.b.joining(optional: B.c.including(optional: C.d))), """
SELECT "a".*, "d".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
func testChainOfThreeJoiningJoiningJoining() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.joining(required: A.b.joining(required: B.c.joining(required: C.d))), """
SELECT "a".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
JOIN "d" ON ("d"."id" = "c"."did")
""")
try assertEqualSQL(db, A.joining(required: A.b.joining(required: B.c.joining(optional: C.d))), """
SELECT "a".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(required: A.b.joining(optional: B.c.joining(required: C.d))), "TODO")
try assertEqualSQL(db, A.joining(required: A.b.joining(optional: B.c.joining(optional: C.d))), """
SELECT "a".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
// TODO: chainOptionalRequired
// try assertEqualSQL(db, A.joining(optional: A.b.joining(required: B.c.joining(required: C.d))), "TODO")
// try assertEqualSQL(db, A.joining(optional: A.b.joining(required: B.c.joining(optional: C.d))), "TODO)
// try assertEqualSQL(db, A.joining(optional: A.b.joining(optional: B.c.joining(required: C.d))), "TODO")
try assertEqualSQL(db, A.joining(optional: A.b.joining(optional: B.c.joining(optional: C.d))), """
SELECT "a".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id") \
LEFT JOIN "d" ON ("d"."id" = "c"."did")
""")
}
}
}
@@ -0,0 +1,406 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
// A <- B
private struct A : TableRecord {
static let databaseTableName = "a"
static let b = hasOne(B.self)
static let restrictedB = hasOne(RestrictedB.self)
static let extendedB = hasOne(ExtendedB.self)
}
private struct B : TableRecord {
static let a = belongsTo(A.self)
static let databaseTableName = "b"
}
private struct RestrictedB : TableRecord {
static let databaseTableName = "b"
static let databaseSelection: [SQLSelectable] = [Column("name")]
}
private struct ExtendedB : TableRecord {
static let databaseTableName = "b"
static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID]
}
/// Test SQL generation
class AssociationHasOneSQLDerivationTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "a") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "b") { t in
t.column("id", .integer).primaryKey()
t.column("aid", .integer).references("a")
t.column("name", .text)
}
}
}
func testDefaultSelection() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."aid" = "a"."id")
""")
try assertEqualSQL(db, A.including(required: A.restrictedB), """
SELECT "a".*, "b"."name" \
FROM "a" \
JOIN "b" ON ("b"."aid" = "a"."id")
""")
try assertEqualSQL(db, A.including(required: A.extendedB), """
SELECT "a".*, "b".*, "b"."rowid" \
FROM "a" \
JOIN "b" ON ("b"."aid" = "a"."id")
""")
}
}
func testCustomSelection() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
do {
let request = A.including(required: A.b
.select(Column("name")))
try assertEqualSQL(db, request, """
SELECT "a".*, "b"."name" \
FROM "a" \
JOIN "b" ON ("b"."aid" = "a"."id")
""")
}
do {
let request = A.including(required: A.b
.select(
AllColumns(),
Column.rowID))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".*, "b"."rowid" \
FROM "a" \
JOIN "b" ON ("b"."aid" = "a"."id")
""")
}
do {
let aAlias = TableAlias()
let request = A
.aliased(aAlias)
.including(required: A.b
.select(
Column("name"),
(Column("id") + aAlias[Column("id")]).aliased("foo")))
try assertEqualSQL(db, request, """
SELECT "a".*, "b"."name", ("b"."id" + "a"."id") AS "foo" \
FROM "a" \
JOIN "b" ON ("b"."aid" = "a"."id")
""")
}
}
}
func testFilteredAssociationImpactsJoinOnClause() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
do {
let request = A.including(required: A.b.filter(Column("name") != nil))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."aid" = "a"."id") AND ("b"."name" IS NOT NULL))
""")
}
do {
let request = A.including(required: A.b.filter(key: 1))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."aid" = "a"."id") AND ("b"."id" = 1))
""")
}
do {
let request = A.including(required: A.b.filter(keys: [1, 2, 3]))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."aid" = "a"."id") AND ("b"."id" IN (1, 2, 3)))
""")
}
do {
let request = A.including(required: A.b.filter(key: ["id": 1]))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."aid" = "a"."id") AND ("b"."id" = 1))
""")
}
do {
let request = A.including(required: A.b.filter(keys: [["id": 1], ["id": 2]]))
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON (("b"."aid" = "a"."id") AND (("b"."id" = 1) OR ("b"."id" = 2)))
""")
}
do {
let bAlias = TableAlias(name: "customB")
let request = A.including(required: A.b
.aliased(bAlias)
.filter(sql: "customB.name = ?", arguments: ["foo"]))
try assertEqualSQL(db, request, """
SELECT "a".*, "customB".* \
FROM "a" \
JOIN "b" "customB" ON (("customB"."aid" = "a"."id") AND (customB.name = 'foo'))
""")
}
}
}
func testFilterAssociationInWhereClause() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let bAlias = TableAlias()
let request = A
.including(required: A.b.aliased(bAlias))
.filter(bAlias[Column("name")] != nil)
try assertEqualSQL(db, request, """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."aid" = "a"."id") \
WHERE ("b"."name" IS NOT NULL)
""")
}
}
func testAssociationOrderBubbleUp() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let aBase = A.all().aliased(TableAlias(name: "a"))
let abBase = A.b.aliased(TableAlias(name: "ab"))
let abaBase = B.a.aliased(TableAlias(name: "aba"))
let aTransforms = [
{ (r: QueryInterfaceRequest<A>) in return r },
{ (r: QueryInterfaceRequest<A>) in return r.order(Column("id")) },
{ (r: QueryInterfaceRequest<A>) in return r.order(Column("id")).reversed() },
]
let abTransforms = [
{ (r: HasOneAssociation<A, B>) in return r },
{ (r: HasOneAssociation<A, B>) in return r.order(Column("name"), Column("id").desc) },
{ (r: HasOneAssociation<A, B>) in return r.order(Column("name")).order(Column("id").desc) },
{ (r: HasOneAssociation<A, B>) in return r.order(Column("name")).reversed() },
{ (r: HasOneAssociation<A, B>) in return r.reversed() },
]
let abaTransforms = [
{ (r: BelongsToAssociation<B, A>) in return r },
{ (r: BelongsToAssociation<B, A>) in return r.order(Column("id")) },
{ (r: BelongsToAssociation<B, A>) in return r.order(Column("id")).reversed() },
]
var sqls: [String] = []
for aTransform in aTransforms {
for abTransform in abTransforms {
for abaTransform in abaTransforms {
let request = aTransform(aBase)
.including(required: abTransform(abBase)
.including(required: abaTransform(abaBase)))
let sqlRequest = try SQLRequest(db, request: request)
sqls.append(sqlRequest.sql)
}
}
}
let prefix = """
SELECT "a".*, "ab".*, "aba".* \
FROM "a" \
JOIN "b" "ab" ON ("ab"."aid" = "a"."id") \
JOIN "a" "aba" ON ("aba"."id" = "ab"."aid")
"""
let orderClauses = sqls.map { sql -> String in
let prefixEndIndex = sql.index(sql.startIndex, offsetBy: prefix.count)
return String(sql.suffix(from: prefixEndIndex))
}
XCTAssertEqual(orderClauses, [
// a: { (r: QueryInterfaceRequest<A>) in return r },
// ab: { (r: BelongsToAssociation<A, B>) in return r }
// aba: { (r: HasOneAssociation<B, A>) in return r }
"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name"), Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"ab\".\"name\", \"ab\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"ab\".\"name\", \"ab\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"ab\".\"name\", \"ab\".\"id\" DESC, \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).order(Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"ab\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"ab\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"ab\".\"id\" DESC, \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"ab\".\"name\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"ab\".\"name\" DESC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"ab\".\"name\" DESC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"aba\".\"id\"",
// a: { (r: QueryInterfaceRequest<A>) in return r.order(Column("id")) },
// ab: { (r: BelongsToAssociation<A, B>) in return r }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name"), Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\", \"ab\".\"name\", \"ab\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"ab\".\"name\", \"ab\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"ab\".\"name\", \"ab\".\"id\" DESC, \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).order(Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\", \"ab\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"ab\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"ab\".\"id\" DESC, \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\", \"ab\".\"name\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"ab\".\"name\" DESC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"ab\".\"name\" DESC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\", \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\", \"aba\".\"id\"",
// a: { (r: QueryInterfaceRequest<A>) in return r.order(Column("id")).reversed() }
// ab: { (r: BelongsToAssociation<A, B>) in return r }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name"), Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\" DESC, \"ab\".\"id\" ASC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\" DESC, \"ab\".\"id\" ASC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\" DESC, \"ab\".\"id\" ASC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).order(Column("id").desc) }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"id\" ASC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"id\" ASC, \"aba\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"id\" ASC, \"aba\".\"id\"",
// ab: { (r: BelongsToAssociation<A, B>) in return r.order(Column("name")).reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\", \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"ab\".\"name\", \"aba\".\"id\" DESC",
// ab: { (r: BelongsToAssociation<A, B>) in return r.reversed() }
// aba: { (r: HasOneAssociation<B, A>) in return r }
" ORDER BY \"a\".\"id\" DESC",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")) }
" ORDER BY \"a\".\"id\" DESC, \"aba\".\"id\"",
// aba: { (r: HasOneAssociation<B, A>) in return r.order(Column("id")).reversed() }
" ORDER BY \"a\".\"id\" DESC, \"aba\".\"id\" DESC",
])
}
}
// TODO: Test if and only if we really want to build an association from any request
// func testAssociationFromRequest() throws {
// let dbQueue = try makeDatabaseQueue()
// try dbQueue.inDatabase { db in
// do {
// let bRequest = B
// .filter(Column("name") != nil)
// .order(Column("id"))
// let association = A.hasOne(bRequest)
// let request = A.including(required: association)
// try assertEqualSQL(db, request, """
// SELECT "a".*, "b".* \
// FROM "a" \
// JOIN "b" ON (("b"."aid" = "a"."id") AND ("b"."name" IS NOT NULL)) \
// ORDER BY "b"."id"
// """)
// }
// do {
// let bRequest = RestrictedB
// .filter(Column("name") != nil)
// .order(Column("id"))
// let association = A.hasOne(bRequest)
// let request = A.including(required: association)
// try assertEqualSQL(db, request, """
// SELECT "a".*, "b"."name" \
// FROM "a" \
// JOIN "b" ON (("b"."aid" = "a"."id") AND ("b"."name" IS NOT NULL)) \
// ORDER BY "b"."id"
// """)
// }
// do {
// let bRequest = ExtendedB
// .select([Column("name")])
// .filter(Column("name") != nil)
// .order(Column("id"))
// let association = A.hasOne(bRequest)
// let request = A.including(required: association)
// try assertEqualSQL(db, request, """
// SELECT "a".*, "b"."name" \
// FROM "a" \
// JOIN "b" ON (("b"."aid" = "a"."id") AND ("b"."name" IS NOT NULL)) \
// ORDER BY "b"."id"
// """)
// }
// }
// }
}
@@ -0,0 +1,769 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
/// Test SQL generation
class AssociationHasOneSQLTests: GRDBTestCase {
func testSingleColumnNoForeignKeyNoPrimaryKey() throws {
struct Child : TableRecord {
static let databaseTableName = "children"
}
struct Parent : TableRecord, MutablePersistableRecord {
static let databaseTableName = "parents"
func encode(to container: inout PersistenceContainer) {
container["id"] = 1
container["rowid"] = 2
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("id", .integer)
}
try db.create(table: "children") { t in
t.column("parentId", .integer)
}
}
try dbQueue.inDatabase { db in
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentId")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."rowid")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."rowid")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."rowid")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."rowid")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 2)")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentId")], to: [Column("id")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)")
}
}
}
func testSingleColumnNoForeignKey() throws {
struct Child : TableRecord {
static let databaseTableName = "children"
}
struct Parent : TableRecord, MutablePersistableRecord {
static let databaseTableName = "parents"
func encode(to container: inout PersistenceContainer) {
container["id"] = 1
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "children") { t in
t.column("parentId", .integer)
}
}
try dbQueue.inDatabase { db in
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentId")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentId")], to: [Column("id")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)")
}
}
}
func testSingleColumnSingleForeignKey() throws {
struct Child : TableRecord {
static let databaseTableName = "children"
}
struct Parent : TableRecord, MutablePersistableRecord {
static let databaseTableName = "parents"
func encode(to container: inout PersistenceContainer) {
container["id"] = 1
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "children") { t in
t.column("parentId", .integer).references("parents")
}
}
try dbQueue.inDatabase { db in
do {
let association = Parent.hasOne(Child.self)
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentId")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentId")], to: [Column("id")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parentId" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parentId\" = 1)")
}
}
}
func testSingleColumnSeveralForeignKeys() throws {
struct Child : TableRecord {
static let databaseTableName = "children"
}
struct Parent : TableRecord, MutablePersistableRecord {
static let databaseTableName = "parents"
func encode(to container: inout PersistenceContainer) {
container["id"] = 1
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "children") { t in
t.column("parent1Id", .integer).references("parents")
t.column("parent2Id", .integer).references("parents")
}
}
try dbQueue.inDatabase { db in
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parent1Id")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parent1Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parent1Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parent1Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parent1Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parent1Id\" = 1)")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parent1Id")], to: [Column("id")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parent1Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parent1Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parent1Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parent1Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parent1Id\" = 1)")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parent2Id")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parent2Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parent2Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parent2Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parent2Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parent2Id\" = 1)")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parent2Id")], to: [Column("id")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON ("children"."parent2Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parent2Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON ("children"."parent2Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON ("children"."parent2Id" = "parents"."id")
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE (\"parent2Id\" = 1)")
}
}
}
func testCompoundColumnNoForeignKeyNoPrimaryKey() throws {
struct Child : TableRecord {
static let databaseTableName = "children"
}
struct Parent : TableRecord, MutablePersistableRecord {
static let databaseTableName = "parents"
func encode(to container: inout PersistenceContainer) {
container["a"] = 1
container["b"] = 2
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("a", .integer)
t.column("b", .integer)
}
try db.create(table: "children") { t in
t.column("parentA", .integer)
t.column("parentB", .integer)
}
}
try dbQueue.inDatabase { db in
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))")
}
}
}
func testCompoundColumnNoForeignKey() throws {
struct Child : TableRecord {
static let databaseTableName = "children"
}
struct Parent : TableRecord, MutablePersistableRecord {
static let databaseTableName = "parents"
func encode(to container: inout PersistenceContainer) {
container["a"] = 1
container["b"] = 2
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("a", .integer)
t.column("b", .integer)
t.primaryKey(["a", "b"])
}
try db.create(table: "children") { t in
t.column("parentA", .integer)
t.column("parentB", .integer)
}
}
try dbQueue.inDatabase { db in
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))")
}
}
}
func testCompoundColumnSingleForeignKey() throws {
struct Child : TableRecord {
static let databaseTableName = "children"
}
struct Parent : TableRecord, MutablePersistableRecord {
static let databaseTableName = "parents"
func encode(to container: inout PersistenceContainer) {
container["a"] = 1
container["b"] = 2
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("a", .integer)
t.column("b", .integer)
t.primaryKey(["a", "b"])
}
try db.create(table: "children") { t in
t.column("parentA", .integer)
t.column("parentB", .integer)
t.foreignKey(["parentA", "parentB"], references: "parents")
}
}
try dbQueue.inDatabase { db in
do {
let association = Parent.hasOne(Child.self)
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parentA"), Column("parentB")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parentA" = "parents"."a") AND ("children"."parentB" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parentA\" = 1) AND (\"parentB\" = 2))")
}
}
}
func testCompoundColumnSeveralForeignKeys() throws {
struct Child : TableRecord {
static let databaseTableName = "children"
}
struct Parent : TableRecord, MutablePersistableRecord {
static let databaseTableName = "parents"
func encode(to container: inout PersistenceContainer) {
container["a"] = 1
container["b"] = 2
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "parents") { t in
t.column("a", .integer)
t.column("b", .integer)
t.primaryKey(["a", "b"])
}
try db.create(table: "children") { t in
t.column("parent1A", .integer)
t.column("parent1B", .integer)
t.column("parent2A", .integer)
t.column("parent2B", .integer)
t.foreignKey(["parent1A", "parent1B"], references: "parents")
t.foreignKey(["parent2A", "parent2B"], references: "parents")
}
}
try dbQueue.inDatabase { db in
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parent1A"), Column("parent1B")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parent1A\" = 1) AND (\"parent1B\" = 2))")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parent1A"), Column("parent1B")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parent1A" = "parents"."a") AND ("children"."parent1B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parent1A\" = 1) AND (\"parent1B\" = 2))")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parent2A"), Column("parent2B")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parent2A\" = 1) AND (\"parent2B\" = 2))")
}
do {
let association = Parent.hasOne(Child.self, using: ForeignKey([Column("parent2A"), Column("parent2B")], to: [Column("a"), Column("b")]))
try assertEqualSQL(db, Parent.all().including(required: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().including(optional: association), """
SELECT "parents".*, "children".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(required: association), """
SELECT "parents".* \
FROM "parents" \
JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent.all().joining(optional: association), """
SELECT "parents".* \
FROM "parents" \
LEFT JOIN "children" ON (("children"."parent2A" = "parents"."a") AND ("children"."parent2B" = "parents"."b"))
""")
try assertEqualSQL(db, Parent().request(for: association), "SELECT * FROM \"children\" WHERE ((\"parent2A\" = 1) AND (\"parent2B\" = 2))")
}
}
}
func testForeignKeyDefinitionFromColumn() {
// This test pass if code compiles
struct Parent : TableRecord {
static let databaseTableName = "parents"
enum Columns {
static let id = Column("id")
}
static let child1 = hasOne(Child.self, using: Child.ForeignKeys.parent1)
static let child2 = hasOne(Child.self, using: Child.ForeignKeys.parent2)
}
struct Child : TableRecord {
static let databaseTableName = "children"
enum Columns {
static let parentId = Column("parentId")
}
enum ForeignKeys {
static let parent1 = ForeignKey([Columns.parentId])
static let parent2 = ForeignKey([Columns.parentId], to: [Parent.Columns.id])
}
}
}
}
@@ -0,0 +1,237 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
// A -> B
// A -> D
private struct A: Codable, FetchableRecord, PersistableRecord {
static let databaseTableName = "a"
static let b = belongsTo(B.self)
static let d = belongsTo(D.self)
var id: Int64
var bid: Int64?
var did: Int64?
var name: String
}
private struct B: Codable, FetchableRecord, PersistableRecord {
static let a = hasOne(A.self)
static let databaseTableName = "b"
var id: Int64
var name: String
}
private struct D: Codable, FetchableRecord, PersistableRecord {
static let a = hasOne(A.self)
static let databaseTableName = "d"
var id: Int64
var name: String
}
private struct AWithRequiredBD: Decodable, FetchableRecord {
var a: A
var b: B
var d: D
static let b = A.b.forKey(CodingKeys.b)
static let d = A.d.forKey(CodingKeys.d)
}
private struct AWithOptionalBD: Decodable, FetchableRecord {
var a: A
var b: B?
var d: D?
static let b = A.b.forKey(CodingKeys.b)
static let d = A.d.forKey(CodingKeys.d)
}
/// Test support for Decodable records
class AssociationParallelDecodableRecordTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "b") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
}
try db.create(table: "d") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
}
try db.create(table: "a") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
t.column("did", .integer).references("d")
t.column("name", .text)
}
try B(id: 1, name: "b1").insert(db)
try B(id: 2, name: "b2").insert(db)
try B(id: 3, name: "b3").insert(db)
try D(id: 1, name: "d1").insert(db)
try A(id: 1, bid: 1, did: 1, name: "a1").insert(db)
try A(id: 2, bid: 1, did: nil, name: "a2").insert(db)
try A(id: 3, bid: 2, did: 1, name: "a3").insert(db)
try A(id: 4, bid: 2, did: nil, name: "a4").insert(db)
try A(id: 5, bid: nil, did: 1, name: "a5").insert(db)
try A(id: 6, bid: nil, did: nil, name: "a6").insert(db)
}
}
func testParallelTwoIncludingRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = A
.including(required: AWithRequiredBD.b)
.including(required: AWithRequiredBD.d)
.order(sql: "a.id, b.id, d.id")
.asRequest(of: AWithRequiredBD.self)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(records.count, 2)
XCTAssertEqual(records[0].a.id, 1)
XCTAssertEqual(records[0].a.bid, 1)
XCTAssertEqual(records[0].a.did, 1)
XCTAssertEqual(records[0].a.name, "a1")
XCTAssertEqual(records[0].b.id, 1)
XCTAssertEqual(records[0].b.name, "b1")
XCTAssertEqual(records[0].d.id, 1)
XCTAssertEqual(records[0].d.name, "d1")
XCTAssertEqual(records[1].a.id, 3)
XCTAssertEqual(records[1].a.bid, 2)
XCTAssertEqual(records[1].a.did, 1)
XCTAssertEqual(records[1].a.name, "a3")
XCTAssertEqual(records[1].b.id, 2)
XCTAssertEqual(records[1].b.name, "b2")
XCTAssertEqual(records[1].d.id, 1)
XCTAssertEqual(records[1].d.name, "d1")
}
func testParallelTwoIncludingOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = A
.including(optional: AWithOptionalBD.b)
.including(optional: AWithOptionalBD.d)
.order(sql: "a.id, b.id, d.id")
.asRequest(of: AWithOptionalBD.self)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(records.count, 6)
XCTAssertEqual(records[0].a.id, 1)
XCTAssertEqual(records[0].a.bid, 1)
XCTAssertEqual(records[0].a.did, 1)
XCTAssertEqual(records[0].a.name, "a1")
XCTAssertEqual(records[0].b!.id, 1)
XCTAssertEqual(records[0].b!.name, "b1")
XCTAssertEqual(records[0].d!.id, 1)
XCTAssertEqual(records[0].d!.name, "d1")
XCTAssertEqual(records[1].a.id, 2)
XCTAssertEqual(records[1].a.bid, 1)
XCTAssertEqual(records[1].a.did, nil)
XCTAssertEqual(records[1].a.name, "a2")
XCTAssertEqual(records[1].b!.id, 1)
XCTAssertEqual(records[1].b!.name, "b1")
XCTAssertNil(records[1].d)
XCTAssertEqual(records[2].a.id, 3)
XCTAssertEqual(records[2].a.bid, 2)
XCTAssertEqual(records[2].a.did, 1)
XCTAssertEqual(records[2].a.name, "a3")
XCTAssertEqual(records[2].b!.id, 2)
XCTAssertEqual(records[2].b!.name, "b2")
XCTAssertEqual(records[2].d!.id, 1)
XCTAssertEqual(records[2].d!.name, "d1")
XCTAssertEqual(records[3].a.id, 4)
XCTAssertEqual(records[3].a.bid, 2)
XCTAssertEqual(records[3].a.did, nil)
XCTAssertEqual(records[3].a.name, "a4")
XCTAssertEqual(records[3].b!.id, 2)
XCTAssertEqual(records[3].b!.name, "b2")
XCTAssertNil(records[3].d)
XCTAssertEqual(records[4].a.id, 5)
XCTAssertEqual(records[4].a.bid, nil)
XCTAssertEqual(records[4].a.did, 1)
XCTAssertEqual(records[4].a.name, "a5")
XCTAssertNil(records[4].b)
XCTAssertEqual(records[4].d!.id, 1)
XCTAssertEqual(records[4].d!.name, "d1")
XCTAssertEqual(records[5].a.id, 6)
XCTAssertEqual(records[5].a.bid, nil)
XCTAssertEqual(records[5].a.did, nil)
XCTAssertEqual(records[5].a.name, "a6")
XCTAssertNil(records[5].b)
XCTAssertNil(records[5].d)
}
func testParallelTwoJoiningRequired() throws {
let dbQueue = try makeDatabaseQueue()
let request = A
.joining(required: A.b)
.joining(required: A.d)
.order(sql: "a.id, b.id, d.id")
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(records.count, 2)
XCTAssertEqual(records[0].id, 1)
XCTAssertEqual(records[0].bid, 1)
XCTAssertEqual(records[0].did, 1)
XCTAssertEqual(records[0].name, "a1")
XCTAssertEqual(records[1].id, 3)
XCTAssertEqual(records[1].bid, 2)
XCTAssertEqual(records[1].did, 1)
XCTAssertEqual(records[1].name, "a3")
}
func testParallelTwoJoiningOptional() throws {
let dbQueue = try makeDatabaseQueue()
let request = A
.joining(optional: A.b)
.joining(optional: A.d)
.order(sql: "a.id, b.id, d.id")
let records = try dbQueue.inDatabase { try request.fetchAll($0) }
XCTAssertEqual(records.count, 6)
XCTAssertEqual(records[0].id, 1)
XCTAssertEqual(records[0].bid, 1)
XCTAssertEqual(records[0].did, 1)
XCTAssertEqual(records[0].name, "a1")
XCTAssertEqual(records[1].id, 2)
XCTAssertEqual(records[1].bid, 1)
XCTAssertEqual(records[1].did, nil)
XCTAssertEqual(records[1].name, "a2")
XCTAssertEqual(records[2].id, 3)
XCTAssertEqual(records[2].bid, 2)
XCTAssertEqual(records[2].did, 1)
XCTAssertEqual(records[2].name, "a3")
XCTAssertEqual(records[3].id, 4)
XCTAssertEqual(records[3].bid, 2)
XCTAssertEqual(records[3].did, nil)
XCTAssertEqual(records[3].name, "a4")
XCTAssertEqual(records[4].id, 5)
XCTAssertEqual(records[4].bid, nil)
XCTAssertEqual(records[4].did, 1)
XCTAssertEqual(records[4].name, "a5")
XCTAssertEqual(records[5].id, 6)
XCTAssertEqual(records[5].bid, nil)
XCTAssertEqual(records[5].did, nil)
XCTAssertEqual(records[5].name, "a6")
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,272 @@
import XCTest
#if GRDBCIPHER
import GRDBCipher
#elseif GRDBCUSTOMSQLITE
import GRDBCustomSQLite
#else
import GRDB
#endif
// A -> B <- C
// A -> D
private struct A: TableRecord {
static let databaseTableName = "a"
static let b = belongsTo(B.self)
static let d = belongsTo(D.self)
}
private struct B: TableRecord {
static let a = hasOne(A.self)
static let c = hasOne(C.self)
static let databaseTableName = "b"
}
private struct C: TableRecord {
static let databaseTableName = "c"
static let b = belongsTo(B.self)
}
private struct D: TableRecord {
static let a = hasOne(A.self)
static let databaseTableName = "d"
}
/// Test SQL generation
class AssociationParallelSQLTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
try db.create(table: "b") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "d") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "a") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
t.column("did", .integer).references("d")
}
try db.create(table: "c") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
}
}
}
func testParallelTwoIncludingIncluding() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b).including(required: A.d), """
SELECT "a".*, "b".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.including(required: A.b).including(optional: A.d), """
SELECT "a".*, "b".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.including(optional: A.b).including(required: A.d), """
SELECT "a".*, "b".*, "d".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.including(optional: A.b).including(optional: A.d), """
SELECT "a".*, "b".*, "d".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, B.including(required: B.a).including(required: B.c), """
SELECT "b".*, "a".*, "c".* \
FROM "b" \
JOIN "a" ON ("a"."bid" = "b"."id") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.including(required: B.a).including(optional: B.c), """
SELECT "b".*, "a".*, "c".* \
FROM "b" \
JOIN "a" ON ("a"."bid" = "b"."id") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.including(optional: B.a).including(required: B.c), """
SELECT "b".*, "a".*, "c".* \
FROM "b" \
LEFT JOIN "a" ON ("a"."bid" = "b"."id") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.including(optional: B.a).including(optional: B.c), """
SELECT "b".*, "a".*, "c".* \
FROM "b" \
LEFT JOIN "a" ON ("a"."bid" = "b"."id") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
}
}
func testParallelTwoIncludingJoining() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.including(required: A.b).joining(required: A.d), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.including(required: A.b).joining(optional: A.d), """
SELECT "a".*, "b".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.including(optional: A.b).joining(required: A.d), """
SELECT "a".*, "b".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.including(optional: A.b).joining(optional: A.d), """
SELECT "a".*, "b".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, B.including(required: B.a).joining(required: B.c), """
SELECT "b".*, "a".* \
FROM "b" \
JOIN "a" ON ("a"."bid" = "b"."id") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.including(required: B.a).joining(optional: B.c), """
SELECT "b".*, "a".* \
FROM "b" \
JOIN "a" ON ("a"."bid" = "b"."id") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.including(optional: B.a).joining(required: B.c), """
SELECT "b".*, "a".* \
FROM "b" \
LEFT JOIN "a" ON ("a"."bid" = "b"."id") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.including(optional: B.a).joining(optional: B.c), """
SELECT "b".*, "a".* \
FROM "b" \
LEFT JOIN "a" ON ("a"."bid" = "b"."id") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
}
}
func testParallelTwoJoiningIncluding() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.joining(required: A.b).including(required: A.d), """
SELECT "a".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.joining(required: A.b).including(optional: A.d), """
SELECT "a".*, "d".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.joining(optional: A.b).including(required: A.d), """
SELECT "a".*, "d".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.joining(optional: A.b).including(optional: A.d), """
SELECT "a".*, "d".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, B.joining(required: B.a).including(required: B.c), """
SELECT "b".*, "c".* \
FROM "b" \
JOIN "a" ON ("a"."bid" = "b"."id") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.joining(required: B.a).including(optional: B.c), """
SELECT "b".*, "c".* \
FROM "b" \
JOIN "a" ON ("a"."bid" = "b"."id") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.joining(optional: B.a).including(required: B.c), """
SELECT "b".*, "c".* \
FROM "b" \
LEFT JOIN "a" ON ("a"."bid" = "b"."id") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.joining(optional: B.a).including(optional: B.c), """
SELECT "b".*, "c".* \
FROM "b" \
LEFT JOIN "a" ON ("a"."bid" = "b"."id") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
}
}
func testParallelTwoJoiningJoining() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
try assertEqualSQL(db, A.joining(required: A.b).joining(required: A.d), """
SELECT "a".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.joining(required: A.b).joining(optional: A.d), """
SELECT "a".* \
FROM "a" \
JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.joining(optional: A.b).joining(required: A.d), """
SELECT "a".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, A.joining(optional: A.b).joining(optional: A.d), """
SELECT "a".* \
FROM "a" \
LEFT JOIN "b" ON ("b"."id" = "a"."bid") \
LEFT JOIN "d" ON ("d"."id" = "a"."did")
""")
try assertEqualSQL(db, B.joining(required: B.a).joining(required: B.c), """
SELECT "b".* \
FROM "b" \
JOIN "a" ON ("a"."bid" = "b"."id") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.joining(required: B.a).joining(optional: B.c), """
SELECT "b".* \
FROM "b" \
JOIN "a" ON ("a"."bid" = "b"."id") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.joining(optional: B.a).joining(required: B.c), """
SELECT "b".* \
FROM "b" \
LEFT JOIN "a" ON ("a"."bid" = "b"."id") \
JOIN "c" ON ("c"."bid" = "b"."id")
""")
try assertEqualSQL(db, B.joining(optional: B.a).joining(optional: B.c), """
SELECT "b".* \
FROM "b" \
LEFT JOIN "a" ON ("a"."bid" = "b"."id") \
LEFT JOIN "c" ON ("c"."bid" = "b"."id")
""")
}
}
}
@@ -0,0 +1,244 @@
import XCTest
#if GRDBCIPHER
@testable import GRDBCipher
#elseif GRDBCUSTOMSQLITE
@testable import GRDBCustomSQLite
#else
@testable import GRDB
#endif
// a -> b* -> c
// -> d*
// -> c*
private struct A: TableRecord, FetchableRecord, Decodable {
static let databaseTableName = "a"
static let b = hasOne(B.self)
static let c = hasOne(C.self)
var id: Int64
}
private struct B: TableRecord, FetchableRecord, Decodable {
static let databaseTableName = "b"
static let c = hasOne(C.self)
static let d = hasOne(D.self)
var id: Int64
var aid: Int64
}
private struct C: TableRecord, FetchableRecord, Decodable {
static let databaseTableName = "c"
var id: Int64
var aid: Int64?
var bid: Int64?
}
private struct D: TableRecord, FetchableRecord, Decodable {
static let databaseTableName = "d"
var id: Int64
var bid: Int64
}
class AssociationRowScopeSearchTests: GRDBTestCase {
override func setup(_ dbWriter: DatabaseWriter) throws {
try dbWriter.write { db in
// 1. Prepare data
try db.create(table: "a") { t in
t.column("id", .integer).primaryKey()
}
try db.create(table: "b") { t in
t.column("id", .integer).primaryKey()
t.column("aid", .integer).references("a")
}
try db.create(table: "c") { t in
t.column("id", .integer).primaryKey()
t.column("aid", .integer).references("a")
t.column("bid", .integer).references("b")
}
try db.create(table: "d") { t in
t.column("id", .integer).primaryKey()
t.column("bid", .integer).references("b")
}
try db.execute("INSERT INTO a (id) VALUES (1)")
try db.execute("INSERT INTO b (id, aid) VALUES (2, 1)")
try db.execute("INSERT INTO c (id, aid, bid) VALUES (3, NULL, 2)")
try db.execute("INSERT INTO c (id, aid, bid) VALUES (4, 1, NULL)")
try db.execute("INSERT INTO d (id, bid) VALUES (5, 2)")
}
}
private let testedRequest = A
.including(required: A.b
.including(required: B.c)
.including(required: B.d)
)
.including(required: A.c)
func testTestedRequest() throws {
// Assert that we fetch the expected nested scopes before we start testing breadth-first lookup
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let rows = try testedRequest.asRequest(of: Row.self).fetchAll(db)
XCTAssertEqual(rows.count, 1)
let row = rows[0]
XCTAssertEqual(row.unscoped, ["id": 1])
XCTAssertEqual(row.scopes["b"]!.unscoped, ["id": 2, "aid": 1])
XCTAssertEqual(row.scopes["b"]!.scopes["c"]!, ["id": 3, "aid": nil, "bid": 2])
XCTAssertEqual(row.scopes["b"]!.scopes["d"]!, ["id": 5, "bid": 2])
XCTAssertEqual(row.scopes["c"]!, ["id": 4, "aid": 1, "bid": nil])
}
}
func testBreadthFirstScopeLookup() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let row = try testedRequest.asRequest(of: Row.self).fetchOne(db)!
XCTAssertEqual(row.scopesTree["b"]!.unscoped, ["id": 2, "aid": 1])
XCTAssertEqual(row.scopesTree["c"]!, ["id": 4, "aid": 1, "bid": nil])
XCTAssertEqual(row.scopesTree["d"]!, ["id": 5, "bid": 2])
}
}
func testFetchableRecordDecoding() throws {
struct Record: FetchableRecord {
var a: A
var b: B
var c: C
var d: D
init(row: Row) {
a = A(row: row)
b = row["b"]
c = row["c"]
d = row["d"]
}
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let record = try testedRequest.asRequest(of: Record.self).fetchOne(db)!
XCTAssertEqual(record.a.id, 1)
XCTAssertEqual(record.b.id, 2)
XCTAssertEqual(record.b.aid, 1)
XCTAssertEqual(record.c.id, 4)
XCTAssertEqual(record.c.aid, 1)
XCTAssertNil(record.c.bid)
XCTAssertEqual(record.d.id, 5)
XCTAssertEqual(record.d.bid, 2)
}
}
func testFlatDecodableRecordDecoding() throws {
struct Record: FetchableRecord, Decodable {
var a: A
var b: B
var c: C
var d: D
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let record = try testedRequest.asRequest(of: Record.self).fetchOne(db)!
XCTAssertEqual(record.a.id, 1)
XCTAssertEqual(record.b.id, 2)
XCTAssertEqual(record.b.aid, 1)
XCTAssertEqual(record.c.id, 4)
XCTAssertEqual(record.c.aid, 1)
XCTAssertNil(record.c.bid)
XCTAssertEqual(record.d.id, 5)
XCTAssertEqual(record.d.bid, 2)
}
}
func testNestedDecodableRecordDecoding() throws {
struct NestedB: Decodable {
var b: B
var c: C
var d: D
}
struct Record: FetchableRecord, Decodable {
var a: A
var b: NestedB
var c: C
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let record = try testedRequest.asRequest(of: Record.self).fetchOne(db)!
XCTAssertEqual(record.a.id, 1)
XCTAssertEqual(record.b.b.id, 2)
XCTAssertEqual(record.b.b.aid, 1)
XCTAssertEqual(record.b.c.id, 3)
XCTAssertNil(record.b.c.aid)
XCTAssertEqual(record.b.c.bid, 2)
XCTAssertEqual(record.b.d.id, 5)
XCTAssertEqual(record.b.d.bid, 2)
XCTAssertEqual(record.c.id, 4)
XCTAssertEqual(record.c.aid, 1)
XCTAssertNil(record.c.bid)
}
}
func testDecodableWithCustomRowDecoding() throws {
struct CustomA: FetchableRecord, Decodable {
var id: Int64
var custom: Bool?
init(row: Row) {
id = row["id"]
custom = true
}
}
struct CustomB: FetchableRecord, Decodable {
var id: Int64
var aid: Int64
var custom: Bool?
init(row: Row) {
id = row["id"]
aid = row["aid"]
custom = true
}
}
struct CustomC: FetchableRecord, Decodable {
var id: Int64
var aid: Int64?
var bid: Int64?
var custom: Bool?
init(row: Row) {
id = row["id"]
aid = row["aid"]
bid = row["bid"]
custom = true
}
}
struct CustomD: FetchableRecord, Decodable {
var id: Int64
var bid: Int64
var custom: Bool?
init(row: Row) {
id = row["id"]
bid = row["bid"]
custom = true
}
}
struct Record: FetchableRecord, Decodable {
var a: CustomA
var b: CustomB
var c: CustomC
var d: CustomD
}
let dbQueue = try makeDatabaseQueue()
try dbQueue.inDatabase { db in
let record = try testedRequest.asRequest(of: Record.self).fetchOne(db)!
XCTAssertEqual(record.a.id, 1)
XCTAssertEqual(record.a.custom, true)
XCTAssertEqual(record.b.id, 2)
XCTAssertEqual(record.b.aid, 1)
XCTAssertEqual(record.b.custom, true)
XCTAssertEqual(record.c.id, 4)
XCTAssertEqual(record.c.aid, 1)
XCTAssertNil(record.c.bid)
XCTAssertEqual(record.c.custom, true)
XCTAssertEqual(record.d.id, 5)
XCTAssertEqual(record.d.bid, 2)
XCTAssertEqual(record.d.custom, true)
}
}
}
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff. Show more