81 lines
1.6 KiB
ReStructuredText
Raw Normal View History

2013-04-01 18:43:01 +02:00
.. dataset documentation master file, created by
sphinx-quickstart on Mon Apr 1 18:41:21 2013.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to dataset's documentation!
===================================
2013-04-01 22:40:28 +02:00
Contents:
.. toctree::
:maxdepth: 2
Quick-start
===========
At first you need to import the package :). To connect to a database you need to identify it using
what is called an engine url. Here are a few examples::
import dataset
# connecting to a SQLite database
db = dataset.connect('sqlite:///factbook.db')
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
# connecting to a MySQL database
db = dataset.connect('mysql:///')
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
Storing data
------------
Storing data in a table is as simple. **dataset** will automatically create the columns, if they don't exist yet::
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
table.insert(dict(country='China', year=2012, population=1354040000))
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
Reading data from tables
------------------------
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
Checking::
2013-04-01 21:33:12 +02:00
table = db['population']
2013-04-01 22:40:28 +02:00
# Let's grab a list of all items/rows/entries in the table:
table.all()
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
table.distinct()
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
Searching for specific entries::
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
# Returns the first item where the column country equals 'China'
table.find_one(country='China')
2013-04-01 21:33:12 +02:00
2013-04-01 22:40:28 +02:00
# Returns all items
table.find(country='China')
2013-04-01 21:33:12 +02:00
2013-04-01 18:43:01 +02:00
2013-04-01 22:40:28 +02:00
You can add additional columns at any time::
table.insert(dict(country='US', year=2013, population=315591999, source='http://www.census.gov'))
Updating existing entries::
table.update(dict(country='China', year=2012, population=1354040001), ['country', 'year'])
2013-04-01 18:43:01 +02:00
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`