docs
This commit is contained in:
parent
b5a759087a
commit
d240a45e77
@ -12,11 +12,11 @@ dataset: databases for lazy people
|
|||||||
|
|
||||||
Although managing data in relational database has plenty of benefits, we find them rarely being used in the typical day-to-day work with small to medium scale datasets. But why is that? Why do we see an awful lot of data stored in static files in CSV or JSON format?
|
Although managing data in relational database has plenty of benefits, we find them rarely being used in the typical day-to-day work with small to medium scale datasets. But why is that? Why do we see an awful lot of data stored in static files in CSV or JSON format?
|
||||||
|
|
||||||
Because **good programmers are lazy**, and thus they tend to prefer the easiest solution they find. And managing data in a databases simply wasn't the simplest solution to store a bunch of structured data. This is where ``dataset`` steps in!
|
Because **programmers are lazy**, and thus they tend to prefer the easiest solution they find. And managing data in a databases simply wasn't the simplest solution to store a bunch of structured data. This is where ``dataset`` steps in!
|
||||||
|
|
||||||
Dataset is here to **take the pain out of databases**. It makes reading and writing data in databases as simple as reading and writing JSON files.
|
Dataset is here to **take the pain out of databases**. It makes reading and writing data in databases as simple as reading and writing JSON files.
|
||||||
|
|
||||||
In short, ::
|
::
|
||||||
|
|
||||||
import dataset
|
import dataset
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ In short, ::
|
|||||||
db['sometable'].insert(dict(name='Jane Doe', age=34, gender='female'))
|
db['sometable'].insert(dict(name='Jane Doe', age=34, gender='female'))
|
||||||
|
|
||||||
|
|
||||||
Now look at `similar code, without dataset <https://gist.github.com/gka/5296492>`_.
|
Here is `similar code, without dataset <https://gist.github.com/gka/5296492>`_.
|
||||||
|
|
||||||
|
|
||||||
Features
|
Features
|
||||||
@ -33,10 +33,11 @@ Features
|
|||||||
|
|
||||||
* **Automatic schema**: If a table or column is written that does not
|
* **Automatic schema**: If a table or column is written that does not
|
||||||
exist in the database, it will be created automatically.
|
exist in the database, it will be created automatically.
|
||||||
* **Upserts**: Records are either created or updated, depdending on
|
* **Upserts**: Records are either created or updated, depending on
|
||||||
whether an existing version can be found.
|
whether an existing version can be found.
|
||||||
* **Query helpers** for simple queries such as all rows in a table or
|
* **Query helpers** for simple queries such as :py:meth:`all <dataset.Table.all>` rows in a table or
|
||||||
all distinct values across a set of columns.
|
all :py:meth:`distinct <dataset.Table.distinct>` values across a set of columns.
|
||||||
|
* **Compatibility**: Being built on top of `SQLAlchemy <http://www.sqlalchemy.org/>`_, ``dataset`` works with all major databases, such as SQLite, PostgreSQL and MySQL.
|
||||||
|
|
||||||
Contents
|
Contents
|
||||||
--------
|
--------
|
||||||
|
|||||||
@ -69,14 +69,14 @@ Searching for specific entries::
|
|||||||
# Returns all items
|
# Returns all items
|
||||||
table.find(country='China')
|
table.find(country='China')
|
||||||
|
|
||||||
Querying data
|
Running custom SQL queries
|
||||||
-------------
|
--------------------------
|
||||||
|
|
||||||
Querying data is easy. Dataset returns an iteratable result object::
|
Of course the main reason you're using a database is that you want to use the full power of SQL queries. Here's how you run them using dataset::
|
||||||
|
|
||||||
result = db.query('SELECT ...')
|
result = db.query('SELECT country, COUNT(*) cnt FROM population GROUP BY year')
|
||||||
for row in result:
|
for row in res:
|
||||||
print row
|
print row.country, row.cnt
|
||||||
|
|
||||||
Freezing your data
|
Freezing your data
|
||||||
------------------
|
------------------
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user