Skip to content

Commit

Permalink
Update uszipcodes for SQLAlchemy 1.4 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed Jun 30, 2023
1 parent b0edd52 commit 79c557a
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ For a production environment:
poetry install --only main,pg
```

_Important note_: The `uszipcodes` dependency is pinned because we also rely on a [repo-local](./data/simple_db.sqlite)
copy of the [release-specific version](https://github.com/MacHu-GWU/uszipcode-project/releases) of the
associated "simple" (versus "comprehensive") database (e.g.,
[this file](https://github.com/MacHu-GWU/uszipcode-project/releases/download/1.0.1.db/simple_db.sqlite)
for release 1.0.1). When updating this dependency, it is important to obtain the corresponding database and store it as
`./data/simple_db.sqlite`, since that is where the code expects to find it.

### Initialize the database

To initialize a fresh database (ie no tables yet created) use the following script:
Expand Down
Binary file modified data/simple_db.sqlite
Binary file not shown.
16 changes: 11 additions & 5 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@
)
from sqlalchemy import exc as sa_exc
from sqlalchemy import func
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import IntegrityError, MultipleResultsFound, NoResultFound
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import aliased, backref, relationship, sessionmaker, validates
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
from sqlalchemy.orm import (
aliased,
backref,
declarative_base,
relationship,
sessionmaker,
validates,
)
from sqlalchemy.orm.session import Session
from sqlalchemy.sql import compiler
from sqlalchemy.sql.expression import (
Expand Down Expand Up @@ -1644,7 +1649,7 @@ def lookup_one_through_external_source(self, name):
return None

search = uszipcode.SearchEngine(
db_file_dir=Configuration.DATADIR, simple_zipcode=True
db_file_path=f"{Configuration.DATADIR}/simple_db.sqlite"
)
state = self.abbreviated_name
uszipcode_matches = []
Expand All @@ -1654,6 +1659,7 @@ def lookup_one_through_external_source(self, name):
):
# The given name is an exact match for one of the
# cities. Let's look up every ZIP code for that city.
# `returns=None` here means to not limit the number of results.
uszipcode_matches = search.by_city_and_state(name, state, returns=None)

# Look up a Place object for each ZIP code and return the
Expand Down
Loading

0 comments on commit 79c557a

Please sign in to comment.