sqlite-utils 3.36__py3-none-any.whl → 3.37__py3-none-any.whl

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.
sqlite_utils/cli.py CHANGED
@@ -1489,7 +1489,7 @@ def create_database(path, enable_wal, init_spatialite, load_extension):
1489
1489
  )
1490
1490
  @click.argument("table")
1491
1491
  @click.argument("columns", nargs=-1, required=True)
1492
- @click.option("--pk", help="Column to use as primary key")
1492
+ @click.option("pks", "--pk", help="Column to use as primary key", multiple=True)
1493
1493
  @click.option(
1494
1494
  "--not-null",
1495
1495
  multiple=True,
@@ -1532,7 +1532,7 @@ def create_table(
1532
1532
  path,
1533
1533
  table,
1534
1534
  columns,
1535
- pk,
1535
+ pks,
1536
1536
  not_null,
1537
1537
  default,
1538
1538
  fk,
@@ -1581,7 +1581,7 @@ def create_table(
1581
1581
  )
1582
1582
  db[table].create(
1583
1583
  coltypes,
1584
- pk=pk,
1584
+ pk=pks[0] if len(pks) == 1 else pks,
1585
1585
  not_null=not_null,
1586
1586
  defaults=dict(default),
1587
1587
  foreign_keys=fk,
@@ -2594,7 +2594,7 @@ def extract(
2594
2594
  multiple=True,
2595
2595
  help="Column definitions for the table",
2596
2596
  )
2597
- @click.option("--pk", type=str, help="Column to use as primary key")
2597
+ @click.option("pks", "--pk", help="Column to use as primary key", multiple=True)
2598
2598
  @click.option("--alter", is_flag=True, help="Alter table to add missing columns")
2599
2599
  @click.option("--replace", is_flag=True, help="Replace files with matching primary key")
2600
2600
  @click.option("--upsert", is_flag=True, help="Upsert files with matching primary key")
@@ -2611,7 +2611,7 @@ def insert_files(
2611
2611
  table,
2612
2612
  file_or_dir,
2613
2613
  column,
2614
- pk,
2614
+ pks,
2615
2615
  alter,
2616
2616
  replace,
2617
2617
  upsert,
@@ -2641,8 +2641,8 @@ def insert_files(
2641
2641
  column = ["path:path", "content_text:content_text", "size:size"]
2642
2642
  else:
2643
2643
  column = ["path:path", "content:content", "size:size"]
2644
- if not pk:
2645
- pk = "path"
2644
+ if not pks:
2645
+ pks = ["path"]
2646
2646
 
2647
2647
  def yield_paths_and_relative_paths():
2648
2648
  for f_or_d in file_or_dir:
@@ -2712,7 +2712,11 @@ def insert_files(
2712
2712
  try:
2713
2713
  with db.conn:
2714
2714
  db[table].insert_all(
2715
- to_insert(), pk=pk, alter=alter, replace=replace, upsert=upsert
2715
+ to_insert(),
2716
+ pk=pks[0] if len(pks) == 1 else pks,
2717
+ alter=alter,
2718
+ replace=replace,
2719
+ upsert=upsert,
2716
2720
  )
2717
2721
  except UnicodeDecodeErrorForPath as e:
2718
2722
  raise click.ClickException(
@@ -2871,9 +2875,9 @@ def _generate_convert_help():
2871
2875
  Convert columns using Python code you supply. For example:
2872
2876
 
2873
2877
  \b
2874
- sqlite-utils convert my.db mytable mycolumn \\
2875
- '"\\n".join(textwrap.wrap(value, 10))' \\
2876
- --import=textwrap
2878
+ sqlite-utils convert my.db mytable mycolumn \\
2879
+ '"\\n".join(textwrap.wrap(value, 10))' \\
2880
+ --import=textwrap
2877
2881
 
2878
2882
  "value" is a variable with the column value to be converted.
2879
2883
 
@@ -2892,7 +2896,7 @@ def _generate_convert_help():
2892
2896
  for name in recipe_names:
2893
2897
  fn = getattr(recipes, name)
2894
2898
  help += "\n\nr.{}{}\n\n\b{}".format(
2895
- name, str(inspect.signature(fn)), fn.__doc__.rstrip()
2899
+ name, str(inspect.signature(fn)), textwrap.dedent(fn.__doc__.rstrip())
2896
2900
  )
2897
2901
  help += "\n\n"
2898
2902
  help += textwrap.dedent(
@@ -2900,8 +2904,8 @@ def _generate_convert_help():
2900
2904
  You can use these recipes like so:
2901
2905
 
2902
2906
  \b
2903
- sqlite-utils convert my.db mytable mycolumn \\
2904
- 'r.jsonsplit(value, delimiter=":")'
2907
+ sqlite-utils convert my.db mytable mycolumn \\
2908
+ 'r.jsonsplit(value, delimiter=":")'
2905
2909
  """
2906
2910
  ).strip()
2907
2911
  return help
sqlite_utils/db.py CHANGED
@@ -206,21 +206,25 @@ COLUMN_TYPE_MAPPING = {
206
206
  }
207
207
  # If numpy is available, add more types
208
208
  if np:
209
- COLUMN_TYPE_MAPPING.update(
210
- {
211
- np.int8: "INTEGER",
212
- np.int16: "INTEGER",
213
- np.int32: "INTEGER",
214
- np.int64: "INTEGER",
215
- np.uint8: "INTEGER",
216
- np.uint16: "INTEGER",
217
- np.uint32: "INTEGER",
218
- np.uint64: "INTEGER",
219
- np.float16: "FLOAT",
220
- np.float32: "FLOAT",
221
- np.float64: "FLOAT",
222
- }
223
- )
209
+ try:
210
+ COLUMN_TYPE_MAPPING.update(
211
+ {
212
+ np.int8: "INTEGER",
213
+ np.int16: "INTEGER",
214
+ np.int32: "INTEGER",
215
+ np.int64: "INTEGER",
216
+ np.uint8: "INTEGER",
217
+ np.uint16: "INTEGER",
218
+ np.uint32: "INTEGER",
219
+ np.uint64: "INTEGER",
220
+ np.float16: "FLOAT",
221
+ np.float32: "FLOAT",
222
+ np.float64: "FLOAT",
223
+ }
224
+ )
225
+ except AttributeError:
226
+ # https://github.com/simonw/sqlite-utils/issues/632
227
+ pass
224
228
 
225
229
  # If pandas is available, add more types
226
230
  if pd:
@@ -457,8 +461,7 @@ class Database:
457
461
  fn_name, arity, fn, **dict(kwargs, deterministic=True)
458
462
  )
459
463
  registered = True
460
- except (sqlite3.NotSupportedError, TypeError):
461
- # TypeError is Python 3.7 "function takes at most 3 arguments"
464
+ except sqlite3.NotSupportedError:
462
465
  pass
463
466
  if not registered:
464
467
  self.conn.create_function(fn_name, arity, fn, **kwargs)
@@ -930,9 +933,9 @@ class Database:
930
933
  " [{column_name}] {column_type}{column_extras}".format(
931
934
  column_name=column_name,
932
935
  column_type=COLUMN_TYPE_MAPPING[column_type],
933
- column_extras=(" " + " ".join(column_extras))
934
- if column_extras
935
- else "",
936
+ column_extras=(
937
+ (" " + " ".join(column_extras)) if column_extras else ""
938
+ ),
936
939
  )
937
940
  )
938
941
  extra_pk = ""
@@ -1481,9 +1484,11 @@ class Table(Queryable):
1481
1484
  def __repr__(self) -> str:
1482
1485
  return "<Table {}{}>".format(
1483
1486
  self.name,
1484
- " (does not exist yet)"
1485
- if not self.exists()
1486
- else " ({})".format(", ".join(c.name for c in self.columns)),
1487
+ (
1488
+ " (does not exist yet)"
1489
+ if not self.exists()
1490
+ else " ({})".format(", ".join(c.name for c in self.columns))
1491
+ ),
1487
1492
  )
1488
1493
 
1489
1494
  @property
@@ -2940,9 +2945,11 @@ class Table(Queryable):
2940
2945
  value = jsonify_if_needed(
2941
2946
  record.get(
2942
2947
  key,
2943
- None
2944
- if key != hash_id
2945
- else hash_record(record, hash_id_columns),
2948
+ (
2949
+ None
2950
+ if key != hash_id
2951
+ else hash_record(record, hash_id_columns)
2952
+ ),
2946
2953
  )
2947
2954
  )
2948
2955
  if key in extracts:
sqlite_utils/utils.py CHANGED
@@ -304,10 +304,7 @@ def rows_from_file(
304
304
  rows = rows_from_file(
305
305
  fp, format=Format.CSV, dialect=csv.excel_tab, encoding=encoding
306
306
  )[0]
307
- return (
308
- _extra_key_strategy(rows, ignore_extras, extras_key),
309
- Format.TSV,
310
- )
307
+ return _extra_key_strategy(rows, ignore_extras, extras_key), Format.TSV
311
308
  elif format is None:
312
309
  # Detect the format, then call this recursively
313
310
  buffered = io.BufferedReader(cast(io.RawIOBase, fp), buffer_size=4096)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlite-utils
3
- Version: 3.36
3
+ Version: 3.37
4
4
  Summary: CLI tool and Python library for manipulating SQLite databases
5
5
  Home-page: https://github.com/simonw/sqlite-utils
6
6
  Author: Simon Willison
@@ -16,13 +16,13 @@ Classifier: Intended Audience :: Science/Research
16
16
  Classifier: Intended Audience :: End Users/Desktop
17
17
  Classifier: Topic :: Database
18
18
  Classifier: License :: OSI Approved :: Apache Software License
19
- Classifier: Programming Language :: Python :: 3.7
20
19
  Classifier: Programming Language :: Python :: 3.8
21
20
  Classifier: Programming Language :: Python :: 3.9
22
21
  Classifier: Programming Language :: Python :: 3.10
23
22
  Classifier: Programming Language :: Python :: 3.11
24
23
  Classifier: Programming Language :: Python :: 3.12
25
- Requires-Python: >=3.7
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Requires-Python: >=3.8
26
26
  Description-Content-Type: text/markdown
27
27
  License-File: LICENSE
28
28
  Requires-Dist: sqlite-fts4
@@ -49,7 +49,7 @@ Requires-Dist: types-pluggy ; extra == 'mypy'
49
49
  Requires-Dist: data-science-types ; extra == 'mypy'
50
50
  Provides-Extra: test
51
51
  Requires-Dist: pytest ; extra == 'test'
52
- Requires-Dist: black ; extra == 'test'
52
+ Requires-Dist: black >=24.1.1 ; extra == 'test'
53
53
  Requires-Dist: hypothesis ; extra == 'test'
54
54
  Requires-Dist: cogapp ; extra == 'test'
55
55
  Provides-Extra: tui
@@ -0,0 +1,15 @@
1
+ sqlite_utils/__init__.py,sha256=eyDK-5KOo-ARS3i0JcuxGiJmk5T-58Z1p_bhACbBrGc,201
2
+ sqlite_utils/__main__.py,sha256=8hDtWlaFZK24KhfNq_ZKgtXqYHsDQDetukOCMlsbW0Q,59
3
+ sqlite_utils/cli.py,sha256=sBAF9cxvJ108OBWspzQoz1dvN_fLBhlJSaAbmWbYlHc,89771
4
+ sqlite_utils/db.py,sha256=na--6HxI5db7_LaZwwY2nAusVJaZ2AlC-DYTNHwY1A8,146365
5
+ sqlite_utils/hookspecs.py,sha256=NFA0BFZ8WUhnI_NRz4oFVDcomQYlguuAgUCBKAN792o,395
6
+ sqlite_utils/plugins.py,sha256=V5nXD4r0o1wSbIHHOAiUBBV66ZOfKVnywKfZzCUqdsA,771
7
+ sqlite_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ sqlite_utils/recipes.py,sha256=_npzti0nPV6XxvMj69Ca4QF-pXwZZQp_f_VY3i7pQDs,1687
9
+ sqlite_utils/utils.py,sha256=PRqoITtqmaUI7xzyB2exaTPg6oXbTMhGDzld7srNOG4,17099
10
+ sqlite_utils-3.37.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
+ sqlite_utils-3.37.dist-info/METADATA,sha256=DdfINwbgTnsxBvYUgSaz0pePxd9PqJCcyfn107VNkJA,7561
12
+ sqlite_utils-3.37.dist-info/WHEEL,sha256=-oYQCr74JF3a37z2nRlQays_SX2MqOANoqVjBBAP2yE,91
13
+ sqlite_utils-3.37.dist-info/entry_points.txt,sha256=33jbVHROlRBNhoXoSI-QI2rN6JDkJIkKIX7P5sNIWdY,54
14
+ sqlite_utils-3.37.dist-info/top_level.txt,sha256=_dw_n5BWKUEtCYB2DTlmPMQfdRZSuFsmRQe2ZhNYwnQ,13
15
+ sqlite_utils-3.37.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (71.0.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,15 +0,0 @@
1
- sqlite_utils/__init__.py,sha256=eyDK-5KOo-ARS3i0JcuxGiJmk5T-58Z1p_bhACbBrGc,201
2
- sqlite_utils/__main__.py,sha256=8hDtWlaFZK24KhfNq_ZKgtXqYHsDQDetukOCMlsbW0Q,59
3
- sqlite_utils/cli.py,sha256=C69OYAbz5Tu_PK8-Rtkuu8UhpJZpCztLkiG2orkNhUU,89593
4
- sqlite_utils/db.py,sha256=rXIeGnA3TM6QvjpvQE5p4oHV79dKfa7hch2eJ1fJTHA,146180
5
- sqlite_utils/hookspecs.py,sha256=NFA0BFZ8WUhnI_NRz4oFVDcomQYlguuAgUCBKAN792o,395
6
- sqlite_utils/plugins.py,sha256=V5nXD4r0o1wSbIHHOAiUBBV66ZOfKVnywKfZzCUqdsA,771
7
- sqlite_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- sqlite_utils/recipes.py,sha256=_npzti0nPV6XxvMj69Ca4QF-pXwZZQp_f_VY3i7pQDs,1687
9
- sqlite_utils/utils.py,sha256=jvlsGQ5F_Z7-bAiP7gw4hmov_58PrVMvY_5UZ3nXfAg,17136
10
- sqlite_utils-3.36.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
- sqlite_utils-3.36.dist-info/METADATA,sha256=kcoJW64Z6uM0yyzjyaKrdxM21ev9EEbHmrMORB5m3TA,7551
12
- sqlite_utils-3.36.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
13
- sqlite_utils-3.36.dist-info/entry_points.txt,sha256=33jbVHROlRBNhoXoSI-QI2rN6JDkJIkKIX7P5sNIWdY,54
14
- sqlite_utils-3.36.dist-info/top_level.txt,sha256=_dw_n5BWKUEtCYB2DTlmPMQfdRZSuFsmRQe2ZhNYwnQ,13
15
- sqlite_utils-3.36.dist-info/RECORD,,