nyansqlite 1.0.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Disnana
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,378 @@
1
+ Metadata-Version: 2.4
2
+ Name: nyansqlite
3
+ Version: 1.0.0.dev1
4
+ Summary: A dict-like SQLite wrapper with APSW for instant persistence and memory caching
5
+ Author-email: Disnana <support@disnana.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/disnana/nyansqlite
8
+ Project-URL: Documentation, https://nyansqlite.disnana.com/
9
+ Project-URL: Repository, https://github.com/disnana/nyansqlite
10
+ Project-URL: Issues, https://github.com/disnana/nyansqlite/issues
11
+ Keywords: sqlite,apsw,dict,database,persistence,cache,key-value,nosql
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Database
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: apsw>=3.40.0.0
29
+ Requires-Dist: pydantic>2.0.0
30
+ Provides-Extra: speed
31
+ Requires-Dist: lru-dict>=1.3.0; extra == "speed"
32
+ Requires-Dist: orjson>=3.9.10; extra == "speed"
33
+ Requires-Dist: nanalib>=0.1.0; extra == "speed"
34
+ Provides-Extra: encryption
35
+ Requires-Dist: cryptography>=42.0.0; extra == "encryption"
36
+ Provides-Extra: validation
37
+ Requires-Dist: validkit-py>=1.0.0; extra == "validation"
38
+ Provides-Extra: re2
39
+ Requires-Dist: google-re2>=1.1; extra == "re2"
40
+ Provides-Extra: dev
41
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
42
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
43
+ Requires-Dist: pytest-asyncio<2.0.0,>=0.21.0; extra == "dev"
44
+ Requires-Dist: pydantic>=2.0.0; extra == "dev"
45
+ Requires-Dist: tox>=4.0.0; extra == "dev"
46
+ Requires-Dist: ruff>=0.8.0; extra == "dev"
47
+ Requires-Dist: mypy>=1.13.0; extra == "dev"
48
+ Requires-Dist: pytest-xdist>=3.0.0; extra == "dev"
49
+ Requires-Dist: pytest-benchmark>=4.0.0; extra == "dev"
50
+ Requires-Dist: cryptography>=42.0.0; extra == "dev"
51
+ Requires-Dist: validkit-py>=1.0.0; extra == "dev"
52
+ Requires-Dist: lru-dict>=1.3.0; extra == "dev"
53
+ Requires-Dist: orjson>=3.9.10; extra == "dev"
54
+ Requires-Dist: nanalib>=0.1.0; extra == "dev"
55
+ Requires-Dist: google-re2>=1.1; extra == "dev"
56
+ Requires-Dist: google-re2==1.1.20240702; python_version <= "3.9" and extra == "dev"
57
+ Provides-Extra: all
58
+ Requires-Dist: lru-dict>=1.3.0; extra == "all"
59
+ Requires-Dist: orjson>=3.9.10; extra == "all"
60
+ Requires-Dist: cryptography>=42.0.0; extra == "all"
61
+ Requires-Dist: validkit-py>=1.0.0; extra == "all"
62
+ Requires-Dist: pydantic>=2.0.0; extra == "all"
63
+ Requires-Dist: google-re2>=1.1; extra == "all"
64
+ Dynamic: license-file
65
+
66
+ # NyanSQLite
67
+
68
+ [![PyPI version](https://img.shields.io/pypi/v/nyansqlite.svg)](https://pypi.org/project/nyansqlite/)
69
+ [![Python versions](https://img.shields.io/pypi/pyversions/nyansqlite.svg)](https://pypi.org/project/nyansqlite/)
70
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
71
+
72
+ **Pythonic SQLite with Pydantic models, Django-like queries, and FTS5 full-text search.**
73
+
74
+ [English](#english) | [日本語](#日本語)
75
+
76
+ ---
77
+
78
+ ## 日本語
79
+
80
+ NyanSQLiteは、Pydanticモデルをそのままデータベーススキーマとして利用できる、型安全で高性能なSQLiteラッパーです。
81
+ 複雑なSQLを書くことなく、Pythonの型ヒントと直感的なクエリでデータを管理できます。
82
+
83
+ ### 🚀 主な特徴
84
+
85
+ | 機能 | 説明 |
86
+ |-----|------|
87
+ | **Pydanticベースのスキーマ** | 型ヒントで自動バリデーション、JSON変換も透過的 |
88
+ | **Djangoライクなクエリ** | `__gte`, `__in`, `__like` など直感的なフィルタリング |
89
+ | **FTS5全文検索** | テキストデータから高速に検索結果を取得 |
90
+ | **自動インデックス管理** | `Indexed[T]` アノテーションで B-tree インデックスを自動構築 |
91
+ | **複雑な型を透過的に処理** | dict や list を JSON で保存、自動で Python オブジェクトに戻す |
92
+ | **パフォーマンス最適化** | WAL モード、バッチ処理による高速化 |
93
+
94
+ ### 📦 インストール
95
+
96
+ ```bash
97
+ pip install nyansqlite
98
+ ```
99
+
100
+ Pydantic v2が必須です:
101
+
102
+ ```bash
103
+ pip install "pydantic>=2.0"
104
+ ```
105
+
106
+ ### ⚡ 5分クイックスタート
107
+
108
+ ```python
109
+ from pydantic import BaseModel
110
+ from nyansqlite import NyanSQLite, Indexed, Searchable
111
+
112
+ # 1️⃣ スキーマ定義(型ヒント+Pydantic)
113
+ class Article(BaseModel):
114
+ id: int # idフィールドが自動的に主キーになる
115
+ author: Indexed[str] # インデックス付きカラム
116
+ title: Searchable[str] # 全文検索対象
117
+ body: Searchable[str] # 全文検索対象
118
+ views: int = 0
119
+
120
+ # 2️⃣ DB初期化&テーブル作成
121
+ db = NyanSQLite("blog.db")
122
+ db.register(Article)
123
+
124
+ # 3️⃣ データ挿入
125
+ db.insert(Article(
126
+ id=1,
127
+ author="neko",
128
+ title="SQLiteを使いこなそう",
129
+ body="NyanSQLiteで簡単にデータ管理ができます。"
130
+ ))
131
+
132
+ # 4️⃣ クエリ実行(Django風)
133
+ articles = db.query(Article, author="neko", views__gte=0, order_by="id", desc=True)
134
+
135
+ # 5️⃣ 全文検索(FTS5)
136
+ results = db.search(Article, "SQLite")
137
+ for hit in results:
138
+ print(f"✨ {hit.title}")
139
+
140
+ db.close()
141
+ ```
142
+
143
+ ### 🔍 クエリ演算子リファレンス
144
+
145
+ ```python
146
+ # 完全一致
147
+ db.query(Article, author="neko")
148
+
149
+ # 演算子フィルタ
150
+ db.query(Article,
151
+ views__gt=10, # >
152
+ views__gte=10, # >=
153
+ views__lt=100, # <
154
+ views__lte=100, # <=
155
+ views__ne=50, # !=
156
+ )
157
+
158
+ # 文字列フィルタ
159
+ db.query(Article,
160
+ title__like="%Python%", # LIKE検索
161
+ )
162
+
163
+ # IN句
164
+ db.query(Article,
165
+ id__in=[1, 2, 3],
166
+ )
167
+
168
+ # NULL チェック
169
+ db.query(Article,
170
+ author__is_null=False,
171
+ )
172
+ ```
173
+
174
+ ### 🎯 実装例:ゲームのプレイヤーシステム
175
+
176
+ ```python
177
+ from datetime import datetime
178
+ from pydantic import BaseModel
179
+
180
+ class Player(BaseModel):
181
+ player_id: int # 主キー
182
+ username: Indexed[str] # ユーザー名でインデックス
183
+ level: Indexed[int] # レベルでインデックス
184
+ score: int = 0
185
+ created_at: datetime
186
+
187
+ db = NyanSQLite("game.db")
188
+ db.register(Player)
189
+
190
+ # バッチ登録(大量データが高速)
191
+ players = [
192
+ Player(player_id=i, username=f"player_{i}", level=i%50, created_at=datetime.now())
193
+ for i in range(1, 1001)
194
+ ]
195
+ db.insert_many(players)
196
+
197
+ # ランキング取得
198
+ top_players = db.query(Player, order_by="score", desc=True, limit=10)
199
+
200
+ # 条件付き検索&更新
201
+ high_level = db.query(Player, level__gte=40, limit=100)
202
+ db.update(Player, where={"player_id": 1}, score=9999)
203
+
204
+ # 数を数える
205
+ player_count = db.count(Player)
206
+ active_count = db.count(Player, level__gte=30)
207
+ ```
208
+
209
+ ### 📊 パフォーマンス
210
+
211
+ NyanSQLiteは以下の最適化を実装しています:
212
+
213
+ - **WAL モード**: 読み書き同時実行性の向上
214
+ - **トランザクション**: `insert_many()` はデフォルトでトランザクション内で実行
215
+ - **パラメータ化クエリ**: SQL インジェクション対策も兼ねた安全性
216
+
217
+ ```python
218
+ # 10万件をわずか0秒台で挿入(バッチ処理)
219
+ import time
220
+ players = [Player(player_id=i, ...) for i in range(100000)]
221
+ start = time.time()
222
+ db.insert_many(players)
223
+ print(f"Inserted in {time.time() - start:.4f}s") # 例: 0.3456s
224
+ ```
225
+
226
+ ### 🛠️ 高度な機能
227
+
228
+ #### 複合インデックス
229
+
230
+ ```python
231
+ from nyansqlite import CompositeIndex
232
+
233
+ class Order(BaseModel):
234
+ __nyan_indexes__ = [
235
+ CompositeIndex("user_id", "created_at"),
236
+ CompositeIndex("product_id", "status", unique=True),
237
+ ]
238
+ id: int
239
+ user_id: int
240
+ product_id: int
241
+ created_at: datetime
242
+ status: str
243
+ ```
244
+
245
+ #### 主キーのカスタマイズ
246
+
247
+ フィールド名が `id` でない場合:
248
+
249
+ ```python
250
+ class User(BaseModel):
251
+ __nyan_primary_key__ = "user_id"
252
+ user_id: int
253
+ email: str
254
+ name: str
255
+ ```
256
+
257
+ #### コンテキストマネージャー
258
+
259
+ ```python
260
+ with NyanSQLite("app.db") as db:
261
+ db.register(Article)
262
+ db.insert(Article(...))
263
+ # 自動的にcloseされる
264
+ ```
265
+
266
+ ### 🧹 メンテナンス
267
+
268
+ ```python
269
+ # インデックスの再構築
270
+ db.rebuild_fts(Article)
271
+
272
+ # データベース最適化(ファイルサイズを縮小)
273
+ db.vacuum()
274
+
275
+ # 存在確認
276
+ if db.exists(Article, id=1):
277
+ print("Found!")
278
+
279
+ # 部分取得(カラムを指定)
280
+ titles = db.select(Article, ["title", "author"], views__gte=100)
281
+ ```
282
+
283
+ ### 🚨 型モデルのベストプラクティス
284
+
285
+ ```python
286
+ from pydantic import ConfigDict
287
+
288
+ class Article(BaseModel):
289
+ # Pydantic v2の設定
290
+ model_config = ConfigDict(
291
+ arbitrary_types_allowed=True, # 複雑な型をサポート
292
+ validate_assignment=True,
293
+ )
294
+
295
+ id: int
296
+ # ... その他フィールド
297
+ ```
298
+
299
+ ---
300
+
301
+ ## English
302
+
303
+ NyanSQLite is a type-safe, high-performance SQLite wrapper that transforms Pydantic models directly into database schemas. Write minimal SQL while leveraging the power of FTS5 full-text search and Django-inspired query syntax.
304
+
305
+ ### 🚀 Features
306
+
307
+ | Feature | Benefit |
308
+ |---------|---------|
309
+ | **Pydantic Integration** | Type-safe validation and automatic JSON serialization |
310
+ | **Django-like Queries** | `__gte`, `__in`, `__like` and more—no SQL needed |
311
+ | **FTS5 Search** | Lightning-fast full-text search on `Searchable[str]` fields |
312
+ | **Auto-Indexing** | Create B-tree indexes with `Indexed[T]` annotations |
313
+ | **Complex Types** | Transparent handling of dict, list, and custom types |
314
+ | **Performance Optimized** | WAL mode, batch inserts, parameterized queries |
315
+
316
+ ### 📦 Installation
317
+
318
+ ```bash
319
+ pip install nyansqlite
320
+ ```
321
+
322
+ Requires Python 3.9+ and Pydantic 2.0+.
323
+
324
+ ### ⚡ Quick Start
325
+
326
+ ```python
327
+ from pydantic import BaseModel
328
+ from nyansqlite import NyanSQLite, Indexed, Searchable
329
+
330
+ class Post(BaseModel):
331
+ id: int
332
+ title: Searchable[str]
333
+ author: Indexed[str]
334
+ views: int = 0
335
+
336
+ db = NyanSQLite(":memory:")
337
+ db.register(Post)
338
+
339
+ # Insert
340
+ db.insert(Post(id=1, title="Hello SQLite", author="neko"))
341
+
342
+ # Query
343
+ posts = db.query(Post, author="neko", views__gte=0)
344
+
345
+ # Full-text search
346
+ results = db.search(Post, "SQLite")
347
+
348
+ db.close()
349
+ ```
350
+
351
+ ### 📚 API Reference
352
+
353
+ **Core Methods:**
354
+
355
+ - `register(model)` – Introspect model and create table
356
+ - `insert(obj)` – Insert a single record
357
+ - `insert_many(objs)` – Bulk insert with transaction
358
+ - `query(**kwargs)` – SELECT with filters, ordering, pagination
359
+ - `search(query, limit)` – FTS5 full-text search
360
+ - `get(**kwargs)` – Fetch one record or None
361
+ - `update(where, **fields)` – Partial UPDATE
362
+ - `delete(**kwargs)` – Conditional DELETE
363
+ - `count(**kwargs)` – COUNT rows matching condition
364
+ - `exists(**kwargs)` – Check if any row matches
365
+ - `select(fields, **kwargs)` – Fetch specific columns as dicts
366
+ - `vacuum()` – Optimize database file
367
+ - `close()` – Close connection
368
+
369
+ ### 🔗 Resources
370
+
371
+ - **Repository**: [github.com/disnana/nyansqlite](https://github.com/disnana/nyansqlite)
372
+ - **Issues**: [Report bugs](https://github.com/disnana/nyansqlite/issues)
373
+
374
+ ---
375
+
376
+ ## License
377
+
378
+ MIT License – see [LICENSE](LICENSE) for details.
@@ -0,0 +1,313 @@
1
+ # NyanSQLite
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/nyansqlite.svg)](https://pypi.org/project/nyansqlite/)
4
+ [![Python versions](https://img.shields.io/pypi/pyversions/nyansqlite.svg)](https://pypi.org/project/nyansqlite/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ **Pythonic SQLite with Pydantic models, Django-like queries, and FTS5 full-text search.**
8
+
9
+ [English](#english) | [日本語](#日本語)
10
+
11
+ ---
12
+
13
+ ## 日本語
14
+
15
+ NyanSQLiteは、Pydanticモデルをそのままデータベーススキーマとして利用できる、型安全で高性能なSQLiteラッパーです。
16
+ 複雑なSQLを書くことなく、Pythonの型ヒントと直感的なクエリでデータを管理できます。
17
+
18
+ ### 🚀 主な特徴
19
+
20
+ | 機能 | 説明 |
21
+ |-----|------|
22
+ | **Pydanticベースのスキーマ** | 型ヒントで自動バリデーション、JSON変換も透過的 |
23
+ | **Djangoライクなクエリ** | `__gte`, `__in`, `__like` など直感的なフィルタリング |
24
+ | **FTS5全文検索** | テキストデータから高速に検索結果を取得 |
25
+ | **自動インデックス管理** | `Indexed[T]` アノテーションで B-tree インデックスを自動構築 |
26
+ | **複雑な型を透過的に処理** | dict や list を JSON で保存、自動で Python オブジェクトに戻す |
27
+ | **パフォーマンス最適化** | WAL モード、バッチ処理による高速化 |
28
+
29
+ ### 📦 インストール
30
+
31
+ ```bash
32
+ pip install nyansqlite
33
+ ```
34
+
35
+ Pydantic v2が必須です:
36
+
37
+ ```bash
38
+ pip install "pydantic>=2.0"
39
+ ```
40
+
41
+ ### ⚡ 5分クイックスタート
42
+
43
+ ```python
44
+ from pydantic import BaseModel
45
+ from nyansqlite import NyanSQLite, Indexed, Searchable
46
+
47
+ # 1️⃣ スキーマ定義(型ヒント+Pydantic)
48
+ class Article(BaseModel):
49
+ id: int # idフィールドが自動的に主キーになる
50
+ author: Indexed[str] # インデックス付きカラム
51
+ title: Searchable[str] # 全文検索対象
52
+ body: Searchable[str] # 全文検索対象
53
+ views: int = 0
54
+
55
+ # 2️⃣ DB初期化&テーブル作成
56
+ db = NyanSQLite("blog.db")
57
+ db.register(Article)
58
+
59
+ # 3️⃣ データ挿入
60
+ db.insert(Article(
61
+ id=1,
62
+ author="neko",
63
+ title="SQLiteを使いこなそう",
64
+ body="NyanSQLiteで簡単にデータ管理ができます。"
65
+ ))
66
+
67
+ # 4️⃣ クエリ実行(Django風)
68
+ articles = db.query(Article, author="neko", views__gte=0, order_by="id", desc=True)
69
+
70
+ # 5️⃣ 全文検索(FTS5)
71
+ results = db.search(Article, "SQLite")
72
+ for hit in results:
73
+ print(f"✨ {hit.title}")
74
+
75
+ db.close()
76
+ ```
77
+
78
+ ### 🔍 クエリ演算子リファレンス
79
+
80
+ ```python
81
+ # 完全一致
82
+ db.query(Article, author="neko")
83
+
84
+ # 演算子フィルタ
85
+ db.query(Article,
86
+ views__gt=10, # >
87
+ views__gte=10, # >=
88
+ views__lt=100, # <
89
+ views__lte=100, # <=
90
+ views__ne=50, # !=
91
+ )
92
+
93
+ # 文字列フィルタ
94
+ db.query(Article,
95
+ title__like="%Python%", # LIKE検索
96
+ )
97
+
98
+ # IN句
99
+ db.query(Article,
100
+ id__in=[1, 2, 3],
101
+ )
102
+
103
+ # NULL チェック
104
+ db.query(Article,
105
+ author__is_null=False,
106
+ )
107
+ ```
108
+
109
+ ### 🎯 実装例:ゲームのプレイヤーシステム
110
+
111
+ ```python
112
+ from datetime import datetime
113
+ from pydantic import BaseModel
114
+
115
+ class Player(BaseModel):
116
+ player_id: int # 主キー
117
+ username: Indexed[str] # ユーザー名でインデックス
118
+ level: Indexed[int] # レベルでインデックス
119
+ score: int = 0
120
+ created_at: datetime
121
+
122
+ db = NyanSQLite("game.db")
123
+ db.register(Player)
124
+
125
+ # バッチ登録(大量データが高速)
126
+ players = [
127
+ Player(player_id=i, username=f"player_{i}", level=i%50, created_at=datetime.now())
128
+ for i in range(1, 1001)
129
+ ]
130
+ db.insert_many(players)
131
+
132
+ # ランキング取得
133
+ top_players = db.query(Player, order_by="score", desc=True, limit=10)
134
+
135
+ # 条件付き検索&更新
136
+ high_level = db.query(Player, level__gte=40, limit=100)
137
+ db.update(Player, where={"player_id": 1}, score=9999)
138
+
139
+ # 数を数える
140
+ player_count = db.count(Player)
141
+ active_count = db.count(Player, level__gte=30)
142
+ ```
143
+
144
+ ### 📊 パフォーマンス
145
+
146
+ NyanSQLiteは以下の最適化を実装しています:
147
+
148
+ - **WAL モード**: 読み書き同時実行性の向上
149
+ - **トランザクション**: `insert_many()` はデフォルトでトランザクション内で実行
150
+ - **パラメータ化クエリ**: SQL インジェクション対策も兼ねた安全性
151
+
152
+ ```python
153
+ # 10万件をわずか0秒台で挿入(バッチ処理)
154
+ import time
155
+ players = [Player(player_id=i, ...) for i in range(100000)]
156
+ start = time.time()
157
+ db.insert_many(players)
158
+ print(f"Inserted in {time.time() - start:.4f}s") # 例: 0.3456s
159
+ ```
160
+
161
+ ### 🛠️ 高度な機能
162
+
163
+ #### 複合インデックス
164
+
165
+ ```python
166
+ from nyansqlite import CompositeIndex
167
+
168
+ class Order(BaseModel):
169
+ __nyan_indexes__ = [
170
+ CompositeIndex("user_id", "created_at"),
171
+ CompositeIndex("product_id", "status", unique=True),
172
+ ]
173
+ id: int
174
+ user_id: int
175
+ product_id: int
176
+ created_at: datetime
177
+ status: str
178
+ ```
179
+
180
+ #### 主キーのカスタマイズ
181
+
182
+ フィールド名が `id` でない場合:
183
+
184
+ ```python
185
+ class User(BaseModel):
186
+ __nyan_primary_key__ = "user_id"
187
+ user_id: int
188
+ email: str
189
+ name: str
190
+ ```
191
+
192
+ #### コンテキストマネージャー
193
+
194
+ ```python
195
+ with NyanSQLite("app.db") as db:
196
+ db.register(Article)
197
+ db.insert(Article(...))
198
+ # 自動的にcloseされる
199
+ ```
200
+
201
+ ### 🧹 メンテナンス
202
+
203
+ ```python
204
+ # インデックスの再構築
205
+ db.rebuild_fts(Article)
206
+
207
+ # データベース最適化(ファイルサイズを縮小)
208
+ db.vacuum()
209
+
210
+ # 存在確認
211
+ if db.exists(Article, id=1):
212
+ print("Found!")
213
+
214
+ # 部分取得(カラムを指定)
215
+ titles = db.select(Article, ["title", "author"], views__gte=100)
216
+ ```
217
+
218
+ ### 🚨 型モデルのベストプラクティス
219
+
220
+ ```python
221
+ from pydantic import ConfigDict
222
+
223
+ class Article(BaseModel):
224
+ # Pydantic v2の設定
225
+ model_config = ConfigDict(
226
+ arbitrary_types_allowed=True, # 複雑な型をサポート
227
+ validate_assignment=True,
228
+ )
229
+
230
+ id: int
231
+ # ... その他フィールド
232
+ ```
233
+
234
+ ---
235
+
236
+ ## English
237
+
238
+ NyanSQLite is a type-safe, high-performance SQLite wrapper that transforms Pydantic models directly into database schemas. Write minimal SQL while leveraging the power of FTS5 full-text search and Django-inspired query syntax.
239
+
240
+ ### 🚀 Features
241
+
242
+ | Feature | Benefit |
243
+ |---------|---------|
244
+ | **Pydantic Integration** | Type-safe validation and automatic JSON serialization |
245
+ | **Django-like Queries** | `__gte`, `__in`, `__like` and more—no SQL needed |
246
+ | **FTS5 Search** | Lightning-fast full-text search on `Searchable[str]` fields |
247
+ | **Auto-Indexing** | Create B-tree indexes with `Indexed[T]` annotations |
248
+ | **Complex Types** | Transparent handling of dict, list, and custom types |
249
+ | **Performance Optimized** | WAL mode, batch inserts, parameterized queries |
250
+
251
+ ### 📦 Installation
252
+
253
+ ```bash
254
+ pip install nyansqlite
255
+ ```
256
+
257
+ Requires Python 3.9+ and Pydantic 2.0+.
258
+
259
+ ### ⚡ Quick Start
260
+
261
+ ```python
262
+ from pydantic import BaseModel
263
+ from nyansqlite import NyanSQLite, Indexed, Searchable
264
+
265
+ class Post(BaseModel):
266
+ id: int
267
+ title: Searchable[str]
268
+ author: Indexed[str]
269
+ views: int = 0
270
+
271
+ db = NyanSQLite(":memory:")
272
+ db.register(Post)
273
+
274
+ # Insert
275
+ db.insert(Post(id=1, title="Hello SQLite", author="neko"))
276
+
277
+ # Query
278
+ posts = db.query(Post, author="neko", views__gte=0)
279
+
280
+ # Full-text search
281
+ results = db.search(Post, "SQLite")
282
+
283
+ db.close()
284
+ ```
285
+
286
+ ### 📚 API Reference
287
+
288
+ **Core Methods:**
289
+
290
+ - `register(model)` – Introspect model and create table
291
+ - `insert(obj)` – Insert a single record
292
+ - `insert_many(objs)` – Bulk insert with transaction
293
+ - `query(**kwargs)` – SELECT with filters, ordering, pagination
294
+ - `search(query, limit)` – FTS5 full-text search
295
+ - `get(**kwargs)` – Fetch one record or None
296
+ - `update(where, **fields)` – Partial UPDATE
297
+ - `delete(**kwargs)` – Conditional DELETE
298
+ - `count(**kwargs)` – COUNT rows matching condition
299
+ - `exists(**kwargs)` – Check if any row matches
300
+ - `select(fields, **kwargs)` – Fetch specific columns as dicts
301
+ - `vacuum()` – Optimize database file
302
+ - `close()` – Close connection
303
+
304
+ ### 🔗 Resources
305
+
306
+ - **Repository**: [github.com/disnana/nyansqlite](https://github.com/disnana/nyansqlite)
307
+ - **Issues**: [Report bugs](https://github.com/disnana/nyansqlite/issues)
308
+
309
+ ---
310
+
311
+ ## License
312
+
313
+ MIT License – see [LICENSE](LICENSE) for details.