MariaDB

3.0.2

A stand-alone Swift wrapper around the MariaDB client library, enabling access to MariaDB servers. http://www.perfect.org
PerfectlySoft/Perfect-MariaDB

What's New

Adding ping()

2018-01-24T15:39:31Z

MySQL connection will go away when idle timeout. The ping() function
can confirm the connectivity and also reconnect if need.
https://dev.mysql.com/doc/refman/5.7/en/mysql-ping.html
Thanks @joecharlier.

Perfect - MariaDB Connector 简体中文

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 4.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

This project provides a Swift wrapper around the MariaDB client library, enabling access to MariaDB database servers.

This package builds with Swift Package Manager and is part of the Perfect project. It was written to be stand-alone and so does not require PerfectLib or any other components.

Ensure you have installed and activated the latest Swift 4.0 tool chain.

OS X Build Notes

To install MariaDB connector:

 brew install mariadb-connector-c

You will have to deal with pkg-config file, such as: /usr/local/lib/pkgconfig/mariadb.pc, similar with below:

libdir=/usr/local/lib/mariadb
includedir=/usr/local/include/mariadb

Name: mariadb
Description: MariaDB Connector/C
Version: 5.5.1
Requires:
Libs: -L${libdir} -lmariadb  -ldl -lm -lpthread
Cflags: -I${includedir}
Libs_r: -L${libdir} -lmariadb -ldl -lm -lpthread

Then please also edit your ~/.bash_profile with the following line:

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig"

once done, reload this profile as

source ~/.bash_profile

To test if pkg-config is working, try command:

$ pkg-config mariadb --cflags --libs

Linux Build Notes

Tests performed on Ubuntu 16.04. Prior to build this library, please ensure:

sudo apt-get install pkg-config libmariadb2 libmariadb-client-lgpl-dev  

Please also make sure the pkg-config file /usr/lib/pkgconfig/mariadb.pc specified for MariaDB should be MANUALLY added and corrected before building, possibly looks like this:

libdir=/usr/lib/x86_64-linux-gnu
includedir=/usr/include/mariadb

Name: mariadb
Description: MariaDB Connector/C
Version: 5.5.0
Requires:
Libs: -L${libdir} -lmariadb  -ldl -lm -lpthread
Cflags: -I${includedir}
Libs_r: -L${libdir} -lmariadb -ldl -lm -lpthread

To test if pkg-config is working, try command:

$ pkg-config mariadb --cflags --libs

Building

Add this project as a dependency in your Package.swift file.

.Package(url:"https://github.com/PerfectlySoft/Perfect-MariaDB.git", 
majorVersion: 3)

Import required libraries:

import MariaDB

Setup the credentials for your connection:

let testHost = "127.0.0.1"
let testUser = "test"

// PLEASE change to whatever your actual password is before running these tests
let testPassword = "password"
let testSchema = "schema"

Create an instance of the MySQL class

	let dataMysql = MySQL()

    // need to make sure something is available.
    guard dataMysql.connect(host: testHost, user: testUser, password: testPassword ) else {
    // something wrong here
        return
    }

    defer {
        dataMysql.close()  // defer ensures we close our db connection at the end of this request
    }

    //set database to be used, this example assumes presence of a users table and run a raw query, return failure message on a error
    guard dataMysql.selectDatabase(named: testSchema) && dataMysql.query(statement: "select * from users limit 1") else {
    // something wrong here
        return
    }

    //store complete result set
    let results = dataMysql.storeResults()

    //setup an array to store results
    var resultArray = [[String?]]()

    while let row = results?.next() {
        resultArray.append(row)

    }

	print(resultArray)

Additionally, there are more complex Statement constructors, and potential object designs which can further abstract the process of interacting with your data.

Issues

We are transitioning to using JIRA for all bugs and support related issues, therefore the GitHub issues has been disabled.

If you find a mistake, bug, or any other helpful suggestion you'd like to make on the docs please head over to http://jira.perfect.org:8080/servicedesk/customer/portal/1 and raise it.

A comprehensive list of open issues can be found at http://jira.perfect.org:8080/projects/ISS/issues

Further Information

For more information on the Perfect project, please visit perfect.org.

Description

  • Swift Tools 3.1.0
View More Packages from this Author

Dependencies

Last updated: Wed Dec 11 2024 06:28:09 GMT-1000 (Hawaii-Aleutian Standard Time)