Commit Graph
3 Commits
Author SHA1 Message Date
Paul M Furley c414f85df9 find(): if table doesn't exist, return an iterator
... rather than []

If a table exists, you can treat the output of `find` as an iterator,
specifically you can call `next(find(...))`:

```
>>> db = dataset.connect('sqlite:///:memory1:')
>>> table = db['table_which_exists']
>>> table.insert({'foo': 'x'})
>>> next(table.find(foo='x'))  # no problem
```

But if the table hasn't been created yet, `find(...)` returns an empty list,
which you can't call `next()` on:

```
>>> db = dataset.connect('sqlite:///:memory2:')
>>> table = db_no_table['table_which_doesnt_exis']
>>> next(table.find(foo='x'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object is not an iterator
```

^^^ rather than a `TypeError`, I'd expect to get a `StopIteration`
exception.
2018-05-29 18:07:32 +01:00
Paul M Furley 866713f110 Order JSON freeze fields deterministically
To avoid commits like [this
one](https://github.com/paulfurley/experimental-liverpool-planning-data/commit/f0599f87bcd0211b2cff977d008119b6aa267bea)
on Python 3
2016-11-21 07:30:43 +00:00
Paul Furley 69815e65fc Moved logging.basicConfig() so using dataset as a library doesn't interfere with the global logger 2013-08-06 13:48:55 +01:00