-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:db/query.dart'; | ||
import 'package:types/types.dart'; | ||
|
||
/// Lookup a shipyard listing by WaypointSymbol. | ||
Query shipyardListingByWaypointSymbolQuery(WaypointSymbol symbol) => Query( | ||
'SELECT * FROM shipyard_listing WHERE symbol = @symbol', | ||
parameters: {'symbol': symbol.waypoint}, | ||
); | ||
|
||
/// Query all shipyard listings. | ||
Query allShipyardListingsQuery() => | ||
const Query('SELECT * FROM shipyard_listing'); | ||
|
||
/// Query to upsert a shipyard listing. | ||
Query upsertShipyardListingQuery(ShipyardListing listing) => Query( | ||
''' | ||
INSERT INTO shipyard_listing (symbol, ships) | ||
VALUES (@symbol, @types) | ||
ON CONFLICT (symbol) DO UPDATE SET | ||
types = @types | ||
''', | ||
parameters: shipyardListingToColumnMap(listing), | ||
); | ||
|
||
/// Build a column map from a shipyard listing. | ||
Map<String, dynamic> shipyardListingToColumnMap( | ||
ShipyardListing shipyardListing, | ||
) => | ||
{ | ||
'symbol': shipyardListing.waypointSymbol.toJson(), | ||
'types': shipyardListing.shipTypes.map((e) => e.toString()).toList(), | ||
}; | ||
|
||
/// Build a shipyard listing from a column map. | ||
ShipyardListing shipyardListingFromColumnMap(Map<String, dynamic> values) { | ||
return ShipyardListing( | ||
waypointSymbol: WaypointSymbol.fromString(values['symbol'] as String), | ||
shipTypes: (values['ships'] as List<dynamic>) | ||
.cast<String>() | ||
.map((e) => ShipType.fromJson(e)!) | ||
.toSet(), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Describes an shipyard. | ||
CREATE TABLE IF NOT EXISTS "shipyard_listing_" ( | ||
-- The symbol of the shipyard. | ||
"symbol" text NOT NULL PRIMARY KEY, | ||
-- Types of ships available at the shipyard. | ||
"types" text [] NOT NULL, | ||
); |