Skip to content

Commit 22a5611

Browse files
committed
Always use id as pk, refs #4
1 parent 8fa7277 commit 22a5611

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

shapefile_to_sqlite/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
nargs=-1,
2121
)
2222
@click.option("--table", help="Table to load data into")
23-
@click.option("--pk", help="Column to use as a primary key")
2423
@click.option("--alter", is_flag=True, help="Add any missing columns")
2524
@click.option("--spatialite", is_flag=True, help="Use SpatiaLite")
2625
@click.option(
2726
"--spatialite_mod",
2827
help="Path to SpatiaLite module, for if --spatialite cannot find it automatically",
2928
)
30-
def cli(db_path, table, shapefile, pk, alter, spatialite, spatialite_mod):
29+
def cli(db_path, table, shapefile, alter, spatialite, spatialite_mod):
3130
"Load shapefiles into a SQLite (optionally SpatiaLite) database"
3231
for filepath in shapefile:
3332
openpath = filepath
@@ -39,7 +38,6 @@ def cli(db_path, table, shapefile, pk, alter, spatialite, spatialite_mod):
3938
db_path,
4039
table=table or Path(filepath).stem,
4140
features=bar,
42-
pk=pk,
4341
alter=alter,
4442
spatialite=spatialite,
4543
spatialite_mod=spatialite_mod,

shapefile_to_sqlite/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def import_features(
2626
db_path,
2727
table,
2828
features,
29-
pk=None,
3029
alter=False,
3130
spatialite=False,
3231
spatialite_mod=None,
@@ -63,14 +62,11 @@ def yield_features():
6362
features_iter = itertools.chain(first_100, features_iter)
6463
column_types = sqlite_utils.suggest_column_types(first_100)
6564
column_types.pop("geometry")
66-
db[table].create(column_types, pk=pk)
65+
db[table].create(column_types, pk="id")
6766
ensure_table_has_geometry(db, table)
6867
conversions = {"geometry": "GeomFromText(?, 4326)"}
6968

70-
if pk:
71-
db[table].upsert_all(features_iter, conversions=conversions, pk=pk, alter=alter)
72-
else:
73-
db[table].insert_all(features_iter, conversions=conversions, alter=alter)
69+
db[table].insert_all(features_iter, conversions=conversions, alter=alter, pk="id", replace=True)
7470
return db[table]
7571

7672

tests/test_shapefile_to_sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ def test_import_features_spatialite(tmpdir):
7474
},
7575
]
7676

77-
assert ["rowid"] == db["features"].pks
77+
assert ["id"] == db["features"].pks
7878
assert expected_rows == rows

0 commit comments

Comments
 (0)