<h2>Sequel: The Database Toolkit for Ruby (v<%= Sequel::VERSION %>)</h2>

<h3 id='features'>Features:</h3>

<ul>
<li>Sequel provides thread safety, connection pooling and a concise DSL for constructing SQL queries and table schemas.</li>
<li>Sequel includes a comprehensive ORM layer for mapping records to Ruby objects and handling associated records.</li>
<li>Sequel supports advanced database features such as prepared statements, bound variables, stored procedures, savepoints, two-phase commit, transaction isolation, primary/replica configurations, and database sharding.</li>
<li>Sequel currently has adapters for ADO, Amalgalite, IBM_DB, JDBC, MySQL, Mysql2, ODBC, Oracle, PostgreSQL, SQLAnywhere, SQLite3, and TinyTDS.</li>
</ul>

<h3 id='a_short_example'>A short example:</h3>

<pre><code class='ruby' lang='ruby'><span class='ident'>require</span> <span class='punct'>&quot;</span><span class='string'>sequel</span><span class='punct'>&quot;</span>

<span class='comment'># connect to an in-memory database</span>
<span class='constant'>DB</span> <span class='punct'>=</span> <span class='constant'>Sequel</span><span class='punct'>.</span><span class='ident'>sqlite</span>

<span class='comment'># create an items table</span>
<span class='constant'>DB</span><span class='punct'>.</span><span class='ident'>create_table</span> <span class='symbol'>:items</span> <span class='keyword'>do</span>
  <span class='ident'>primary_key</span> <span class='symbol'>:id</span>
  <span class='ident'>String</span> <span class='symbol'>:name</span><span class='punct'>,</span> <span class='symbol'>unique:</span> <span class='keyword'>true</span><span class='punct'>,</span> <span class='symbol'>null:</span> <span class='keyword'>false</span>
  <span class='ident'>Float</span> <span class='symbol'>:price</span><span class='punct'>,</span> <span class='symbol'>null:</span> <span class='keyword'>false</span>
<span class='keyword'>end</span>

<span class='comment'># create a dataset from the items table</span>
<span class='ident'>items</span> <span class='punct'>=</span> <span class='constant'>DB</span><span class='punct'>[</span><span class='symbol'>:items</span><span class='punct'>]</span>

<span class='comment'># populate the table</span>
<span class='ident'>items</span><span class='punct'>.</span><span class='ident'>insert</span><span class='punct'>(</span><span class='symbol'>name:</span> <span class='punct'>&#39;</span><span class='string'>abc</span><span class='punct'>&#39;,</span> <span class='symbol'>price:</span> <span class='ident'>rand</span> <span class='punct'>*</span> <span class='number'>100</span><span class='punct'>)</span>
<span class='ident'>items</span><span class='punct'>.</span><span class='ident'>insert</span><span class='punct'>(</span><span class='symbol'>name:</span> <span class='punct'>&#39;</span><span class='string'>def</span><span class='punct'>&#39;,</span> <span class='symbol'>price:</span> <span class='ident'>rand</span> <span class='punct'>*</span> <span class='number'>100</span><span class='punct'>)</span>
<span class='ident'>items</span><span class='punct'>.</span><span class='ident'>insert</span><span class='punct'>(</span><span class='symbol'>name:</span> <span class='punct'>&#39;</span><span class='string'>ghi</span><span class='punct'>&#39;,</span> <span class='symbol'>price:</span> <span class='ident'>rand</span> <span class='punct'>*</span> <span class='number'>100</span><span class='punct'>)</span>

<span class='comment'># print out the number of records</span>
<span class='ident'>puts</span> <span class='punct'>&quot;</span><span class='string'>Item count: <span class='expr'>#{items.count}</span></span><span class='punct'>&quot;</span>

<span class='comment'># print out the average price</span>
<span class='ident'>puts</span> <span class='punct'>&quot;</span><span class='string'>The average price is: <span class='expr'>#{items.avg(:price)}</span></span><span class='punct'>&quot;</span></code></pre>

<h2><a href='documentation.html'>Learn more about Sequel&#8230;</a></h2>
