Skip to content

Commit

Permalink
Improve typescript support for filtered results for basic gtfs queries (
Browse files Browse the repository at this point in the history
  • Loading branch information
b-e-b-o-o authored Nov 5, 2024
1 parent 90a24f8 commit 970f178
Show file tree
Hide file tree
Showing 31 changed files with 156 additions and 150 deletions.
10 changes: 5 additions & 5 deletions src/lib/gtfs/agencies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
Agency,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all agencies that match the query parameters.
*/
export function getAgencies(
export function getAgencies<Fields extends keyof Agency>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getAgencies(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as Agency[];
.all() as QueryResult<Agency, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/areas.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
Area,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all areas that match the query parameters.
*/
export function getAreas(
export function getAreas<Fields extends keyof Area>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getAreas(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as Area[];
.all() as QueryResult<Area, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/attributions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
Attribution,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all attributions that match the query parameters.
*/
export function getAttributions(
export function getAttributions<Fields extends keyof Attribution>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getAttributions(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as Attribution[];
.all() as QueryResult<Attribution, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/booking-rules.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
BookingRule,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all booking rules that match the query parameters.
*/
export function getBookingRules(
export function getBookingRules<Fields extends keyof BookingRule>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getBookingRules(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as BookingRule[];
.all() as QueryResult<BookingRule, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/calendar-dates.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
CalendarDate,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of calendarDates that match the query parameters.
*/
export function getCalendarDates(
export function getCalendarDates<Fields extends keyof CalendarDate>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getCalendarDates(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as CalendarDate[];
.all() as QueryResult<CalendarDate, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/calendars.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
Calendar,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -16,9 +16,9 @@ import {
/*
* Returns an array of calendars that match the query parameters.
*/
export function getCalendars(
export function getCalendars<Fields extends keyof Calendar>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -32,7 +32,7 @@ export function getCalendars(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as Calendar[];
.all() as QueryResult<Calendar, Fields>[];
}

/*
Expand Down
10 changes: 5 additions & 5 deletions src/lib/gtfs/fare-attributes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
FareAttribute,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all fare attributes that match the query parameters.
*/
export function getFareAttributes(
export function getFareAttributes<Fields extends keyof FareAttribute>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getFareAttributes(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as FareAttribute[];
.all() as QueryResult<FareAttribute, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/fare-leg-rules.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
FareLegRule,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all fare leg rules that match the query parameters.
*/
export function getFareLegRules(
export function getFareLegRules<Fields extends keyof FareLegRule>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getFareLegRules(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as FareLegRule[];
.all() as QueryResult<FareLegRule, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/fare-media.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
FareMedia,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all fare media that match the query parameters.
*/
export function getFareMedia(
export function getFareMedia<Fields extends keyof FareMedia>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getFareMedia(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as FareMedia[];
.all() as QueryResult<FareMedia, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/fare-products.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
FareProduct,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all fare products that match the query parameters.
*/
export function getFareProducts(
export function getFareProducts<Fields extends keyof FareProduct>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getFareProducts(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as FareProduct[];
.all() as QueryResult<FareProduct, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/fare-rules.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
FareRule,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all fare rules that match the query parameters.
*/
export function getFareRules(
export function getFareRules<Fields extends keyof FareRule>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getFareRules(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as FareRule[];
.all() as QueryResult<FareRule, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/fare-transfer-rules.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
FareTransferRule,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all fare transfer rules that match the query parameters.
*/
export function getFareTransferRules(
export function getFareTransferRules<Fields extends keyof FareTransferRule>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getFareTransferRules(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as FareTransferRule[];
.all() as QueryResult<FareTransferRule, Fields>[];
}
10 changes: 5 additions & 5 deletions src/lib/gtfs/feed-info.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
FeedInfo,
QueryOptions,
SqlOrderBy,
SqlSelect,
QueryResult,
SqlWhere,
} from '../../types/global_interfaces.ts';
import { openDb } from '../db.ts';
Expand All @@ -15,9 +15,9 @@ import {
/*
* Returns an array of all feed info that match the query parameters.
*/
export function getFeedInfo(
export function getFeedInfo<Fields extends keyof FeedInfo>(
query: SqlWhere = {},
fields: SqlSelect = [],
fields: Fields[] = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
) {
Expand All @@ -31,5 +31,5 @@ export function getFeedInfo(
.prepare(
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
)
.all() as FeedInfo[];
.all() as QueryResult<FeedInfo, Fields>[];
}
Loading

0 comments on commit 970f178

Please sign in to comment.