├── .gitmodules
├── .swift-version
├── Tests
├── SwiftKueryTests
│ ├── port.txt
│ ├── host.txt
│ ├── password.txt
│ ├── username.txt
│ ├── TestRaw.swift
│ ├── TestAlias.swift
│ ├── TestParameters.swift
│ ├── VerifyLinuxTestCount.swift
│ ├── TestJoin.swift
│ ├── TestSubquery.swift
│ └── TestAggregateFunctions.swift
└── LinuxMain.swift
├── .gitignore
├── docs
├── img
│ ├── dash.png
│ ├── gh.png
│ ├── carat.png
│ └── spinner.gif
├── docsets
│ ├── SwiftKuery.tgz
│ └── SwiftKuery.docset
│ │ └── Contents
│ │ ├── Resources
│ │ ├── docSet.dsidx
│ │ └── Documents
│ │ │ ├── img
│ │ │ ├── dash.png
│ │ │ ├── gh.png
│ │ │ ├── carat.png
│ │ │ └── spinner.gif
│ │ │ ├── js
│ │ │ ├── jazzy.js
│ │ │ └── jazzy.search.js
│ │ │ └── css
│ │ │ └── highlight.css
│ │ └── Info.plist
├── badge.svg
├── js
│ ├── jazzy.js
│ └── jazzy.search.js
├── undocumented.json
└── css
│ └── highlight.css
├── docker.compose.yml
├── .jazzy.yaml
├── Sources
└── SwiftKuery
│ ├── PreparedStatement.swift
│ ├── QuerySuffixProtocol.swift
│ ├── IndexColumn.swift
│ ├── Buildable.swift
│ ├── String+Buildable.swift
│ ├── OrderBy.swift
│ ├── ResultFetcher.swift
│ ├── Union.swift
│ ├── Field.swift
│ ├── RawField.swift
│ ├── ConnectionPoolOptions.swift
│ ├── FilterAndHaving_Extensions.swift
│ ├── Query.swift
│ ├── QueryError.swift
│ ├── Raw.swift
│ ├── Join.swift
│ ├── Parameter.swift
│ ├── IndexColumnOrdered.swift
│ ├── With.swift
│ ├── Condition.swift
│ ├── ColumnCreator.swift
│ ├── ResultSet.swift
│ ├── Filter.swift
│ ├── Having.swift
│ ├── Index.swift
│ ├── Predicate.swift
│ ├── ForeignKey.swift
│ ├── Delete.swift
│ ├── Utils.swift
│ ├── Update.swift
│ ├── AuxiliaryTable.swift
│ ├── Migration.swift
│ ├── ConditionalClause.swift
│ └── SQLDataType.swift
├── Scripts
├── TestAggregate.txt
├── TestAggregateScalar.txt
├── runScripts.sh
├── ColumnExtensionClauses.txt
├── ColumnExtensionOperands.txt
├── FilterAndHavingBoolOperators.txt
├── SimpleOperators.txt
├── TestLike.txt
├── FilterAndHavingBoolTypes.txt
├── InSelectTypes.txt
├── filterAndHavingExtensions.sh
├── SubqueriesTypes.txt
├── TestBetweenAndIn.txt
├── simpleOperators.sh
├── subqueries.sh
├── testSimpleOperators.sh
├── testAggregate.sh
└── columnExtensions.sh
├── .travis.yml
└── Package.swift
/.gitmodules:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.swift-version:
--------------------------------------------------------------------------------
1 | 5.1
2 |
--------------------------------------------------------------------------------
/Tests/SwiftKueryTests/port.txt:
--------------------------------------------------------------------------------
1 | 5432
2 |
--------------------------------------------------------------------------------
/Tests/SwiftKueryTests/host.txt:
--------------------------------------------------------------------------------
1 | localhost
2 |
--------------------------------------------------------------------------------
/Tests/SwiftKueryTests/password.txt:
--------------------------------------------------------------------------------
1 | kitura
2 |
--------------------------------------------------------------------------------
/Tests/SwiftKueryTests/username.txt:
--------------------------------------------------------------------------------
1 | postgres
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.xcodeproj/
2 | .build
3 | build
4 | Package.resolved
5 | .DS_Store
--------------------------------------------------------------------------------
/docs/img/dash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/img/dash.png
--------------------------------------------------------------------------------
/docs/img/gh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/img/gh.png
--------------------------------------------------------------------------------
/docs/img/carat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/img/carat.png
--------------------------------------------------------------------------------
/docs/img/spinner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/img/spinner.gif
--------------------------------------------------------------------------------
/docs/docsets/SwiftKuery.tgz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/docsets/SwiftKuery.tgz
--------------------------------------------------------------------------------
/docs/docsets/SwiftKuery.docset/Contents/Resources/docSet.dsidx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/docsets/SwiftKuery.docset/Contents/Resources/docSet.dsidx
--------------------------------------------------------------------------------
/docker.compose.yml:
--------------------------------------------------------------------------------
1 | test:
2 | image: ibmcom/swift-ubuntu:4.0.3
3 | volumes:
4 | - .:/Swift-Kuery
5 | command: bash -c "cd /Swift-Kuery && swift package clean && swift build"
6 |
--------------------------------------------------------------------------------
/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/img/dash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/img/dash.png
--------------------------------------------------------------------------------
/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/img/gh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/img/gh.png
--------------------------------------------------------------------------------
/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/img/carat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/img/carat.png
--------------------------------------------------------------------------------
/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/img/spinner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kitura/Swift-Kuery/HEAD/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/img/spinner.gif
--------------------------------------------------------------------------------
/.jazzy.yaml:
--------------------------------------------------------------------------------
1 | module: SwiftKuery
2 | author: IBM & Kitura project authors
3 | github_url: https://github.com/Kitura/Swift-Kuery/
4 |
5 | theme: fullwidth
6 | clean: true
7 | exclude: [Packages]
8 |
9 | readme: README.md
10 |
11 | skip_undocumented: false
12 | hide_documentation_coverage: false
13 |
--------------------------------------------------------------------------------
/docs/docsets/SwiftKuery.docset/Contents/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleIdentifier
6 | com.jazzy.swiftkuery
7 | CFBundleName
8 | SwiftKuery
9 | DocSetPlatformFamily
10 | swiftkuery
11 | isDashDocset
12 |
13 | dashIndexFilePath
14 | index.html
15 | isJavaScriptEnabled
16 |
17 | DashDocSetFamily
18 | dashtoc
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/PreparedStatement.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2017
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: Prepared statement
18 |
19 | /// A protocol for database specific prepared statements to implement.
20 | public protocol PreparedStatement {}
21 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/QuerySuffixProtocol.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2017
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: QuerySuffixProtocol
18 |
19 | /// Defines the protocol which should be used for all suffix clauses.
20 | public protocol QuerySuffixProtocol: Buildable {
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/Scripts/TestAggregate.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # Aggregate functions to test. Used in testAggregate.sh. The resulting test file is TestAggregateFunctions.swift.
18 | avg AVG
19 | max MAX
20 | min MIN
21 | sum SUM
22 | last LAST
23 | first FIRST
24 | count COUNT
25 |
26 |
--------------------------------------------------------------------------------
/Scripts/TestAggregateScalar.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # Scalar functions with aggregate function as an argument to test.
18 | # Used in testAggregate.sh. The resulting test file is TestAggregateFunctions.swift.
19 |
20 | ucase UCASE
21 | lcase LCASE
22 | len LEN
23 |
24 |
--------------------------------------------------------------------------------
/Scripts/runScripts.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Copyright IBM Corporation 2016
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | SCRIPT_DIR=$(dirname "$BASH_SOURCE")
18 | cd "$SCRIPT_DIR"
19 |
20 | ./columnExtensions.sh
21 | ./simpleOperators.sh
22 | ./specialOperators.sh
23 | ./subqueries.sh
24 | ./filterAndHavingExtensions.sh
25 |
26 | ./testSimpleOperators.sh
27 | ./testAggregate.sh
28 | ./testSpecialOperators.sh
29 | ./testSubqueries.sh
30 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/IndexColumn.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2017
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: IndexColumn
18 |
19 | /// A protocol for columns used in indices.
20 | public protocol IndexColumn {
21 | /// Build the index column using `QueryBuilder`.
22 | ///
23 | /// - Parameter queryBuilder: The QueryBuilder to use.
24 | /// - Returns: A String representation of the index column.
25 | func buildIndex(queryBuilder: QueryBuilder) -> String
26 |
27 | var table: Table { get }
28 | }
29 |
--------------------------------------------------------------------------------
/Scripts/ColumnExtensionClauses.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016, 2017
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # An input file for columnExtension.sh that generates extensions for Column, ScalarColumnExpression
18 | # and AggregateColumnExpression for (NOT)LIKE, (NOT)BETWEEN, and (NOT)IN operators.
19 | # This file contains the pairs of (Filter/Having, type to extend).
20 | # The generated code is in Sources/SwiftKuery/ColumnAndExpressions_Extensions.swift.
21 |
22 | Filter ScalarColumnExpression
23 | Filter Column
24 | Having AggregateColumnExpression
25 | Having Column
26 |
--------------------------------------------------------------------------------
/docs/badge.svg:
--------------------------------------------------------------------------------
1 |
29 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/Buildable.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: Buildable protocol
18 |
19 | /// Defines the protocol which all query components must implement.
20 | /// Each query component should be able to return its representation as a String.
21 | public protocol Buildable {
22 | /// Build the query component using `QueryBuilder`.
23 | ///
24 | /// - Parameter queryBuilder: The QueryBuilder to use.
25 | /// - Returns: A String representation of the query component.
26 | /// - Throws: QueryError.syntaxError if query build fails.
27 | func build(queryBuilder: QueryBuilder) throws -> String
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/Scripts/ColumnExtensionOperands.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016, 2017
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # An input file for columnExtension.sh that generates extensions for Column, ScalarColumnExpression,
18 | # and AggregateColumnExpression for (NOT)LIKE, (NOT)BETWEEN, and (NOT)IN operators.
19 | # This file contains the types of the operands.
20 | # The generated code is in Sources/SwiftKuery/ColumnAndExpressions_Extensions.swift.
21 |
22 | # It is also an input for specialOperators.sh that generates extensions for the types listed in this file for the same operators.
23 | # The generated code is in Sources/SwiftKuery/SpecialOperators_Extensions.swift.
24 |
25 | Bool
26 | String
27 | Int
28 | Float
29 | Double
30 | Parameter
31 | Date
32 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/String+Buildable.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016, 2017
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: String extensions
18 |
19 | /// The String extension with `QueryFilterProtocol` and `QueryHavingProtocol`.
20 | /// Enables the use if `String` in query as filtering clauses.
21 | extension String: QueryFilterProtocol, QueryHavingProtocol, QuerySuffixProtocol {
22 |
23 | /// Process `String` as raw SQL using `QueryBuilder`.
24 | ///
25 | /// - Parameter queryBuilder: The QueryBuilder to use.
26 | /// - Returns: A String representation of the query.
27 | /// - Throws: QueryError.syntaxError if query build fails.
28 | public func build(queryBuilder: QueryBuilder) throws -> String {
29 | return self
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Scripts/FilterAndHavingBoolOperators.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016, 2017
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # An input file for simpleOperators.sh that generates global operators for simple conditions that return Filter and Having clauses.
18 | # This file contains both the operators and the types for conditions with Bool as a type of one of the operands.
19 | # The last entry is ignored.
20 | # The generated code is in Sources/SwiftKuery/FilterAndHaving_GlobalFunctions.swift.
21 |
22 | # This is also an input file for testSimpleOperators.sh that generates the tests for the code created by simpleOperators.sh.
23 | # The format is (operator in query creation, Condition case (ignored), SQL operator).
24 | # The generated tests are in TestFilterAndHaving.swift
25 | == equal =
26 | != notEqual <>
27 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # Travis CI build file.
2 |
3 | # whitelist (branches that should be built)
4 | branches:
5 | only:
6 | - master
7 | - next
8 | - /^issue.*$/
9 |
10 | # the matrix of builds should cover each combination of Swift version
11 | # and platform that is supported. The version of Swift used is specified
12 | # by .swift-version, unless SWIFT_SNAPSHOT is specified.
13 | matrix:
14 | include:
15 | - os: linux
16 | dist: xenial
17 | sudo: required
18 | services: docker
19 | env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci-ubuntu16.04:5.1.5
20 | - os: linux
21 | dist: bionic
22 | sudo: required
23 | services: docker
24 | env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci-ubuntu18.04:5.4
25 | - os: linux
26 | dist: xenial
27 | sudo: required
28 | services: docker
29 | env: DOCKER_IMAGE=docker.kitura.net/kitura/swift-ci-ubuntu18.04:latest USE_SWIFT_DEVELOPMENT_SNAPSHOT=1
30 | - os: osx
31 | osx_image: xcode11
32 | sudo: required
33 | env: SWIFT_SNAPSHOT=5.1.5 JAZZY_ELIGIBLE=true
34 | - os: osx
35 | osx_image: xcode12.2
36 | sudo: required
37 | - os: osx
38 | osx_image: xcode12.5
39 | sudo: required
40 | env: USE_SWIFT_DEVELOPMENT_SNAPSHOT=1
41 |
42 | before_install:
43 | - git clone https://github.com/Kitura/Package-Builder.git
44 |
45 | script:
46 | - ./Package-Builder/build-package.sh -projectDir $TRAVIS_BUILD_DIR
47 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/OrderBy.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: OrderBy
18 |
19 | /// An SQL ORDER BY clause.
20 | public enum OrderBy: Buildable {
21 | /// Order ascending.
22 | case ASC(Field)
23 | /// Order descending.
24 | case DESC(Field)
25 |
26 | /// Build the query component using `QueryBuilder`.
27 | ///
28 | /// - Parameter queryBuilder: The QueryBuilder to use.
29 | /// - Returns: A String representation of the query component.
30 | /// - Throws: QueryError.syntaxError if query build fails.
31 | public func build(queryBuilder: QueryBuilder) throws -> String {
32 | switch self {
33 | case .ASC(let field):
34 | return try field.build(queryBuilder: queryBuilder) + " ASC"
35 | case .DESC(let field):
36 | return try field.build(queryBuilder: queryBuilder) + " DESC"
37 | }
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/ResultFetcher.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: ResultFetcher protocol
18 |
19 | /// A protocol for retrieving query results. All database plugins must implement this protocol.
20 | public protocol ResultFetcher {
21 |
22 | /// Fetch the next row of the query result. This function is non-blocking.
23 | ///
24 | /// - Parameter callback: A callback to call when the next row of the query result is ready.
25 | func fetchNext(callback: @escaping (([Any?]?, Error?)) ->())
26 |
27 | /// Fetch the titles of the query result. This function is non-blocking.
28 | ///
29 | /// - Parameter callback: A callback to call when the column titles of the query result are ready.
30 | func fetchTitles(callback: @escaping (([String]?, Error?)) -> ())
31 |
32 | /// Closes any underlying database connections and releases system resources synchronously
33 | ///
34 | func done()
35 | }
36 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/Union.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: Union
18 |
19 | /// The SQL SELECT UNION/UNION ALL statement.
20 | public enum Union: Buildable {
21 | /// The SQL UNION statement.
22 | case union(Select)
23 | /// The SQL UNION ALL statement.
24 | case unionAll(Select)
25 |
26 | /// Build the query component using `QueryBuilder`.
27 | ///
28 | /// - Parameter queryBuilder: The QueryBuilder to use.
29 | /// - Returns: A String representation of the query component.
30 | /// - Throws: QueryError.syntaxError if query build fails.
31 | public func build(queryBuilder: QueryBuilder) throws -> String {
32 | switch self {
33 | case .union(let query):
34 | return try " UNION " + query.build(queryBuilder: queryBuilder)
35 | case .unionAll(let query):
36 | return try " UNION ALL " + query.build(queryBuilder: queryBuilder)
37 | }
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/Field.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 |
18 | // MARK: Field protocol
19 |
20 | /// Defines the protocol for columns, and aggregate and scalar functions on columns.
21 | public protocol Field: Buildable {
22 |
23 | /// The alias of the field.
24 | var alias: String? { get set }
25 |
26 | /// Add an alias to the field, i.e., implement the SQL AS operator.
27 | ///
28 | /// - Parameter newName: A String containing the alias for the field.
29 | /// - Returns: A new Field instance with the alias.
30 | func `as`(_ newName: String) -> Field
31 | }
32 |
33 | extension Field {
34 | /// Add an alias to the field, i.e., implement the SQL AS operator.
35 | ///
36 | /// - Parameter newName: A String containing the alias for the field.
37 | /// - Returns: A new Field instance with the alias.
38 | public func `as`(_ newName: String) -> Field {
39 | var new = self
40 | new.alias = newName
41 | return new
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/RawField.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: RawField
18 |
19 | /// An arbitrary field represented by a String.
20 | public struct RawField: Field {
21 | /// A String containg the field.
22 | public let field: String
23 |
24 | /// The alias of the field.
25 | public var alias: String?
26 |
27 | /// Initialize an instance of RawField.
28 | ///
29 | /// - Parameter field: A String containing the field.
30 | public init(_ field: String) {
31 | self.field = field
32 | }
33 |
34 | /// Build the field using `QueryBuilder`.
35 | ///
36 | /// - Parameter queryBuilder: The QueryBuilder to use.
37 | /// - Returns: A String representation of the field.
38 | public func build(queryBuilder: QueryBuilder) -> String {
39 | var result = field
40 | if let alias = alias {
41 | result += " AS " + Utils.packName(alias, queryBuilder: queryBuilder)
42 | }
43 | return result
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Scripts/SimpleOperators.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016, 2017
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # An input file for simpleOperators.sh that generates global operators for simple conditions that return Filter and Having clauses.
18 | # This file contains the operators.
19 | # The generated code is in Sources/SwiftKuery/FilterAndHaving_GlobalFunctions.swift.
20 |
21 | # An input file for subqueries.sh that generates global operators with subqueries (i.e. 'expression operator ANY/ALL(subquery)').
22 | # The generated code is in Sources/SwiftKuery/Subqueries_GlobalFunctionsAndExtensions.swift.
23 |
24 | # This is also an input file for testSimpleOperators.sh that generates the tests for the code created by simpleOperators.sh.
25 | # The generated tests are in TestFilterAndHaving.swift
26 |
27 | # This is also an input file for testSubquries.sh that generates the tests for the code created by subqueries.sh.
28 | # The generated tests are in TestSubqueries.swift
29 |
30 | == equal =
31 | >= greaterThanOrEqual >=
32 | > greaterThan >
33 | <= lessThanOrEqual <=
34 | < lessThan <
35 | != notEqual <>
36 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/ConnectionPoolOptions.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2017
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 |
18 | // MARK: ConnectionPoolOptions
19 |
20 | /// Options for `ConectionPool` configuration.
21 | public struct ConnectionPoolOptions {
22 | /// The initial number of connections in the pool.
23 | public let initialCapacity: Int
24 |
25 | /// The maximum number of connections in the pool. The pool is allowed to grow from `initialCapacity` up to
26 | /// this limit. If not specified, or `maxCapacity` <= `initialCapacity`, the pool cannot grow.
27 | public let maxCapacity: Int
28 |
29 | /// Initialize an instance of `ConnectionPoolOptions`.
30 | ///
31 | /// - Parameter initialCapacity: The initial number of connections in the pool.
32 | /// - Parameter maxCapacity: The maximum number of connections in the pool
33 | /// - Parameter timeout: Maximum wait (in milliseconds) to receive a connection before returning nil.
34 | public init(initialCapacity: Int, maxCapacity: Int = 0) {
35 | self.initialCapacity = initialCapacity
36 | self.maxCapacity = maxCapacity
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Scripts/TestLike.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016, 2017
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # Arguments of the LIKE operator: operand.like(argument).
18 | # The format of each line is (where/having, operand in Swift, operand in SQL, argument in Swift, argument in SQL).
19 | # Used in testSpecialOperators.sh. The resulting test file is TestSpecialOperators.swift.
20 |
21 | where t.a table.a "%kuery%" '%kuery%'
22 | having t.a table.a "%kuery%" '%kuery%'
23 | where t.a table.a Parameter() \?1
24 | having t.a table.a Parameter() \?1
25 | where ucase(t.a) UCASE(table.a) "%kuery%" '%kuery%'
26 | having first(t.a) FIRST(table.a) "%kuery%" '%kuery%'
27 | where ucase(t.a) UCASE(table.a) Parameter() \?1
28 | having first(t.a) FIRST(table.a) Parameter() \?1
29 | where "swift-kuery" 'swift-kuery' "%kuery%" '%kuery%'
30 | having "swift-kuery" 'swift-kuery' "%kuery%" '%kuery%'
31 | where "swift-kuery" 'swift-kuery' Parameter() \?1
32 | having "swift-kuery" 'swift-kuery' Parameter() \?1
33 | where Parameter() \?1 "%kuery%" '%kuery%'
34 | having Parameter("first") @first "%kuery%" '%kuery%'
35 | where Parameter("first") @first Parameter() \?1
36 | having Parameter() \?1 Parameter() \?2
37 |
--------------------------------------------------------------------------------
/Tests/SwiftKueryTests/TestRaw.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | import XCTest
18 |
19 | @testable import SwiftKuery
20 | class TestRaw: XCTestCase {
21 |
22 | static var allTests: [(String, (TestRaw) -> () throws -> Void)] {
23 | return [
24 | ("testRaw", testRaw),
25 | ]
26 | }
27 |
28 | class MyTable : Table {
29 | let a = Column("a")
30 | let b = Column("b")
31 |
32 | let tableName = "tableRaw"
33 | }
34 |
35 | func testRaw () {
36 | let t = MyTable()
37 | let connection = createConnection()
38 |
39 | var r = Raw(query: "DROP TABLE", table: t)
40 | var kuery = connection.descriptionOf(query: r)
41 | var query = "DROP TABLE \"tableRaw\""
42 | XCTAssertEqual(kuery, query, "\nError in query construction: \n\(kuery) \ninstead of \n\(query)")
43 |
44 | r = Raw(query: "DROP TABLE", tables: [t])
45 | kuery = connection.descriptionOf(query: r)
46 | query = "DROP TABLE \"tableRaw\""
47 | XCTAssertEqual(kuery, query, "\nError in query construction: \n\(kuery) \ninstead of \n\(query)")
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/FilterAndHaving_Extensions.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright IBM Corporation 2016, 2017
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | **/
16 |
17 | extension Filter {
18 |
19 | /// Create a `Filter` clause using the isNull operator.
20 | ///
21 | /// - Returns: A `Filter` containing the clause.
22 | public func isNull() -> Filter {
23 | return Filter(lhs: .clause(self), condition: .isNull)
24 | }
25 |
26 | /// Create a `Filter` clause using the isNotNull operator.
27 | ///
28 | /// - Returns: A `Filter` containing the clause.
29 | public func isNotNull() -> Filter {
30 | return Filter(lhs: .clause(self), condition: .isNotNull)
31 | }
32 | }
33 | extension Having {
34 |
35 | /// Create a `Having` clause using the isNull operator.
36 | ///
37 | /// - Returns: A `Having` containing the clause.
38 | public func isNull() -> Having {
39 | return Having(lhs: .clause(self), condition: .isNull)
40 | }
41 |
42 | /// Create a `Having` clause using the isNotNull operator.
43 | ///
44 | /// - Returns: A `Having` containing the clause.
45 | public func isNotNull() -> Having {
46 | return Having(lhs: .clause(self), condition: .isNotNull)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/Query.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: Query protocol
18 |
19 | /// Defines the protocol for queries.
20 | public protocol Query: Buildable {
21 | }
22 |
23 | extension Query {
24 | /// Execute the query.
25 | ///
26 | /// - Parameter connection: The plugin that implements the Connection protocol and executes the query.
27 | /// - Parameter onCompletion: The function to be called when the execution of the query has completed.
28 | public func execute(_ connection: Connection, onCompletion: @escaping ((QueryResult) -> ())) {
29 | connection.execute(query: self, onCompletion: onCompletion)
30 | }
31 |
32 | /// Execute the query with parameters.
33 | ///
34 | /// - Parameter connection: The plugin that implements the Connection protocol and executes the query.
35 | /// - Parameter parameters: An array of the query parameters.
36 | /// - Parameter onCompletion: The function to be called when the execution of the query has completed.
37 | public func execute(_ connection: Connection, parameters: [Any], onCompletion: @escaping ((QueryResult) -> ())) {
38 | connection.execute(query: self, parameters: parameters, onCompletion: onCompletion)
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.0
2 | // The swift-tools-version declares the minimum version of Swift required to build this package.
3 |
4 | /**
5 | * Copyright IBM Corporation and the Kitura project authors 2016-2020
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | **/
19 |
20 | import PackageDescription
21 |
22 | let package = Package(
23 | name: "SwiftKuery",
24 | products: [
25 | // Products define the executables and libraries produced by a package, and make them visible to other packages.
26 | .library(
27 | name: "SwiftKuery",
28 | targets: ["SwiftKuery"]),
29 | ],
30 | dependencies: [
31 | // Dependencies declare other packages that this package depends on.
32 | // .package(url: /* package url */, from: "1.0.0"),
33 | .package(url: "https://github.com/Kitura/LoggerAPI.git", from: "1.9.200"),
34 | ],
35 | targets: [
36 | // Targets are the basic building blocks of a package. A target defines a module or a test suite.
37 | // Targets can depend on other targets in this package, and on products in packages which this package depends on.
38 | .target(
39 | name: "SwiftKuery",
40 | dependencies: ["LoggerAPI"]),
41 | .testTarget(
42 | name: "SwiftKueryTests",
43 | dependencies: ["SwiftKuery"]),
44 | ]
45 | )
46 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/QueryError.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016, 2017
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: QueryError
18 |
19 | /// An enumeration of errors that may occur during query construction and execution.
20 | public enum QueryError: Error {
21 | /// An error connecting to the database.
22 | case connection(String)
23 | /// No result was received from the query execution.
24 | case noResult(String)
25 | /// The database generated an error for the query execution.
26 | case databaseError(String)
27 | /// A syntax error occurred while constructing the query.
28 | case syntaxError(String)
29 | /// The query or its execution is not supported.
30 | case unsupported(String)
31 | /// An error in transaction.
32 | case transactionError(String)
33 | }
34 |
35 | extension QueryError: CustomStringConvertible {
36 | /// A String representation of the error.
37 | public var description: String {
38 | switch self {
39 | case .connection(let error):
40 | return error
41 | case .noResult(let error):
42 | return error
43 | case .databaseError(let error):
44 | return error
45 | case .syntaxError(let error):
46 | return error
47 | case .unsupported(let error):
48 | return error
49 | case .transactionError(let error):
50 | return error
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Scripts/FilterAndHavingBoolTypes.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016, 2017
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # An input file for simpleOperators.sh that generates global operators with Bool operands
18 | # for simple conditions that return Filter and Having clauses.
19 | # This file contains the list of all the types: each line is (Filter/Having, LHS type, RHS type) - the rest is ignored.
20 | # The generated code is in Sources/SwiftKuery/FilterAndHaving_GlobalFunctions.swift.
21 |
22 | # This is also an input file for testSimpleOperators.sh that generates the tests for the code created by simpleOperators.sh.
23 | # The first three entries in each line are ignored. The format of the rest of the line is
24 | # (where/having, first operand in Swift, second operand in Swift, first operand in SQL, second operand in SQL).
25 | # The generated tests are in TestFilterAndHaving.swift
26 |
27 | # The operators are in FilterAndHavingBoolOperators.txt
28 |
29 | Filter ScalarColumnExpression Bool where lcase(t.a) true LCASE(table.a) true
30 | Filter Bool ScalarColumnExpression where false ucase(t.a) false UCASE(table.a)
31 | Filter Column Bool where t.a true table.a true
32 | Filter Bool Column where true t.a true table.a
33 | Having AggregateColumnExpression Bool having first(t.a) true FIRST(table.a) true
34 | Having Bool AggregateColumnExpression having false last(t.a) false LAST(table.a)
35 | Having Column Bool having t.a true table.a true
36 | Having Bool Column having true t.a true table.a
37 |
--------------------------------------------------------------------------------
/docs/js/jazzy.js:
--------------------------------------------------------------------------------
1 | window.jazzy = {'docset': false}
2 | if (typeof window.dash != 'undefined') {
3 | document.documentElement.className += ' dash'
4 | window.jazzy.docset = true
5 | }
6 | if (navigator.userAgent.match(/xcode/i)) {
7 | document.documentElement.className += ' xcode'
8 | window.jazzy.docset = true
9 | }
10 |
11 | function toggleItem($link, $content) {
12 | var animationDuration = 300;
13 | $link.toggleClass('token-open');
14 | $content.slideToggle(animationDuration);
15 | }
16 |
17 | function itemLinkToContent($link) {
18 | return $link.parent().parent().next();
19 | }
20 |
21 | // On doc load + hash-change, open any targetted item
22 | function openCurrentItemIfClosed() {
23 | if (window.jazzy.docset) {
24 | return;
25 | }
26 | var $link = $(`a[name="${location.hash.substring(1)}"]`).nextAll('.token');
27 | $content = itemLinkToContent($link);
28 | if ($content.is(':hidden')) {
29 | toggleItem($link, $content);
30 | }
31 | }
32 |
33 | $(openCurrentItemIfClosed);
34 | $(window).on('hashchange', openCurrentItemIfClosed);
35 |
36 | // On item link ('token') click, toggle its discussion
37 | $('.token').on('click', function(event) {
38 | if (window.jazzy.docset) {
39 | return;
40 | }
41 | var $link = $(this);
42 | toggleItem($link, itemLinkToContent($link));
43 |
44 | // Keeps the document from jumping to the hash.
45 | var href = $link.attr('href');
46 | if (history.pushState) {
47 | history.pushState({}, '', href);
48 | } else {
49 | location.hash = href;
50 | }
51 | event.preventDefault();
52 | });
53 |
54 | // Clicks on links to the current, closed, item need to open the item
55 | $("a:not('.token')").on('click', function() {
56 | if (location == this.href) {
57 | openCurrentItemIfClosed();
58 | }
59 | });
60 |
61 | // KaTeX rendering
62 | if ("katex" in window) {
63 | $($('.math').each( (_, element) => {
64 | katex.render(element.textContent, element, {
65 | displayMode: $(element).hasClass('m-block'),
66 | throwOnError: false,
67 | trust: true
68 | });
69 | }))
70 | }
71 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/Raw.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: Raw
18 |
19 | /// An arbitrary query represented by a String. The generated query will be a concatenation of the
20 | /// supplied query string and tables.
21 | public struct Raw: Query {
22 | /// A String containing the query.
23 | public let query: String
24 |
25 | /// The table to apply the query on.
26 | public let tables: [Table]
27 |
28 | /// Initialize an instance of Raw.
29 | ///
30 | /// - Parameter query: A String containing the query.
31 | /// - Parameter table: The table(s) to apply the query on.
32 | public init(query: String, table: Table...) {
33 | self.init(query: query, tables: table)
34 | }
35 |
36 | /// Initialize an instance of Raw.
37 | ///
38 | /// - Parameter query: A String containing the query.
39 | /// - Parameter tables: An array of tables to apply the query on.
40 | public init(query: String, tables: [Table]) {
41 | self.query = query
42 | self.tables = tables
43 | }
44 |
45 | /// Build the query using `QueryBuilder`.
46 | ///
47 | /// - Parameter queryBuilder: The QueryBuilder to use.
48 | /// - Returns: A String representation of the query.
49 | /// - Throws: QueryError.syntaxError if query build fails.
50 | public func build(queryBuilder: QueryBuilder) throws -> String {
51 | return try query + " " + "\(tables.map { try $0.build(queryBuilder: queryBuilder) }.joined(separator: ", "))"
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Sources/SwiftKuery/Join.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // MARK: Join
18 |
19 | /// The SQL SELECT JOIN statement.
20 | public enum Join: Buildable {
21 | /// The SQL INNER JOIN statement.
22 | case join(Table)
23 | /// The SQL LEFT OUTER JOIN statement.
24 | case left(Table)
25 | /// The SQL CROSS JOIN statement.
26 | case cross(Table)
27 | /// The SQL NATURAL INNER JOIN statement.
28 | case natural(Table)
29 | /// A String with a join statement.
30 | case raw(String, Table)
31 |
32 | /// Build the query component using `QueryBuilder`.
33 | ///
34 | /// - Parameter queryBuilder: The QueryBuilder to use.
35 | /// - Returns: A String representation of the query component.
36 | /// - Throws: QueryError.syntaxError if query build fails.
37 | public func build(queryBuilder: QueryBuilder) throws -> String {
38 | switch self {
39 | case .join(let table):
40 | return try " JOIN " + table.build(queryBuilder: queryBuilder)
41 | case .left(let table):
42 | return try " LEFT JOIN " + table.build(queryBuilder: queryBuilder)
43 | case .cross(let table):
44 | return try " CROSS JOIN " + table.build(queryBuilder: queryBuilder)
45 | case .natural(let table):
46 | return try " NATURAL JOIN " + table.build(queryBuilder: queryBuilder)
47 | case .raw(let raw, let table):
48 | return try " " + raw + " " + table.build(queryBuilder: queryBuilder)
49 | }
50 | }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/Scripts/InSelectTypes.txt:
--------------------------------------------------------------------------------
1 | #/**
2 | #* Copyright IBM Corporation 2016, 2017
3 | #*
4 | #* Licensed under the Apache License, Version 2.0 (the "License");
5 | #* you may not use this file except in compliance with the License.
6 | #* You may obtain a copy of the License at
7 | #*
8 | #* http://www.apache.org/licenses/LICENSE-2.0
9 | #*
10 | #* Unless required by applicable law or agreed to in writing, software
11 | #* distributed under the License is distributed on an "AS IS" BASIS,
12 | #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | #* See the License for the specific language governing permissions and
14 | #* limitations under the License.
15 | #**/
16 |
17 | # An input file for subqueries.sh that generates extensions for (NOT)IN operator with a subquery.
18 | # This file contains the list of all the types for IN and NOT IN operators (the last three entries are ignored).
19 | # The generated code is in Sources/SwiftKuery/Subqueries_GlobalFunctionsAndExtensions.swift.
20 |
21 | # This is also an input file for testSubqueries.sh that generates the tests for the code created by subqueries.sh.
22 | # The first two entries in each line are ignored. The format of the rest of the line is
23 | # (where/having, first operand in Swift, first operand in SQL).
24 | # The generated tests are in TestSubqueries.swift
25 |
26 | Filter ScalarColumnExpression where lcase(t.a) LCASE(table.a)
27 | Filter String where "plum" 'plum'
28 | Filter Column where t.a table.a
29 | Filter Int where 7 7
30 | Filter Float where Float(7.8) 7.8
31 | Filter Double where (-0.9) -0.9
32 | Filter Parameter where Parameter() \?1
33 | Filter Bool where true true
34 | Filter Date where Date(timeIntervalSince1970:_0) '1970-01-01_00:00:00_+0000'
35 | Having AggregateColumnExpression having min(t.a) MIN(table.a)
36 | Having String having "plum" 'plum'
37 | Having Column having t.a table.a
38 | Having Int having 7 7
39 | Having Float having Float(7.8) 7.8
40 | Having Double having (-0.9) -0.9
41 | Having Parameter having Parameter() \?1
42 | Having Bool having false false
43 | Having Date having Date(timeIntervalSince1970:_0) '1970-01-01_00:00:00_+0000'
44 |
--------------------------------------------------------------------------------
/docs/docsets/SwiftKuery.docset/Contents/Resources/Documents/js/jazzy.js:
--------------------------------------------------------------------------------
1 | window.jazzy = {'docset': false}
2 | if (typeof window.dash != 'undefined') {
3 | document.documentElement.className += ' dash'
4 | window.jazzy.docset = true
5 | }
6 | if (navigator.userAgent.match(/xcode/i)) {
7 | document.documentElement.className += ' xcode'
8 | window.jazzy.docset = true
9 | }
10 |
11 | function toggleItem($link, $content) {
12 | var animationDuration = 300;
13 | $link.toggleClass('token-open');
14 | $content.slideToggle(animationDuration);
15 | }
16 |
17 | function itemLinkToContent($link) {
18 | return $link.parent().parent().next();
19 | }
20 |
21 | // On doc load + hash-change, open any targetted item
22 | function openCurrentItemIfClosed() {
23 | if (window.jazzy.docset) {
24 | return;
25 | }
26 | var $link = $(`a[name="${location.hash.substring(1)}"]`).nextAll('.token');
27 | $content = itemLinkToContent($link);
28 | if ($content.is(':hidden')) {
29 | toggleItem($link, $content);
30 | }
31 | }
32 |
33 | $(openCurrentItemIfClosed);
34 | $(window).on('hashchange', openCurrentItemIfClosed);
35 |
36 | // On item link ('token') click, toggle its discussion
37 | $('.token').on('click', function(event) {
38 | if (window.jazzy.docset) {
39 | return;
40 | }
41 | var $link = $(this);
42 | toggleItem($link, itemLinkToContent($link));
43 |
44 | // Keeps the document from jumping to the hash.
45 | var href = $link.attr('href');
46 | if (history.pushState) {
47 | history.pushState({}, '', href);
48 | } else {
49 | location.hash = href;
50 | }
51 | event.preventDefault();
52 | });
53 |
54 | // Clicks on links to the current, closed, item need to open the item
55 | $("a:not('.token')").on('click', function() {
56 | if (location == this.href) {
57 | openCurrentItemIfClosed();
58 | }
59 | });
60 |
61 | // KaTeX rendering
62 | if ("katex" in window) {
63 | $($('.math').each( (_, element) => {
64 | katex.render(element.textContent, element, {
65 | displayMode: $(element).hasClass('m-block'),
66 | throwOnError: false,
67 | trust: true
68 | });
69 | }))
70 | }
71 |
--------------------------------------------------------------------------------
/Tests/SwiftKueryTests/TestAlias.swift:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright IBM Corporation 2016
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | import XCTest
18 |
19 | @testable import SwiftKuery
20 |
21 | class TestAlias: XCTestCase {
22 |
23 | static var allTests: [(String, (TestAlias) -> () throws -> Void)] {
24 | return [
25 | ("testAlias", testAlias),
26 | ]
27 | }
28 |
29 | class MyTable : Table {
30 | let a = Column("a")
31 | let b = Column("b")
32 |
33 | let tableName = "tableAlias"
34 | }
35 |
36 | func testAlias() {
37 | let t = MyTable()
38 | let connection = createConnection()
39 |
40 | var s = Select(t.a.as("\"fruit name\""), t.b.as("number"), from: t)
41 | var kuery = connection.descriptionOf(query: s)
42 | var query = "SELECT \"tableAlias\".\"a\" AS \"fruit name\", \"tableAlias\".\"b\" AS \"number\" FROM \"tableAlias\""
43 | XCTAssertEqual(kuery, query, "\nError in query construction: \n\(kuery) \ninstead of \n\(query)")
44 |
45 | s = Select(from: t.as("new"))
46 | kuery = connection.descriptionOf(query: s)
47 | query = "SELECT * FROM \"tableAlias\" AS \"new\""
48 | XCTAssertEqual(kuery, query, "\nError in query construction: \n\(kuery) \ninstead of \n\(query)")
49 |
50 | let t2 = t.as("\"t 2\"")
51 | s = Select(t2.a, from: t2)
52 | kuery = connection.descriptionOf(query: s)
53 | query = "SELECT \"t 2\".\"a\" FROM \"tableAlias\" AS \"t 2\""
54 | XCTAssertEqual(kuery, query, "\nError in query construction: \n\(kuery) \ninstead of \n\(query)")
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/docs/undocumented.json:
--------------------------------------------------------------------------------
1 | {
2 | "warnings": [
3 | {
4 | "file": "/Users/dannys/projects/kitura/Swift-Kuery/Sources/SwiftKuery/Connection.swift",
5 | "line": 162,
6 | "symbol": "Connection.execute(query:parameters:onCompletion:)",
7 | "symbol_kind": "source.lang.swift.decl.function.method.instance",
8 | "warning": "undocumented"
9 | },
10 | {
11 | "file": "/Users/dannys/projects/kitura/Swift-Kuery/Sources/SwiftKuery/Connection.swift",
12 | "line": 194,
13 | "symbol": "Connection.runCompletionHandler(_:onCompletion:)",
14 | "symbol_kind": "source.lang.swift.decl.function.method.instance",
15 | "warning": "undocumented"
16 | },
17 | {
18 | "file": "/Users/dannys/projects/kitura/Swift-Kuery/Sources/SwiftKuery/Connection.swift",
19 | "line": 200,
20 | "symbol": "Connection.runCompletionHandlerRetainingConnection(result:onCompletion:)",
21 | "symbol_kind": "source.lang.swift.decl.function.method.instance",
22 | "warning": "undocumented"
23 | },
24 | {
25 | "file": "/Users/dannys/projects/kitura/Swift-Kuery/Sources/SwiftKuery/ConnectionPool.swift",
26 | "line": 73,
27 | "symbol": "ConnectionPool.connectionPoolTask",
28 | "symbol_kind": "source.lang.swift.decl.typealias",
29 | "warning": "undocumented"
30 | },
31 | {
32 | "file": "/Users/dannys/projects/kitura/Swift-Kuery/Sources/SwiftKuery/ConnectionPoolConnection.swift",
33 | "line": 397,
34 | "symbol": "DummyColumBuilder",
35 | "symbol_kind": "source.lang.swift.decl.class",
36 | "warning": "undocumented"
37 | },
38 | {
39 | "file": "/Users/dannys/projects/kitura/Swift-Kuery/Sources/SwiftKuery/IndexColumn.swift",
40 | "line": 27,
41 | "symbol": "IndexColumn.table",
42 | "symbol_kind": "source.lang.swift.decl.var.instance",
43 | "warning": "undocumented"
44 | },
45 | {
46 | "file": "/Users/dannys/projects/kitura/Swift-Kuery/Sources/SwiftKuery/IndexColumnOrdered.swift",
47 | "line": 21,
48 | "symbol": "IndexColumnOrdered.table",
49 | "symbol_kind": "source.lang.swift.decl.var.instance",
50 | "warning": "undocumented"
51 | }
52 | ],
53 | "source_directory": "/Users/dannys/projects/kitura/Swift-Kuery"
54 | }
--------------------------------------------------------------------------------
/docs/js/jazzy.search.js:
--------------------------------------------------------------------------------
1 | $(function(){
2 | var $typeahead = $('[data-typeahead]');
3 | var $form = $typeahead.parents('form');
4 | var searchURL = $form.attr('action');
5 |
6 | function displayTemplate(result) {
7 | return result.name;
8 | }
9 |
10 | function suggestionTemplate(result) {
11 | var t = '
';
12 | t += '' + result.name + '';
13 | if (result.parent_name) {
14 | t += '' + result.parent_name + '';
15 | }
16 | t += '