Skip to content

Commit

Permalink
Now you just 'from sqlite_utils import Database'
Browse files Browse the repository at this point in the history
Plus fixed ad_id in the Russian ads example in the docs
  • Loading branch information
Simon Willison committed Jul 31, 2018
1 parent b69f8b6 commit 5deb65f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
11 changes: 6 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Contents

table

While the documentation is being constructed, enjoy an example instead:
While the full documentation is being constructed, enjoy an example:

.. code-block:: python
from sqlite_utils import db
from sqlite_utils import Database
import sqlite3
import requests
import hashlib
Expand Down Expand Up @@ -76,15 +76,16 @@ While the documentation is being constructed, enjoy an example instead:
def hash_id(s):
return hashlib.md5(s.encode("utf8")).hexdigest()[:5]
database = db.Database(sqlite3.connect("/tmp/ads3.db"))
database = Database(sqlite3.connect("/tmp/ads3.db"))
ads = database["ads"]
targets = database["targets"]
ad_targets = database["ad_targets"]
for ad in raw_ads:
ad_id = int(ad["file"].split(')')[-1].split(".")[0])
record = {
"id": ad["id"],
"id": ad_id,
"file": ad["file"],
"clicks": ad["clicks"],
"impressions": ad["impressions"],
Expand All @@ -107,7 +108,7 @@ While the documentation is being constructed, enjoy an example instead:
)
ad_targets.insert({
"target_id": target_id,
"ad_id": ad["id"],
"ad_id": ad_id,
}, foreign_keys=(
("ad_id", "INTEGER", "ads", "id"),
("target_id", "TEXT", "targets", "id"),
Expand Down
3 changes: 3 additions & 0 deletions sqlite_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .db import Database

__all__ = ["Database"]
4 changes: 2 additions & 2 deletions tests/test_create.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from sqlite_utils import db
from sqlite_utils import Database
import json
import sqlite3
import pytest


@pytest.fixture
def fresh_db():
return db.Database(sqlite3.connect(":memory:"))
return Database(sqlite3.connect(":memory:"))


def test_create_table(fresh_db):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_introspect.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from sqlite_utils import db
from sqlite_utils import Database
import sqlite3
import pytest


@pytest.fixture
def existing_db():
database = db.Database(sqlite3.connect(":memory:"))
database = Database(sqlite3.connect(":memory:"))
database.conn.executescript(
"""
CREATE TABLE foo (text TEXT);
Expand Down

0 comments on commit 5deb65f

Please sign in to comment.