finagle-clojure.mysql.client

affected-rows

(affected-rows result)

Given a OK result, returns the number of rows affected (deleted, inserted, created) by that query.

Arguments:

Returns:

the number of rows affected by the query that generated the given Result

configured

(configured client stack-param)

Configure the given Mysql Client with an arbitrary Stack.Param.

Arguments:

  • client: a Mysql Client
  • charset: an arbitrary Stack.Param

Returns:

the given Mysql Client

error-code

(error-code result)

Given an Error result, returns the error code.

Arguments:

Returns:

the error code of the result

exec

(exec stmt & params)

Given a prepared statement and a set of parameters, executes the statement and returns the result as a future.

Arguments:

  • client: a rich MySQL Client
  • params: a variable number of args with which to parameterize the SQL statement

Returns:

a Future containing a com.twitter.finagle.mysql.Result

insert-id

(insert-id result)

Given an OK result from an insert operation, return the ID of the inserted row.

Arguments:

Returns:

the ID of the newly-inserted row

message

(message result)

Given a Result of subtype OK or Error, returns any message associated with that result.

Arguments:

Returns:

any message associated with the given result

mysql-client

(mysql-client)

Initialize a configurable MySQL stack client. The rich-client function must be called once configured in order to execute live queries against this, like so:

(-> (mysql-client)
    (with-database "somedb")
    (with-credentials "test" "test")
    (rich-client))

Arguments:

  • None.

Returns:

A new com.twitter.finagle.mysql.Client.

ok?

(ok? result)

Given a Result, returns true if that result was not an error.

Arguments:

Returns:

true if result is an instance of com.twitter.finagle.mysql.OK or com.twitter.finagle.mysql.ResultSet, false otherwise

ping

(ping client)

Given a rich client, pings it to verify connectivity.

Arguments:

  • client: a rich MySQL Client

Returns:

a Future containing a com.twitter.finagle.mysql.Result

prepare

(prepare client sql)

Given a rich client and a SQL string, returns a PreparedStatement ready to be parameterized and executed.

Arguments:

  • client: a rich MySQL Client
  • sql: a SQL string

Returns:

a com.twitter.finagle.mysql.PreparedStatement

query

(query client sql)

Given a rich client and a SQL string, executes the SQL and returns the result as a Future[Result].

Arguments:

  • client: a rich MySQL Client
  • sql: a SQL string

Returns:

a Future containing a com.twitter.finagle.mysql.Result

ResultSet->vec

(ResultSet->vec rs)

rich-client

(rich-client client dest)(rich-client client dest label)

Converts the given Mysql Client into a rich client, which is used for actually performing queries.

Arguments:

  • client: a Mysql Client
  • dest: a string or Name of the server location

Returns:

a new com.twitter.finagle.mysql.Client used for real queries

Row->map

(Row->map row)

Given a Finagle MySQL row structure, convert it to a Clojure map of field names to idiomatic Java data structures. Raises an exception when it can’t find an appropriate way to convert the boxed MySQL value.

Arguments:

Returns:

a Clojure map of field/value pairs

select-sql

(select-sql client sql)(select-sql client sql fn1)

Given a rich client, a SQL string, and a mapping function, executes the SQL and returns the result as a Future[Seq[T]], where T is the type yielded by the given mapping function. Arguments:

Returns:

a Future containing a Clojure vector whose contents are derived from fn1 (if given) or mapped to a Clojure hashmap of column/value pairs (if not)

select-stmt

(select-stmt stmt params)(select-stmt stmt params fn1)

Given a PreparedStatement, a vector of params, and a mapping function, executes the parameterized statement and returns the result as a Future[Seq[T]], where T is the type yielded by the given mapping function.

Arguments:

  • stmt: a PreparedStatement, generally derived from the prepare function
  • params: a Clojure vector of params
  • fn1 (optional): a Clojure or Scala Function1 that accepts a com.twitter.finagle.mysql.Row

Returns:

a Future containing a Clojure vector whose contents are derived from fn1 (if given) or mapped to a Clojure hashmap of column/value pairs (if not)

server-status

(server-status result)

Given an OK result, return the server status.

Arguments:

Returns:

the current server status, as an int

sql-state

(sql-state result)

Given an Error result, returns the SQL state.

Arguments:

Returns:

the SQL state of the result

ToParameter

protocol

members

->Parameter

(->Parameter v)

warning-count

(warning-count result)

Given an OK result, returns the count of warnings associated with the result.

Arguments:

Returns:

the warning count of the result

with-charset

(with-charset client charset)

Configure the given Mysql Client with a charset.

Arguments:

  • client: a Mysql Client
  • charset: a number representing the charset

Returns:

the given Mysql Client

with-credentials

(with-credentials client user pwd)

Configure the given Mysql Client with connection credentials.

Arguments:

  • client: a Mysql Client
  • user: a database username
  • pwd: a database password

Returns:

the given Mysql Client

with-database

(with-database client db)

Configure the given Mysql Client with a database.

Arguments:

  • client: a Mysql Client
  • db: the name of a database

Returns:

the given Mysql Client