Packages
mysql_client
1.2.8
MySQL native client is written in Erlang and provides API that is very close to Connector/C library.
Current section
Files
Jump to
Current section
Files
doc/example.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Module example</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
</head>
<body bgcolor="white">
<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<hr>
<h1>Module example</h1>
<ul class="index"><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>The module represents an example of using of erlang client.
<p>Copyright © 2010-2014 Alexei Krasnopolski</p>
<p><b>Version:</b> 1.2.8</p>
<p><b>Introduced in:</b> 2011-03-31</p>
<p><b>Authors:</b> Alexei Krasnopolski (<a href="mailto:krasnop@bellsouth.net"><tt>krasnop@bellsouth.net</tt></a>) [<em>web site:</em> <tt><a href="http://krasnopolski.org/" target="_top">http://krasnopolski.org/</a></tt>].</p>
<h2><a name="description">Description</a></h2><p>The module represents an example of using of erlang client. Function run/0
initiates an execution of 3 processes named 'producer', 'consumer' and 'cleaner'. First process
generates and inserts to database a messages, second one retrives and processes the messages and
third process deletes processed messages from database. The processes are running concurrently
and are using separate connection to database. Fourth process is watcher that is periodicaly asking
database for count of processed messages. If database is empty the task is completed.</p>
<h2><a name="index">Function Index</a></h2>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#run-0">run/0</a></td><td>Starting point for example application.</td></tr>
<tr><td valign="top"><a href="#run_producer-1">run_producer/1</a></td><td>The function inserts some amount of messages to database.</td></tr>
<tr><td valign="top"><a href="#run_consumer-0">run_consumer/0</a></td><td>The function starts concurrent_runner for process entry operations and
waiting for stop message.</td></tr>
<tr><td valign="top"><a href="#run_cleaner-0">run_cleaner/0</a></td><td>The function starts concurrent_runner for delete entry operations and
waiting for stop message.</td></tr>
<tr><td valign="top"><a href="#run_watcher-1">run_watcher/1</a></td><td>The function establishes connection to database and recursively retreives
count of messages in the database.</td></tr>
<tr><td valign="top"><a href="#create_schema-0">create_schema/0</a></td><td>Create two tables: 'message' and 'property'.</td></tr>
<tr><td valign="top"><a href="#insert_message-4">insert_message/4</a></td><td>The function inserts to database one message entity and three property entities these belong to the message.</td></tr>
<tr><td valign="top"><a href="#get_messages_list-1">get_messages_list/1</a></td><td>Retrieves a list of ids of messages marked processed or unprocessed.</td></tr>
<tr><td valign="top"><a href="#process_entry-1">process_entry/1</a></td><td>Marks message with Id as processed.</td></tr>
<tr><td valign="top"><a href="#delete_message-1">delete_message/1</a></td><td>Deletes message with Id and correspondend property rows.</td></tr>
<tr><td valign="top"><a href="#watcher-3">watcher/3</a></td><td>Recursively queries message table for count of rows.</td></tr>
<tr><td valign="top"><a href="#get_count_messages-1">get_count_messages/1</a></td><td>Gets count of rows in message table.</td></tr>
</table>
<h2><a name="functions">Function Details</a></h2>
<h3 class="function"><a name="run-0">run/0</a></h3>
<div class="spec">
<p><tt>run() -> any()</tt><br></p>
<p> </p>
</div><p>Starting point for example application. The function creates 2 tables in database and spawns 3 processes: producer, consumer and
cleaner. Then it begins to wait for 'start_watch' message. After the message is received
watcher process is started and main process goes to wait for 'stop' message.
'start_watch' message is generated by producer after last message has inserted to database.
'stop' message is generated by watcher after database returns to empty state.
</p>
<h3 class="function"><a name="run_producer-1">run_producer/1</a></h3>
<div class="spec">
<p><tt>run_producer(P_pid::pid()) -> any()</tt><br></p>
<p> </p>
</div><p>The function inserts some amount of messages to database. And then it sends a message
'start_watch' to parent (main) process.
</p>
<h3 class="function"><a name="run_consumer-0">run_consumer/0</a></h3>
<div class="spec">
<p><tt>run_consumer() -> any()</tt><br></p>
<p> </p>
</div><p>The function starts concurrent_runner for process entry operations and
waiting for stop message. Each 100 milisecond concurrent_runner is restarted.
</p>
<h3 class="function"><a name="run_cleaner-0">run_cleaner/0</a></h3>
<div class="spec">
<p><tt>run_cleaner() -> any()</tt><br></p>
<p> </p>
</div><p>The function starts concurrent_runner for delete entry operations and
waiting for stop message. Each 100 milisecond concurrent_runner is restarted.
</p>
<h3 class="function"><a name="run_watcher-1">run_watcher/1</a></h3>
<div class="spec">
<p><tt>run_watcher(P_pid::pid()) -> any()</tt><br></p>
<p> </p>
</div><p>The function establishes connection to database and recursively retreives
count of messages in the database. If database is empty then completes execution.
</p>
<h3 class="function"><a name="create_schema-0">create_schema/0</a></h3>
<div class="spec">
<p><tt>create_schema() -> any()</tt><br></p>
<p> </p>
</div><p><p>Create two tables: 'message' and 'property'. 'Message' has one-to-many relationship to
'property' table.</p>
<p><img src="example-erlMySQL.png"></p>
</p>
<h3 class="function"><a name="insert_message-4">insert_message/4</a></h3>
<div class="spec">
<p><tt>insert_message(Connection::#connection{}, N::integer(), M::integer(), SleepTime::integer()) -> any()</tt><br></p>
<p> </p>
</div><p>The function inserts to database one message entity and three property entities these belong to the message.
N - number of message, M - amount of message to insert, SleepTime - delay between insert operations.
</p>
<h3 class="function"><a name="get_messages_list-1">get_messages_list/1</a></h3>
<div class="spec">
<p><tt>get_messages_list(Processed::integer()) -> any()</tt><br></p>
<p> </p>
</div><p>Retrieves a list of ids of messages marked processed or unprocessed.
The list size is limited to 10.
</p>
<h3 class="function"><a name="process_entry-1">process_entry/1</a></h3>
<div class="spec">
<p><tt>process_entry(Id::integer()) -> any()</tt><br></p>
<p> </p>
</div><p>Marks message with Id as processed.
</p>
<h3 class="function"><a name="delete_message-1">delete_message/1</a></h3>
<div class="spec">
<p><tt>delete_message(Id::integer()) -> any()</tt><br></p>
<p> </p>
</div><p>Deletes message with Id and correspondend property rows.
</p>
<h3 class="function"><a name="watcher-3">watcher/3</a></h3>
<div class="spec">
<p><tt>watcher(Connection::pid(), P_pid::pid(), N::integer()) -> any()</tt><br></p>
<p> </p>
</div><p>Recursively queries message table for count of rows. If the table becomes empty
the function sends 'stop' to parent process.
</p>
<h3 class="function"><a name="get_count_messages-1">get_count_messages/1</a></h3>
<div class="spec">
<p><tt>get_count_messages(Connection::pid()) -> any()</tt><br></p>
<p> </p>
</div><p>Gets count of rows in message table.
</p>
<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<p><i>Generated by EDoc</i></p>
</body>
</html>