Skip to content

Commit

Permalink
カラム名 Typo の吸収を実装
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatsu47 committed Nov 20, 2021
1 parent d9542ed commit f7f2cce
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
7 changes: 6 additions & 1 deletion amplify/backend/function/backupSymbolInfo/src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ def operation_put(items):
try:
with table.batch_writer() as batch:
for item in items:
# カラム名 Typo の吸収
if 'longitude' in item:
longitude = item['longitude']
else:
longitude = item['longtitude']
baseItem={
'backupTitle': item['backupTitle'],
'id': item['id'],
'title': item['title'],
'describe': item['describe'],
'dateTime': item['dateTime'],
'latitude': item['latitude'],
'longtitude': item['longtitude'],
'longitude': longitude,
'prefecture': item['prefecture'],
'municipalities': item['municipalities']
}
Expand Down
8 changes: 6 additions & 2 deletions lib/aws_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Future<int?> backupSymbolInfos(AmplifyClass amplify, String backupTitle) async {
', "describe": ${jsonEncode(describe)}'
', "dateTime": ${jsonEncode(dateTime)}'
', "latitude": ${jsonEncode(latitude)}'
', "longtitude": ${jsonEncode(longitude)}'
', "longitude": ${jsonEncode(longitude)}'
', "prefecture": ${jsonEncode(prefecture)}'
', "municipalities": ${jsonEncode(municipalities)}'
'}, ';
Expand Down Expand Up @@ -269,8 +269,12 @@ Future<List<SymbolInfoWithLatLng>> _fetchBackupSymbolInfos(
PrefMuni(
item['prefecture'] as String, item['municipalities'] as String),
);
// カラム名 Typo の吸収
final num longitude = (item.containsKey('longitude')
? item['longitude'] as num
: item['longtitude'] as num);
final LatLng latLng =
LatLng(item['latitude'] as double, item['longtitude'] as double);
LatLng((item['latitude'] as num).toDouble(), longitude.toDouble());
final SymbolInfoWithLatLng infoLatLng =
SymbolInfoWithLatLng(item['id'] as int, info, latLng);
resultList.add(infoLatLng);
Expand Down
38 changes: 32 additions & 6 deletions lib/db_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Future<void> createDatabase() async {
' describe TEXT NOT NULL,'
' date_time INTEGER NOT NULL,'
' latitude REAL NOT NULL,'
' longtitude REAL NOT NULL,'
' longitude REAL NOT NULL,'
' prefecture TEXT NOT NULL DEFAULT "",'
' municipalities TEXT NOT NULL DEFAULT ""'
')';
Expand All @@ -27,7 +27,7 @@ Future<void> createDatabase() async {
' cloud_path TEXT NOT NULL'
')';
// DB テーブル作成
_database = await openDatabase('maptool.db', version: 6,
_database = await openDatabase('maptool.db', version: 7,
onCreate: (db, version) async {
await db.execute(
createSymbolInfo,
Expand All @@ -51,6 +51,32 @@ Future<void> createDatabase() async {
// ignore: avoid_print
print('alter table add column (symbol_info)');
}
if (oldVersion < 7) {
// await db.execute(
// 'BEGIN TRANSACTION',
// );
await db.execute(
'ALTER TABLE symbol_info RENAME TO symbol_info_temp',
);
await db.execute(
createSymbolInfo,
);
await db.execute(
'INSERT INTO '
' symbol_info(id, title, describe, date_time, latitude, longitude, prefecture, municipalities) '
'SELECT'
' id, title, describe, date_time, latitude, longtitude, prefecture, municipalities '
'FROM symbol_info_temp',
);
await db.execute(
'DROP TABLE symbol_info_temp',
);
// await db.execute(
// 'COMMIT',
// );
// ignore: avoid_print
print('alter table rename column (symbol_info)');
}
});
}

Expand All @@ -75,7 +101,7 @@ Future<List<SymbolInfoWithLatLng>> fetchRecords() async {
'describe',
'date_time',
'latitude',
'longtitude',
'longitude',
'prefecture',
'municipalities',
],
Expand All @@ -88,7 +114,7 @@ Future<List<SymbolInfoWithLatLng>> fetchRecords() async {
map['describe'],
DateTime.fromMillisecondsSinceEpoch(map['date_time'], isUtc: false),
PrefMuni(map['prefecture'], map['municipalities']));
final LatLng latLng = LatLng(map['latitude'], map['longtitude']);
final LatLng latLng = LatLng(map['latitude'], map['longitude']);
final SymbolInfoWithLatLng symbolInfoWithLatLng =
SymbolInfoWithLatLng(map['id'], symbolInfo, latLng);
symbolInfoWithLatLngs.add(symbolInfoWithLatLng);
Expand Down Expand Up @@ -124,7 +150,7 @@ Future<int> addRecord(SymbolInfoWithLatLng symbolInfoWithLatLng) async {
'date_time':
symbolInfoWithLatLng.symbolInfo.dateTime.millisecondsSinceEpoch,
'latitude': symbolInfoWithLatLng.latLng.latitude,
'longtitude': symbolInfoWithLatLng.latLng.longitude,
'longitude': symbolInfoWithLatLng.latLng.longitude,
'prefecture': symbolInfoWithLatLng.symbolInfo.prefMuni.prefecture,
'municipalities': symbolInfoWithLatLng.symbolInfo.prefMuni.municipalities
},
Expand All @@ -142,7 +168,7 @@ Future<int> addRecordWithId(SymbolInfoWithLatLng symbolInfoWithLatLng) async {
'date_time':
symbolInfoWithLatLng.symbolInfo.dateTime.millisecondsSinceEpoch,
'latitude': symbolInfoWithLatLng.latLng.latitude,
'longtitude': symbolInfoWithLatLng.latLng.longitude,
'longitude': symbolInfoWithLatLng.latLng.longitude,
'prefecture': symbolInfoWithLatLng.symbolInfo.prefMuni.prefecture,
'municipalities': symbolInfoWithLatLng.symbolInfo.prefMuni.municipalities
},
Expand Down
3 changes: 2 additions & 1 deletion lib/supabase_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Future<List<SpotData>> searchNearSpot(
item['category_name'] as String,
item['title'] as String,
item['describe'] as String,
LatLng(item['latitude'] as double, item['longitude'] as double),
LatLng((item['latitude'] as num).toDouble(),
(item['longitude'] as num).toDouble()),
PrefMuni(item['prefecture'] as String, item['municipality'] as String));
resultList.add(spotData);
}
Expand Down

0 comments on commit f7f2cce

Please sign in to comment.