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:
result: a com.twitter.finagle.mysql.OK
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 MysqlClientcharset: an arbitraryStack.Param
Returns:
the given Mysql Client
error-code
(error-code result)Given an Error result, returns the error code.
Arguments:
result: a com.twitter.finagle.mysql.Error
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 MySQLClientparams: 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:
result: a com.twitter.finagle.mysql.OK
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:
ok?
(ok? result)Given a Result, returns true if that result was not an error.
Arguments:
result: a com.twitter.finagle.mysql.Result
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 MySQLClient
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 MySQLClientsql: a SQL string
Returns:
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 MySQLClientsql: a SQL string
Returns:
a Future containing a com.twitter.finagle.mysql.Result
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 MysqlClientdest: a string orNameof 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:
client: a rich MySQLClientsql: a SQL stringfn1(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)
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: aPreparedStatement, generally derived from thepreparefunctionparams: a Clojure vector of paramsfn1(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:
result: a com.twitter.finagle.mysql.OK
Returns:
the current server status, as an int
sql-state
(sql-state result)Given an Error result, returns the SQL state.
Arguments:
result: a com.twitter.finagle.mysql.Error
Returns:
the SQL state of the result
warning-count
(warning-count result)Given an OK result, returns the count of warnings associated with the result.
Arguments:
result: a com.twitter.finagle.mysql.OK
Returns:
the warning count of the result
with-charset
(with-charset client charset)Configure the given Mysql Client with a charset.
Arguments:
client: a MysqlClientcharset: 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 MysqlClientuser: a database usernamepwd: 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 MysqlClientdb: the name of a database
Returns:
the given Mysql Client