Swift SDK for DB2
The Swift SDK for DB2 allows you to connect to your IBM DB2 database or products based off IBM DB2 and execute queries in Swift.
- Summary
- Features
- Swift Version
- Installation (OS X)
- Installation (Linux)
- Using Swift SDK for DB2
- Examples
- Contributing
- License
- Connect asynchronously or synchronously to your database.
- Disconnect asynchronously or synchronously to your database.
- Query your database asynchronously or synchronously.
The latest version of the Swift SDK for DB2 works with the swift-3.0-RELEASE version of the Swift binaries. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.
- Install Homebrew (if you don't already have it installed):
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Install the necessary dependencies:
brew install wget unixodbc
- Run the following to install the Swift SDK for DB2 CLI
wget https://github.com/IBM-DTeam/swift-for-db2-cli/archive/master.zip && unzip master.zip && cd swift-for-db2-cli-master && sudo ./cli.sh && . env.sh && cd .. && rm -f master.zip && rm -rf swift-for-db2-cli-master
- Download and install the supported Swift compiler.
During installation if you are using the package installer make sure to select "all users" for the installation path in order for the correct toolchain version to be available for use with the terminal.
After installation, make sure you update your PATH environment variable as described in the installation instructions (e.g. export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH)
- Now you are ready to use the Swift SDK for DB2. See Using Swift SDK for DB2.
- Get the newest versions of packages and their dependencies
sudo apt-get update
- Install the required dependencies
sudo apt-get install -y clang unixodbc-dev unzip wget tar
- Run the following to install the Swift SDK for DB2 CLI
wget https://github.com/IBM-DTeam/swift-for-db2-cli/archive/master.zip && unzip master.zip && cd swift-for-db2-cli-master && sudo ./cli.sh && . env.sh && cd .. && rm -f master.zip && rm -rf swift-for-db2-cli-master
- Install the supported Swift compiler for Linux.
Follow the instructions provided on that page. After installing it (i.e. uncompressing the tar file), make sure you update your PATH environment variable so that it includes the extracted tools: export PATH=/<path to uncompress tar contents>/usr/bin:$PATH
. To update the PATH env variable, you can update your .bashrc file.
- Now you are ready to use the Swift SDK for DB2. See Using Swift SDK for DB2.
- Create the
Package.swift
file in your project folder, and add the following code
import PackageDescription
let package = Package(
name: "your_project_name",
dependencies: [
.Package(url: "https://github.com/IBM-DTeam/swift-for-db2.git", majorVersion: 1)
]
)
If you already had the Package.swift
file, add the following line under dependencies
.Package(url: "https://github.com/IBM-DTeam/swift-for-db2.git", majorVersion: 1)
2.Then, run the following command in terminal (in your project folder)
swift build
3.Wait until the build finishes, then run the project
.build/debug/your_project_name
Visit the Wiki for examples on how to use the Swift SDK for DB2.
- Clone this repository,
git clone https://github.com/IBM-DTeam/swift-for-db2
- Build and run tests with
swift test -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib
- You are required to set the environment variable DB2_CONN_STRING to your database connection string.
You can find info on contributing to Swift SDK for DB2 in our contributing guidelines.
This library is licensed under Apache 2.0. Full license text is available in LICENSE.