Skip to content

Commit

Permalink
Import sqlite-minutils
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Dec 5, 2024
1 parent c4a88fe commit 4f4d84c
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 64 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release notes

## 5???

### Breaking changes

- Migrate from sqlite-minutils
- Change import path
- Use X instead of OperationalError


## 4.0.3

Expand Down
71 changes: 63 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sqlite-minutils
# apswutils


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
Expand All @@ -18,17 +18,17 @@
## Install

pip install sqlite-minutils
pip install apswutils

## Use

First, import the sqlite-miniutils library. Through the use of the
**all** attribute in our Python modules by using `import *` we only
bring in the `Database`, `Queryable`, `Table`, `View` classes. There’s
no risk of namespace pollution.
First, import the apswutils library. Through the use of the **all**
attribute in our Python modules by using `import *` we only bring in the
`Database`, `Queryable`, `Table`, `View` classes. There’s no risk of
namespace pollution.

``` python
from sqlite_minutils.db import *
from apswutils.db import *
```

Then we create a SQLite database. For the sake of convienance we’re
Expand Down Expand Up @@ -116,7 +116,7 @@ table object.
users.rows
```

<generator object Queryable.rows_where at 0x10849f6f0>
<generator object Queryable.rows_where>

Let’s iterate over that generator to see the results:

Expand Down Expand Up @@ -169,3 +169,58 @@ except ValueError as e:
```

Cannot use offset without limit

## Transactions

If you have any SQL calls outside an explicit transaction, they are
committed instantly.

To group 2 or more queries together into 1 transaction, wrap them in a
BEGIN and COMMIT, executing ROLLBACK if an exception is caught:

``` python
users.get(1)
```

{'id': 1, 'name': 'Raven', 'age': 8, 'pwd': 's3cret'}

``` python
db.begin()
try:
users.delete([1])
db.execute('FNOOORD')
db.commit()
except Exception as e:
print(e)
db.rollback()
```

near "FNOOORD": syntax error

Because the transaction was rolled back, the user was not deleted:

``` python
users.get(1)
```

{'id': 1, 'name': 'Raven', 'age': 8, 'pwd': 's3cret'}

Let’s do it again, but without the DB error, to check the transaction is
successful:

``` python
db.begin()
try:
users.delete([1])
db.commit()
except Exception as e: db.rollback()
```

``` python
try:
users.get(1)
print("Delete failed!")
except: print("Delete succeeded!")
```

Delete succeeded!
File renamed without changes.
8 changes: 8 additions & 0 deletions apswutils/_modidx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Autogenerated by nbdev

d = { 'settings': { 'branch': 'main',
'doc_baseurl': '/apswutils',
'doc_host': 'https://AnswerDotAI.github.io',
'git_url': 'https://github.com/AnswerDotAI/apswutils',
'lib_path': 'apswutils'},
'syms': {'apswutils.db': {}, 'apswutils.utils': {}}}
2 changes: 1 addition & 1 deletion sqlite_minutils/db.py → apswutils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ class Table(Queryable):
#: The primary key of the last inserted, updated or selected row.
last_pk: Optional[Any] = None
# This allows us to preserve the historical design of the Table class
# in sqlite-minutils while also introducting use of RETURNING *.
# in apswutils while also introducting use of RETURNING *.
result: List[Dict] = []

def __init__(
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions nbs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# sqlite-minutils\n",
"# apswutils\n",
"\n",
"> A fork of the sqlite-utils package with the CLI removed."
"> A fork of the sqlite-utils package with the CLI removed and using apsw as the sqlite interface."
]
},
{
Expand All @@ -33,7 +33,7 @@
"metadata": {},
"source": [
"```\n",
"pip install sqlite-minutils\n",
"pip install apswutils\n",
"```"
]
},
Expand All @@ -59,7 +59,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First, import the sqlite-miniutils library. Through the use of the __all__ attribute in our Python modules by using `import *` we only bring in the `Database`, `Queryable`, `Table`, `View` classes. There’s no risk of namespace pollution."
"First, import the apswutils library. Through the use of the __all__ attribute in our Python modules by using `import *` we only bring in the `Database`, `Queryable`, `Table`, `View` classes. There’s no risk of namespace pollution."
]
},
{
Expand All @@ -68,7 +68,7 @@
"metadata": {},
"outputs": [],
"source": [
"from sqlite_minutils.db import *"
"from apswutils.db import *"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions nbs/nbdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ project:
output-dir: _docs

website:
title: "sqlite-minutils"
site-url: "https://AnswerDotAI.github.io/sqlite-minutils"
description: "A fork of sqlite-utils with CLI etc removed"
title: "apswutils"
site-url: "https://AnswerDotAI.github.io/apswutils"
description: "A fork of sqlite-utils with CLI etc removed and and using apsw as the sqlite interface"
repo-branch: main
repo-url: "https://github.com/AnswerDotAI/sqlite-minutils"
repo-url: "https://github.com/AnswerDotAI/apswutils"
16 changes: 8 additions & 8 deletions settings.ini
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
[DEFAULT]
repo = sqlite-minutils
lib_name = sqlite-minutils
repo = apswutils
lib_name = apswutils
version = 4.0.4
min_python = 3.9
license = apache2
black_formatting = False
doc_path = _docs
lib_path = sqlite_minutils
lib_path = apswutils
nbs_path = nbs
recursive = True
tst_flags = notest
put_version_in_init = True
branch = main
custom_sidebar = False
doc_host = https://AnswerDotAI.github.io
doc_baseurl = /sqlite-minutils
git_url = https://github.com/AnswerDotAI/sqlite-minutils
title = sqlite-minutils
doc_baseurl = /apswutils
git_url = https://github.com/AnswerDotAI/apswutils
title = apswutils
audience = Developers
author = Jeremy Howard
author_email = [email protected]
copyright = 2024 onwards, Jeremy Howard
description = A fork of sqlite-utils with CLI etc removed
description = A fork of sqlite-utils with CLI etc removed and using apsw as the sqlite interface
keywords = nbdev jupyter notebook python
language = English
status = 3
user = AnswerDotAI
requirements = fastcore
requirements = fastcore apsw
conda_user = fastai
readme_nb = index.ipynb
allowed_metadata_keys =
Expand Down
8 changes: 0 additions & 8 deletions sqlite_minutils/_modidx.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlite_minutils import Database
from sqlite_minutils.utils import sqlite3
from apswutils import Database
from apswutils.utils import sqlite3
import pytest

CREATE_TABLES = """
Expand Down
2 changes: 1 addition & 1 deletion tests/test_attach.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils import Database
from apswutils import Database


def test_attach(tmpdir):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_column_affinity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from sqlite_minutils.utils import column_affinity
from apswutils.utils import column_affinity

EXAMPLES = [
# Examples from https://www.sqlite.org/datatype3.html#affinity_name_examples
Expand Down
4 changes: 2 additions & 2 deletions tests/test_constructor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlite_minutils import Database
from sqlite_minutils.utils import sqlite3
from apswutils import Database
from apswutils.utils import sqlite3
import pytest


Expand Down
4 changes: 2 additions & 2 deletions tests/test_create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils.db import (
from apswutils.db import (
Index,
Database,
DescIndex,
Expand All @@ -9,7 +9,7 @@
Table,
View,
)
from sqlite_minutils.utils import hash_record, sqlite3
from apswutils.utils import hash_record, sqlite3
import collections
import datetime
import decimal
Expand Down
2 changes: 1 addition & 1 deletion tests/test_create_view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from sqlite_minutils.utils import OperationalError
from apswutils.utils import OperationalError


def test_create_view(fresh_db):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_duplicate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils.db import NoTable
from apswutils.db import NoTable
import datetime
import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/test_extract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils.db import InvalidColumns
from apswutils.db import InvalidColumns
import itertools
import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/test_extracts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils.db import Index
from apswutils.db import Index
import pytest


Expand Down
2 changes: 1 addition & 1 deletion tests/test_get.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from sqlite_minutils.db import NotFoundError
from apswutils.db import NotFoundError


def test_get_rowid(fresh_db):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_hypothesis.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from hypothesis import given
import hypothesis.strategies as st
import sqlite_minutils
import apswutils


# SQLite integers are -(2^63) to 2^63 - 1
@given(st.integers(-9223372036854775808, 9223372036854775807))
def test_roundtrip_integers(integer):
db = sqlite_minutils.Database(memory=True)
db = apswutils.Database(memory=True)
row = {
"integer": integer,
}
Expand All @@ -16,7 +16,7 @@ def test_roundtrip_integers(integer):

@given(st.text())
def test_roundtrip_text(text):
db = sqlite_minutils.Database(memory=True)
db = apswutils.Database(memory=True)
row = {
"text": text,
}
Expand All @@ -26,7 +26,7 @@ def test_roundtrip_text(text):

@given(st.binary(max_size=1024 * 1024))
def test_roundtrip_binary(binary):
db = sqlite_minutils.Database(memory=True)
db = apswutils.Database(memory=True)
row = {
"binary": binary,
}
Expand All @@ -36,7 +36,7 @@ def test_roundtrip_binary(binary):

@given(st.floats(allow_nan=False))
def test_roundtrip_floats(floats):
db = sqlite_minutils.Database(memory=True)
db = apswutils.Database(memory=True)
row = {
"floats": floats,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lookup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils.db import Index
from apswutils.db import Index
import pytest


Expand Down
2 changes: 1 addition & 1 deletion tests/test_m2m.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils.db import ForeignKey, NoObviousTable
from apswutils.db import ForeignKey, NoObviousTable
import pytest


Expand Down
2 changes: 1 addition & 1 deletion tests/test_recreate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils import Database
from apswutils import Database
import sqlite3
import pathlib
import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/test_register_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
import sys
from unittest.mock import MagicMock, call
from sqlite_minutils.utils import sqlite3
from apswutils.utils import sqlite3


def test_register_function(fresh_db):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rows_from_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlite_minutils.utils import rows_from_file, Format, RowError
from apswutils.utils import rows_from_file, Format, RowError
from io import BytesIO, StringIO
import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/test_suggest_column_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from collections import OrderedDict
from sqlite_minutils.utils import suggest_column_types
from apswutils.utils import suggest_column_types


@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlite_minutils.db import ForeignKey
from sqlite_minutils.utils import OperationalError
from apswutils.db import ForeignKey
from apswutils.utils import OperationalError
from sqlite3 import IntegrityError
import pytest

Expand Down
Loading

0 comments on commit 4f4d84c

Please sign in to comment.