pbatis-core 0.1.0__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,80 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ name: test (linux x86_64)
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.12"
20
+ - run: pip install maturin pytest
21
+ - run: maturin build --release --out dist
22
+ - run: pip install dist/*.whl && pytest tests -q
23
+
24
+ build:
25
+ name: wheel ${{ matrix.target }}
26
+ needs: test
27
+ runs-on: ${{ matrix.os }}
28
+ strategy:
29
+ fail-fast: false
30
+ matrix:
31
+ include:
32
+ - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, manylinux: "2_28" }
33
+ - { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, manylinux: "2_28" }
34
+ # 一个 universal2 wheel 同时覆盖 Intel 与 Apple Silicon
35
+ - { os: macos-latest, target: universal2-apple-darwin, manylinux: auto }
36
+ - { os: windows-latest, target: x86_64-pc-windows-msvc, manylinux: auto }
37
+ steps:
38
+ - uses: actions/checkout@v4
39
+ - uses: PyO3/maturin-action@v1
40
+ with:
41
+ target: ${{ matrix.target }}
42
+ manylinux: ${{ matrix.manylinux }}
43
+ args: --release --out dist
44
+ sccache: "true"
45
+ - uses: actions/upload-artifact@v4
46
+ with:
47
+ name: dist-${{ matrix.target }}
48
+ path: dist
49
+
50
+ sdist:
51
+ name: sdist
52
+ needs: test
53
+ runs-on: ubuntu-latest
54
+ steps:
55
+ - uses: actions/checkout@v4
56
+ - uses: PyO3/maturin-action@v1
57
+ with:
58
+ command: sdist
59
+ args: --out dist
60
+ - uses: actions/upload-artifact@v4
61
+ with:
62
+ name: dist-sdist
63
+ path: dist
64
+
65
+ publish:
66
+ name: publish to PyPI
67
+ needs: [build, sdist]
68
+ runs-on: ubuntu-latest
69
+ environment:
70
+ name: pypi
71
+ url: https://pypi.org/p/pbatis-core
72
+ permissions:
73
+ id-token: write
74
+ steps:
75
+ - uses: actions/download-artifact@v4
76
+ with:
77
+ pattern: dist-*
78
+ merge-multiple: true
79
+ path: dist
80
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,9 @@
1
+ /target
2
+ /dist
3
+ *.so
4
+ *.pyd
5
+ *.dylib
6
+ __pycache__/
7
+ *.egg-info/
8
+ .venv/
9
+ .pytest_cache/
@@ -0,0 +1,425 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "ahash"
7
+ version = "0.8.16"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "df3ca8d1551af9c10613a1d38022524dc2ea76206f87b36e9d273bbe8e3e8d05"
10
+ dependencies = [
11
+ "cfg-if",
12
+ "getrandom",
13
+ "once_cell",
14
+ "version_check",
15
+ "zerocopy",
16
+ ]
17
+
18
+ [[package]]
19
+ name = "autocfg"
20
+ version = "1.5.1"
21
+ source = "registry+https://github.com/rust-lang/crates.io-index"
22
+ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
23
+
24
+ [[package]]
25
+ name = "bitflags"
26
+ version = "2.13.2"
27
+ source = "registry+https://github.com/rust-lang/crates.io-index"
28
+ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
29
+
30
+ [[package]]
31
+ name = "bumpalo"
32
+ version = "3.20.4"
33
+ source = "registry+https://github.com/rust-lang/crates.io-index"
34
+ checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db"
35
+
36
+ [[package]]
37
+ name = "cc"
38
+ version = "1.13.0"
39
+ source = "registry+https://github.com/rust-lang/crates.io-index"
40
+ checksum = "53b4e5299ae8fd0d9e848f3efafd5b4feed729b8c731df9d62375cb1efdc3f4e"
41
+ dependencies = [
42
+ "find-msvc-tools",
43
+ "shlex",
44
+ ]
45
+
46
+ [[package]]
47
+ name = "cfg-if"
48
+ version = "1.0.5"
49
+ source = "registry+https://github.com/rust-lang/crates.io-index"
50
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
51
+
52
+ [[package]]
53
+ name = "fallible-iterator"
54
+ version = "0.3.0"
55
+ source = "registry+https://github.com/rust-lang/crates.io-index"
56
+ checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
57
+
58
+ [[package]]
59
+ name = "fallible-streaming-iterator"
60
+ version = "0.1.9"
61
+ source = "registry+https://github.com/rust-lang/crates.io-index"
62
+ checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
63
+
64
+ [[package]]
65
+ name = "find-msvc-tools"
66
+ version = "0.1.17"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ checksum = "f35b0b9b788e7109a8eb0607f5c8a13495edee3ef8e246f60f0664a7cd25b277"
69
+
70
+ [[package]]
71
+ name = "getrandom"
72
+ version = "0.4.3"
73
+ source = "registry+https://github.com/rust-lang/crates.io-index"
74
+ checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
75
+ dependencies = [
76
+ "cfg-if",
77
+ "js-sys",
78
+ "libc",
79
+ "r-efi",
80
+ "wasm-bindgen",
81
+ ]
82
+
83
+ [[package]]
84
+ name = "hashbrown"
85
+ version = "0.14.5"
86
+ source = "registry+https://github.com/rust-lang/crates.io-index"
87
+ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
88
+ dependencies = [
89
+ "ahash",
90
+ ]
91
+
92
+ [[package]]
93
+ name = "hashlink"
94
+ version = "0.9.1"
95
+ source = "registry+https://github.com/rust-lang/crates.io-index"
96
+ checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af"
97
+ dependencies = [
98
+ "hashbrown",
99
+ ]
100
+
101
+ [[package]]
102
+ name = "heck"
103
+ version = "0.5.0"
104
+ source = "registry+https://github.com/rust-lang/crates.io-index"
105
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
106
+
107
+ [[package]]
108
+ name = "indoc"
109
+ version = "2.0.8"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "a37b2691796cffeb8a8cd305ac66e65841559f147f4e63231d0eafa4db5384d1"
112
+ dependencies = [
113
+ "rustversion",
114
+ ]
115
+
116
+ [[package]]
117
+ name = "itoa"
118
+ version = "1.0.19"
119
+ source = "registry+https://github.com/rust-lang/crates.io-index"
120
+ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
121
+
122
+ [[package]]
123
+ name = "js-sys"
124
+ version = "0.3.107"
125
+ source = "registry+https://github.com/rust-lang/crates.io-index"
126
+ checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
127
+ dependencies = [
128
+ "cfg-if",
129
+ "wasm-bindgen",
130
+ ]
131
+
132
+ [[package]]
133
+ name = "libc"
134
+ version = "0.2.191"
135
+ source = "registry+https://github.com/rust-lang/crates.io-index"
136
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
137
+
138
+ [[package]]
139
+ name = "libsqlite3-sys"
140
+ version = "0.30.1"
141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
142
+ checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149"
143
+ dependencies = [
144
+ "cc",
145
+ "pkg-config",
146
+ "vcpkg",
147
+ ]
148
+
149
+ [[package]]
150
+ name = "memoffset"
151
+ version = "0.9.1"
152
+ source = "registry+https://github.com/rust-lang/crates.io-index"
153
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
154
+ dependencies = [
155
+ "autocfg",
156
+ ]
157
+
158
+ [[package]]
159
+ name = "once_cell"
160
+ version = "1.21.4"
161
+ source = "registry+https://github.com/rust-lang/crates.io-index"
162
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
163
+
164
+ [[package]]
165
+ name = "pbatis-core"
166
+ version = "0.1.0"
167
+ dependencies = [
168
+ "itoa",
169
+ "pyo3",
170
+ "rusqlite",
171
+ "ryu",
172
+ ]
173
+
174
+ [[package]]
175
+ name = "pkg-config"
176
+ version = "0.3.34"
177
+ source = "registry+https://github.com/rust-lang/crates.io-index"
178
+ checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
179
+
180
+ [[package]]
181
+ name = "portable-atomic"
182
+ version = "1.15.0"
183
+ source = "registry+https://github.com/rust-lang/crates.io-index"
184
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
185
+
186
+ [[package]]
187
+ name = "proc-macro2"
188
+ version = "1.0.107"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
191
+ dependencies = [
192
+ "unicode-ident",
193
+ ]
194
+
195
+ [[package]]
196
+ name = "pyo3"
197
+ version = "0.24.2"
198
+ source = "registry+https://github.com/rust-lang/crates.io-index"
199
+ checksum = "e5203598f366b11a02b13aa20cab591229ff0a89fd121a308a5df751d5fc9219"
200
+ dependencies = [
201
+ "cfg-if",
202
+ "indoc",
203
+ "libc",
204
+ "memoffset",
205
+ "once_cell",
206
+ "portable-atomic",
207
+ "pyo3-build-config",
208
+ "pyo3-ffi",
209
+ "pyo3-macros",
210
+ "unindent",
211
+ ]
212
+
213
+ [[package]]
214
+ name = "pyo3-build-config"
215
+ version = "0.24.2"
216
+ source = "registry+https://github.com/rust-lang/crates.io-index"
217
+ checksum = "99636d423fa2ca130fa5acde3059308006d46f98caac629418e53f7ebb1e9999"
218
+ dependencies = [
219
+ "once_cell",
220
+ "target-lexicon",
221
+ ]
222
+
223
+ [[package]]
224
+ name = "pyo3-ffi"
225
+ version = "0.24.2"
226
+ source = "registry+https://github.com/rust-lang/crates.io-index"
227
+ checksum = "78f9cf92ba9c409279bc3305b5409d90db2d2c22392d443a87df3a1adad59e33"
228
+ dependencies = [
229
+ "libc",
230
+ "pyo3-build-config",
231
+ ]
232
+
233
+ [[package]]
234
+ name = "pyo3-macros"
235
+ version = "0.24.2"
236
+ source = "registry+https://github.com/rust-lang/crates.io-index"
237
+ checksum = "0b999cb1a6ce21f9a6b147dcf1be9ffedf02e0043aec74dc390f3007047cecd9"
238
+ dependencies = [
239
+ "proc-macro2",
240
+ "pyo3-macros-backend",
241
+ "quote",
242
+ "syn 2.0.119",
243
+ ]
244
+
245
+ [[package]]
246
+ name = "pyo3-macros-backend"
247
+ version = "0.24.2"
248
+ source = "registry+https://github.com/rust-lang/crates.io-index"
249
+ checksum = "822ece1c7e1012745607d5cf0bcb2874769f0f7cb34c4cde03b9358eb9ef911a"
250
+ dependencies = [
251
+ "heck",
252
+ "proc-macro2",
253
+ "pyo3-build-config",
254
+ "quote",
255
+ "syn 2.0.119",
256
+ ]
257
+
258
+ [[package]]
259
+ name = "quote"
260
+ version = "1.0.47"
261
+ source = "registry+https://github.com/rust-lang/crates.io-index"
262
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
263
+ dependencies = [
264
+ "proc-macro2",
265
+ ]
266
+
267
+ [[package]]
268
+ name = "r-efi"
269
+ version = "6.0.0"
270
+ source = "registry+https://github.com/rust-lang/crates.io-index"
271
+ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
272
+
273
+ [[package]]
274
+ name = "rusqlite"
275
+ version = "0.32.1"
276
+ source = "registry+https://github.com/rust-lang/crates.io-index"
277
+ checksum = "7753b721174eb8ff87a9a0e799e2d7bc3749323e773db92e0984debb00019d6e"
278
+ dependencies = [
279
+ "bitflags",
280
+ "fallible-iterator",
281
+ "fallible-streaming-iterator",
282
+ "hashlink",
283
+ "libsqlite3-sys",
284
+ "smallvec",
285
+ ]
286
+
287
+ [[package]]
288
+ name = "rustversion"
289
+ version = "1.0.23"
290
+ source = "registry+https://github.com/rust-lang/crates.io-index"
291
+ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
292
+
293
+ [[package]]
294
+ name = "ryu"
295
+ version = "1.0.23"
296
+ source = "registry+https://github.com/rust-lang/crates.io-index"
297
+ checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
298
+
299
+ [[package]]
300
+ name = "shlex"
301
+ version = "2.0.1"
302
+ source = "registry+https://github.com/rust-lang/crates.io-index"
303
+ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
304
+
305
+ [[package]]
306
+ name = "smallvec"
307
+ version = "1.16.6"
308
+ source = "registry+https://github.com/rust-lang/crates.io-index"
309
+ checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59"
310
+
311
+ [[package]]
312
+ name = "syn"
313
+ version = "2.0.119"
314
+ source = "registry+https://github.com/rust-lang/crates.io-index"
315
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
316
+ dependencies = [
317
+ "proc-macro2",
318
+ "quote",
319
+ "unicode-ident",
320
+ ]
321
+
322
+ [[package]]
323
+ name = "syn"
324
+ version = "3.0.10"
325
+ source = "registry+https://github.com/rust-lang/crates.io-index"
326
+ checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
327
+ dependencies = [
328
+ "proc-macro2",
329
+ "quote",
330
+ "unicode-ident",
331
+ ]
332
+
333
+ [[package]]
334
+ name = "target-lexicon"
335
+ version = "0.13.6"
336
+ source = "registry+https://github.com/rust-lang/crates.io-index"
337
+ checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
338
+
339
+ [[package]]
340
+ name = "unicode-ident"
341
+ version = "1.0.27"
342
+ source = "registry+https://github.com/rust-lang/crates.io-index"
343
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
344
+
345
+ [[package]]
346
+ name = "unindent"
347
+ version = "0.2.4"
348
+ source = "registry+https://github.com/rust-lang/crates.io-index"
349
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
350
+
351
+ [[package]]
352
+ name = "vcpkg"
353
+ version = "0.2.15"
354
+ source = "registry+https://github.com/rust-lang/crates.io-index"
355
+ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
356
+
357
+ [[package]]
358
+ name = "version_check"
359
+ version = "0.9.5"
360
+ source = "registry+https://github.com/rust-lang/crates.io-index"
361
+ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
362
+
363
+ [[package]]
364
+ name = "wasm-bindgen"
365
+ version = "0.2.130"
366
+ source = "registry+https://github.com/rust-lang/crates.io-index"
367
+ checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
368
+ dependencies = [
369
+ "cfg-if",
370
+ "rustversion",
371
+ "wasm-bindgen-macro",
372
+ "wasm-bindgen-shared",
373
+ ]
374
+
375
+ [[package]]
376
+ name = "wasm-bindgen-macro"
377
+ version = "0.2.130"
378
+ source = "registry+https://github.com/rust-lang/crates.io-index"
379
+ checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
380
+ dependencies = [
381
+ "quote",
382
+ "wasm-bindgen-macro-support",
383
+ ]
384
+
385
+ [[package]]
386
+ name = "wasm-bindgen-macro-support"
387
+ version = "0.2.130"
388
+ source = "registry+https://github.com/rust-lang/crates.io-index"
389
+ checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
390
+ dependencies = [
391
+ "bumpalo",
392
+ "proc-macro2",
393
+ "quote",
394
+ "syn 3.0.10",
395
+ "wasm-bindgen-shared",
396
+ ]
397
+
398
+ [[package]]
399
+ name = "wasm-bindgen-shared"
400
+ version = "0.2.130"
401
+ source = "registry+https://github.com/rust-lang/crates.io-index"
402
+ checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
403
+ dependencies = [
404
+ "unicode-ident",
405
+ ]
406
+
407
+ [[package]]
408
+ name = "zerocopy"
409
+ version = "0.8.66"
410
+ source = "registry+https://github.com/rust-lang/crates.io-index"
411
+ checksum = "cba8a86aee14fc8cc6c208af60854b3d4ab7185a9a369a12c648faa2716ff42a"
412
+ dependencies = [
413
+ "zerocopy-derive",
414
+ ]
415
+
416
+ [[package]]
417
+ name = "zerocopy-derive"
418
+ version = "0.8.66"
419
+ source = "registry+https://github.com/rust-lang/crates.io-index"
420
+ checksum = "f89bca3b96ceb3cfcb4572790402f977442270d252b9a8504ebc258760c55f94"
421
+ dependencies = [
422
+ "proc-macro2",
423
+ "quote",
424
+ "syn 2.0.119",
425
+ ]
@@ -0,0 +1,22 @@
1
+ [package]
2
+ name = "pbatis-core"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ description = "Native fast channel for pbatis: query results straight to JSON bytes"
6
+ license = "MIT"
7
+ readme = "README.md"
8
+
9
+ [lib]
10
+ name = "pbatis_core"
11
+ crate-type = ["cdylib"]
12
+
13
+ [dependencies]
14
+ pyo3 = { version = "0.24", features = ["extension-module", "abi3-py39"] }
15
+ itoa = "1"
16
+ ryu = "1"
17
+ rusqlite = { version = "0.32", features = ["bundled"] }
18
+
19
+ [profile.release]
20
+ lto = "thin"
21
+ codegen-units = 1
22
+ panic = "unwind"
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Corsak
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,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: pbatis-core
3
+ Version: 0.1.0
4
+ Provides-Extra: sqlite
5
+ License-File: LICENSE
6
+ Summary: pbatis 的原生快通道:查询结果直出 JSON bytes,不构造 Python 对象
7
+ License: MIT
8
+ Requires-Python: >=3.9
@@ -0,0 +1,79 @@
1
+ # pbatis-core
2
+
3
+ pbatis 的原生快通道:**查询结果在 Rust 里直接写成 JSON bytes**,不构造 Python 对象。
4
+
5
+ 它不是驱动替换,也不接管事务——SQL 仍由 pbatis 编译,写路径仍走 pbatis 的 DBAPI 连接;这里只负责"只读查询 → JSON"这一段,把 CPython 侧最贵的对象创建和序列化整段下沉。
6
+
7
+ ```python
8
+ import json
9
+ import pbatis_core as core
10
+
11
+ raw = core.query_json("sqlite:////var/data/app.db", "select id, name from user limit 100")
12
+ rows = json.loads(raw) # [{'id': 1, 'name': '...'}, ...]
13
+ ```
14
+
15
+ ## 为什么需要它
16
+
17
+ 在 CPython 上,Rust 做"逐行建对象"没有意义——对象必须由 CPython 创建,实测只有 1.05×。有量级收益的只有一种做法:**连接、取值、序列化全在 Rust 里完成,Python 只拿到一段 bytes**。
18
+
19
+ 6 万行 × 4 列 SQLite,5 次取最小值:
20
+
21
+ | 路径 | 耗时 |
22
+ | --- | --- |
23
+ | ORM 实体 `scalars().all()` | 868–1153 ms |
24
+ | `session.dtos(stmt, Dto)`(pbatis 快路径) | 176–207 ms |
25
+ | `fetchall()` + `json.dumps(元组列表)` | ≈ 272 ms |
26
+ | **`pbatis_core.query_json()`** | **43.5 ms** |
27
+
28
+ 对同样"取完再序列化"的 Python 路径约 **6×**;对逐行构造 dict 再 dumps 的写法约 56×(dict 构造本身才是大头)。
29
+
30
+ ## 语义契约
31
+
32
+ - 输出对齐 `json.dumps(rows, ensure_ascii=False, separators=(",", ":"))`;文本、整数、NULL 逐字节一致。
33
+ - 浮点用 ryu,数值一致但指数写法可能不同(`1e300` vs Python 的 `1e+300`)。
34
+ - `inf` / `nan` 输出 `null`(JSON 无此字面量)。
35
+ - `BLOB` 输出 base64 字符串(RFC 4648);`NULL` 输出 `null`。
36
+ - 默认 `readonly=True`:SQLite 以 `READ_ONLY` 打开,写语句直接失败。需要读临时表时显式传 `readonly=False`。
37
+
38
+ ## 方言
39
+
40
+ | 方言 | 状态 | 通道 |
41
+ | --- | --- | --- |
42
+ | SQLite | 可用 | 自序列化(rusqlite bundled) |
43
+ | PostgreSQL | 计划 M1.5 | 自序列化(rust-postgres 二进制协议) |
44
+ | ClickHouse | 计划 M2 | 直通 `FORMAT JSONEachRow` |
45
+ | MySQL | 计划 M3 | 自序列化 |
46
+ | DuckDB | 计划 M4 | 直通 `COPY ... TO STDOUT` |
47
+
48
+ `core.dialects()` 返回当前编译进来的方言及可用状态;未接入的方言会给出明确报错,不会静默降级。
49
+
50
+ ## API
51
+
52
+ ```python
53
+ query_json(dsn, sql, params=None, *, fmt="json", readonly=True) -> bytes
54
+ query_count(dsn, sql, params=None, *, readonly=True) -> int
55
+ dialects() -> list[tuple[str, bool]]
56
+ ```
57
+
58
+ `params` 可以是序列(位置参数)或字典(命名参数);`fmt` 取 `"json"` 或 `"ndjson"`(每行一个对象,便于流式落盘)。
59
+
60
+ ## 开发
61
+
62
+ ```bash
63
+ maturin develop --release
64
+ python -m pytest tests -q
65
+ ```
66
+
67
+ 测试以"Python 路径为 reference":文本/整数/NULL 逐字节比对,浮点数值比对(见 `tests/test_consistency.py`)。
68
+
69
+ ## 路线图
70
+
71
+ - 0.1 SQLite 自序列化 + 语义对齐测试(当前)
72
+ - 0.2 连接池(只读、fork 安全、等连接不持 GIL)
73
+ - 0.3 PostgreSQL(M1.5)
74
+ - 0.4 ClickHouse / DuckDB 直通
75
+ - 0.5 MySQL
76
+
77
+ ## License
78
+
79
+ MIT
@@ -0,0 +1,17 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.7,<2.0"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "pbatis-core"
7
+ version = "0.1.0"
8
+ description = "pbatis 的原生快通道:查询结果直出 JSON bytes,不构造 Python 对象"
9
+ requires-python = ">=3.9"
10
+ license = { text = "MIT" }
11
+
12
+ [project.optional-dependencies]
13
+ # 驱动能力按需开启;sqlite 默认编译进 wheel
14
+ sqlite = []
15
+
16
+ [tool.maturin]
17
+ features = ["pyo3/extension-module"]