added logic to add a device.geography row
parent
a25aa7f665
commit
877701faf9
|
@ -15,3 +15,14 @@ class GeographyRepository(RepositoryBase):
|
|||
db_response = self.cursor.select_all(db_request)
|
||||
|
||||
return [Geography(**row) for row in db_response]
|
||||
|
||||
def add(self, geography):
|
||||
db_request_args = dict(account_id=self.account_id)
|
||||
db_request_args.update(geography)
|
||||
db_request = self._build_db_request(
|
||||
sql_file_name='add_geography.sql',
|
||||
args=db_request_args
|
||||
)
|
||||
db_result = self.cursor.insert_returning(db_request)
|
||||
|
||||
return db_result['id']
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
INSERT INTO
|
||||
device.geography (account_id, country_id, region_id, city_id, timezone_id)
|
||||
VALUES
|
||||
(
|
||||
%(account_id)s,
|
||||
(SELECT id FROM geography.country WHERE name = %(country)s),
|
||||
(
|
||||
SELECT
|
||||
r.id
|
||||
FROM
|
||||
geography.region r
|
||||
INNER JOIN geography.country c ON c.id = r.country_id
|
||||
WHERE
|
||||
r.name = %(region)s
|
||||
AND c.name = %(country)s
|
||||
),
|
||||
(
|
||||
SELECT
|
||||
c.id
|
||||
FROM
|
||||
geography.city c
|
||||
INNER JOIN geography.region r ON r.id = c.region_id
|
||||
|
||||
WHERE
|
||||
c.name = %(city)s
|
||||
AND r.name = %(region)s
|
||||
),
|
||||
(SELECT id FROM geography.timezone WHERE name = %(timezone)s)
|
||||
)
|
||||
RETURNING
|
||||
id
|
Loading…
Reference in New Issue