Public Access
feat(db): add inserts for all tables
This commit is contained in:
+49
-15
@@ -85,6 +85,7 @@ class Route {
|
||||
json["LegList"]["Leg"][-1]["Origin"]["time"] -
|
||||
json["LegList"]["Leg"][0]["Origin"]["time"],
|
||||
);
|
||||
newRoute.dbInsertRoute();
|
||||
return newRoute;
|
||||
}
|
||||
|
||||
@@ -110,20 +111,23 @@ class Route {
|
||||
""");
|
||||
}
|
||||
|
||||
void writeRouteToTable() async {
|
||||
void dbInsertRoute() async {
|
||||
Database database = DbHelper.db;
|
||||
database.insert(
|
||||
id = await database.insert(
|
||||
"route",
|
||||
toMapRoute(),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
}
|
||||
|
||||
void writeRouteSegmentsToTable() async {
|
||||
void dbInsertRouteSegments() async {
|
||||
Database database = DbHelper.db;
|
||||
var routeSegments = toMapRouteSegments();
|
||||
for (var i = 0; i < routeSegments.length; i++) {
|
||||
database.insert("routesegments", routeSegments[i]);
|
||||
database.insert(
|
||||
"routesegments",
|
||||
routeSegments[i],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,6 +143,7 @@ class Segment {
|
||||
Vehicle vehicle;
|
||||
|
||||
Segment({
|
||||
this.id, // might throw errors - needs testing, I guess
|
||||
required this.startPoint,
|
||||
required this.endPoint,
|
||||
required this.startTime,
|
||||
@@ -165,7 +170,7 @@ class Segment {
|
||||
endTime: json["Destination"]["rtTime"],
|
||||
vehicle: Vehicle.fromJson(json["Product"]),
|
||||
);
|
||||
tmp.writeNewToTable(); // TODO: we need to write to db and get the ID!!!!!!!
|
||||
tmp.dbInsert();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -187,10 +192,9 @@ class Segment {
|
||||
""");
|
||||
}
|
||||
|
||||
Future<int> writeNewToTable() async {
|
||||
void dbInsert() async {
|
||||
Database database = DbHelper.db;
|
||||
int id = await database.insert(tableName, toMap());
|
||||
return id;
|
||||
id = await database.insert(tableName, toMap());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,6 +253,19 @@ class Station {
|
||||
);
|
||||
""");
|
||||
}
|
||||
|
||||
void dbInsertStation() async {
|
||||
Database database = DbHelper.db;
|
||||
database.insert(tableName, toMap());
|
||||
}
|
||||
|
||||
void dbInsertStationLines() async {
|
||||
Database database = DbHelper.db;
|
||||
var stationLines = toMapLines();
|
||||
for (var i = 0; i < stationLines.length; i++) {
|
||||
database.insert("stationlines", stationLines[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Vehicle {
|
||||
@@ -265,7 +282,7 @@ class Vehicle {
|
||||
Map<String, Object?> toMap() {
|
||||
return {
|
||||
"id": id,
|
||||
"line": line.id,
|
||||
"line": line.LineId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -286,12 +303,17 @@ class Vehicle {
|
||||
);
|
||||
""");
|
||||
}
|
||||
|
||||
void dbInsert() async {
|
||||
Database database = DbHelper.db;
|
||||
database.insert(tableName, toMap());
|
||||
}
|
||||
}
|
||||
|
||||
class Line {
|
||||
static const String tableName = "line";
|
||||
|
||||
String id;
|
||||
String LineId;
|
||||
Station? destination;
|
||||
Station? direction;
|
||||
VehicleType mode;
|
||||
@@ -300,7 +322,7 @@ class Line {
|
||||
Color? bgColor;
|
||||
|
||||
Line({
|
||||
required this.id,
|
||||
required this.LineId,
|
||||
required this.name,
|
||||
required this.mode,
|
||||
this.fgColor,
|
||||
@@ -309,7 +331,7 @@ class Line {
|
||||
|
||||
Map<String, Object?> toMap() {
|
||||
return {
|
||||
"lineid": id,
|
||||
"lineid": LineId,
|
||||
"destination": destination,
|
||||
"direction": direction,
|
||||
"mode": mode,
|
||||
@@ -328,7 +350,7 @@ class Line {
|
||||
];
|
||||
|
||||
factory Line.fromJson(Map<String, dynamic> json) => Line(
|
||||
id: json["lineId"],
|
||||
LineId: json["lineId"],
|
||||
name: json["name"],
|
||||
mode: _vehicleTypeAsCatCode[int.parse(json["catCode"])],
|
||||
fgColor:
|
||||
@@ -351,17 +373,24 @@ class Line {
|
||||
);
|
||||
""");
|
||||
}
|
||||
|
||||
void dbInsert() async {
|
||||
Database database = DbHelper.db;
|
||||
database.insert(tableName, toMap());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add fromJson
|
||||
class Departure {
|
||||
static const String tableName = "departure";
|
||||
|
||||
String? id;
|
||||
int? id;
|
||||
Vehicle vehicle;
|
||||
Station station;
|
||||
DateTime departureTime;
|
||||
|
||||
Departure({
|
||||
this.id,
|
||||
required this.vehicle,
|
||||
required this.station,
|
||||
required this.departureTime,
|
||||
@@ -390,6 +419,11 @@ class Departure {
|
||||
);
|
||||
""");
|
||||
}
|
||||
|
||||
void dbInsert() async {
|
||||
Database database = DbHelper.db;
|
||||
id = await database.insert(tableName, toMap());
|
||||
}
|
||||
}
|
||||
|
||||
class Color {
|
||||
@@ -417,4 +451,4 @@ enum VehicleType {
|
||||
subway,
|
||||
regionalTrain,
|
||||
PLACEHOLDER,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user