Skip to content

Commit

Permalink
Merge pull request #47 from AnswerDotAI/apsw
Browse files Browse the repository at this point in the history
sqlite3 => apsw
  • Loading branch information
jph00 authored Dec 22, 2024
2 parents 57733fa + 14084d4 commit cb74b33
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 703 deletions.
4 changes: 2 additions & 2 deletions fastlite/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from fastcore.utils import *
from fastcore.xml import highlight
from fastcore.xtras import hl_md, dataclass_src
from sqlite_minutils.db import *
from sqlite_minutils.utils import rows_from_file,TypeTracker,Format
from apswutils.db import *
from apswutils.utils import rows_from_file,TypeTracker,Format
import types

try: from graphviz import Source
Expand Down
3 changes: 2 additions & 1 deletion fastlite/kw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from dataclasses import MISSING
from typing import Any,Union,Tuple,List,Iterable
from fastcore.utils import *
from sqlite_minutils.db import Database,Table,DEFAULT,ForeignKeysType,Default,Queryable,NotFoundError
from apswutils.db import Database,Table,DEFAULT,ForeignKeysType,Default,Queryable,NotFoundError
from apsw import SQLError
from enum import Enum

class MissingPrimaryKey(Exception): pass
Expand Down
487 changes: 266 additions & 221 deletions nbs/00_core.ipynb

Large diffs are not rendered by default.

452 changes: 47 additions & 405 deletions nbs/index.ipynb

Large diffs are not rendered by default.

86 changes: 37 additions & 49 deletions nbs/test_insert.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "ad470f25",
"metadata": {},
"outputs": [],
Expand All @@ -36,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "97dd1b48",
"metadata": {},
"outputs": [],
Expand All @@ -46,7 +46,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "5102a3ac",
"metadata": {},
"outputs": [],
Expand All @@ -56,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "9188c149",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -98,7 +98,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "fba0c4f7",
"metadata": {},
"outputs": [
Expand All @@ -108,7 +108,7 @@
"{}"
]
},
"execution_count": 5,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -127,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "ace59c88",
"metadata": {},
"outputs": [],
Expand All @@ -147,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "a93ec70a",
"metadata": {},
"outputs": [],
Expand All @@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "79cd5186",
"metadata": {},
"outputs": [],
Expand All @@ -173,7 +173,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"id": "aa988175",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -203,7 +203,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"id": "1fdd0aaf",
"metadata": {},
"outputs": [],
Expand All @@ -221,7 +221,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "c736aa0f",
"metadata": {},
"outputs": [],
Expand All @@ -239,7 +239,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"id": "cfd90ab0",
"metadata": {},
"outputs": [],
Expand All @@ -261,7 +261,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"id": "72a25f8d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -300,7 +300,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"id": "5a968d13",
"metadata": {},
"outputs": [],
Expand All @@ -319,7 +319,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"id": "92d53608",
"metadata": {},
"outputs": [],
Expand All @@ -330,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"id": "51cb29b1",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -368,7 +368,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"id": "972bab86",
"metadata": {},
"outputs": [],
Expand All @@ -387,7 +387,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"id": "55364dd6",
"metadata": {},
"outputs": [],
Expand All @@ -407,7 +407,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"id": "45a4c2aa",
"metadata": {},
"outputs": [],
Expand All @@ -420,12 +420,12 @@
"id": "f1209e4b",
"metadata": {},
"source": [
"Test that extra fields raise `sqlite3.OperationalError`"
"Test that extra fields raise `apsw.SqlError`"
]
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"id": "07c034e9",
"metadata": {},
"outputs": [],
Expand All @@ -435,14 +435,14 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"id": "963008b6",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" p = people.insert(name='Extra', age=25, title='Dr')\n",
"except OperationalError as e:\n",
"except SQLError as e:\n",
" assert e.args[0] == 'table people has no column named age'"
]
},
Expand Down Expand Up @@ -480,7 +480,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": null,
"id": "c8a95079",
"metadata": {},
"outputs": [],
Expand All @@ -500,7 +500,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"id": "cee37620",
"metadata": {},
"outputs": [],
Expand All @@ -522,7 +522,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"id": "98118662",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -551,7 +551,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"id": "96632dfb",
"metadata": {},
"outputs": [],
Expand All @@ -571,7 +571,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": null,
"id": "b110b0a7",
"metadata": {},
"outputs": [],
Expand All @@ -592,7 +592,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": null,
"id": "803e6bc9",
"metadata": {},
"outputs": [],
Expand All @@ -614,7 +614,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": null,
"id": "570d5dce",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -645,7 +645,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"id": "ca76eb12",
"metadata": {},
"outputs": [],
Expand All @@ -671,7 +671,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": null,
"id": "5a37e482",
"metadata": {},
"outputs": [],
Expand All @@ -696,7 +696,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"id": "da81a215",
"metadata": {},
"outputs": [],
Expand All @@ -721,35 +721,23 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"id": "9d7d7991",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" people.insert_all([{'name': 'Valid'}, {'invalid_col': 'Bad'}])\n",
"except OperationalError as e:\n",
"except SQLError as e:\n",
" assert 'no column named invalid_col' in str(e)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
14 changes: 2 additions & 12 deletions nbs/test_update.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,7 @@
"id": "f1209e4b",
"metadata": {},
"source": [
"Test that extra fields raise `sqlite3.OperationalError`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "07c034e9",
"metadata": {},
"outputs": [],
"source": [
"from sqlite3 import OperationalError"
"Test that extra fields raise `fastlite.SqlError`, which is a shim for `apsw.SqlError`:"
]
},
{
Expand All @@ -395,7 +385,7 @@
"source": [
"try:\n",
" p = people.update(dict(id=person.id, name='Extra', age=25, title='Dr'))\n",
"except OperationalError as e:\n",
"except SQLError as e:\n",
" assert e.args[0] == 'no such column: age'"
]
}
Expand Down
Loading

0 comments on commit cb74b33

Please sign in to comment.