Skip to content

IBM-DTeam/swift-for-db2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swift-for-db2

Swift SDK for DB2

Build Status - Master Mac OS X Linux Apache 2

Summary

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.

Table of Contents

Features:

  • Connect asynchronously or synchronously to your database.
  • Disconnect asynchronously or synchronously to your database.
  • Query your database asynchronously or synchronously.

Swift Version

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.

Installation (OS X)

  1. Install Homebrew (if you don't already have it installed):

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. Install the necessary dependencies:

brew install wget unixodbc

  1. 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

  1. 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)

  1. Now you are ready to use the Swift SDK for DB2. See Using Swift SDK for DB2.

Installation (Linux)

  1. Get the newest versions of packages and their dependencies

sudo apt-get update

  1. Install the required dependencies

sudo apt-get install -y clang unixodbc-dev unzip wget tar

  1. 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

  1. 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.

  1. Now you are ready to use the Swift SDK for DB2. See Using Swift SDK for DB2.

Using Swift SDK for DB2

  1. 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

Examples

Visit the Wiki for examples on how to use the Swift SDK for DB2.

Contributing

  1. Clone this repository, git clone https://github.com/IBM-DTeam/swift-for-db2
  2. Build and run tests with swift test -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib

Notes

  • 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.

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.