mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 09:54:31 +02:00
Now you just 'from sqlite_utils import Database'
Plus fixed ad_id in the Russian ads example in the docs
This commit is contained in:
parent
b69f8b6c85
commit
5deb65f062
4 changed files with 13 additions and 9 deletions
|
|
@ -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
|
||||
|
|
@ -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"],
|
||||
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
from .db import Database
|
||||
|
||||
__all__ = ["Database"]
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from sqlite_utils import db
|
||||
from sqlite_utils import Database
|
||||
import json
|
||||
import sqlite3
|
||||
import pytest
|
||||
|
|
@ -6,7 +6,7 @@ import pytest
|
|||
|
||||
@pytest.fixture
|
||||
def fresh_db():
|
||||
return db.Database(sqlite3.connect(":memory:"))
|
||||
return Database(sqlite3.connect(":memory:"))
|
||||
|
||||
|
||||
def test_create_table(fresh_db):
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue