Skip to content

Commit 1834eea

Browse files
committed
add methods without writing them all out
1 parent 7ba49c3 commit 1834eea

2 files changed

Lines changed: 27 additions & 243 deletions

File tree

src/models/db/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as candidate from "./candidate";
2+
import * as elected from "./elected";
3+
import * as nomination from "./nomination";
4+
import * as position from "./position";
5+
import * as race from "./race";
6+
import * as seat from "./seat";
7+
import * as user from "./user";
8+
import * as pref from "./vote-preference";
9+
import * as vote from "./vote";
10+
11+
export {
12+
candidate,
13+
elected,
14+
nomination,
15+
position,
16+
race,
17+
seat,
18+
user,
19+
pref,
20+
vote
21+
}

src/models/index.ts

Lines changed: 6 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@ import { DurableObject } from "cloudflare:workers";
22
import { drizzle, DrizzleSqliteDODatabase } from "drizzle-orm/durable-sqlite";
33
import { migrate } from "drizzle-orm/durable-sqlite/migrator";
44
import migrations from "../../drizzle/migrations";
5-
import { getAllPositions, insertPosition, updatePosition, getPosition, deletePosition } from "./db/position";
6-
import { getAllCandidates, getAllCandidatesByPosition, insertCandidate, updateCandidate, getCandidate, deleteCandidate } from "./db/candidate";
7-
import { getAllNominations, getNominationsForPosition, getNominationsForCandidate, insertNomination, deleteNomination } from "./db/nomination";
8-
import { getRace, getAllRaces, insertRace, updateRace, deleteRace, getCurrentRace, saveElectedForRace } from "./db/race";
9-
import { getSeat, insertSeat, deleteSeat, getSeatByCode } from "./db/seat";
10-
import { countUsers, getAllUsers, insertUser, updateUser, getUser, getUserByEmail, deleteUser } from "./db/user";
11-
import { getAllVotePreferences, insertVotePreference, updateVotePreference, getVotePreference, deleteVotePreference, getVotePreferencesForVote, getVotePreferenceForCandidate } from "./db/vote-preference";
12-
import { countVotesForRace, getAllVotesForRace, insertVote, updateVote, getAllVotesByUser, getVoteByUserAndRace, deleteVote, getVoteAggregateForRace, getVoteCollatedForRace } from "./db/vote";
135
import { seedMasterSeat, devSeeds, seedPositions, seedRaces } from "./seed";
146
import * as schema from "./schema";
157
import { eq } from "drizzle-orm";
16-
import { deleteElectedForRace, getAllElected, getElectedForRace, insertElected } from "./db/elected";
8+
9+
import * as dbMod from "./db";
1710

1811
export interface DOEnv {
1912
ENVIRONMENT: "dev" | "prod";
@@ -109,239 +102,9 @@ export class VotingObject extends DurableObject {
109102
connection[1].send(message);
110103
}
111104
}
105+
}
112106

113-
// Positions
114-
getAllPositions(...args: Parameters<typeof getAllPositions>) {
115-
return getAllPositions.call(this, ...args);
116-
}
117-
118-
getPosition(...args: Parameters<typeof getPosition>) {
119-
return getPosition.call(this, ...args);
120-
}
121-
122-
insertPosition(...args: Parameters<typeof insertPosition>) {
123-
return insertPosition.call(this, ...args);
124-
}
125-
126-
updatePosition(...args: Parameters<typeof updatePosition>) {
127-
return updatePosition.call(this, ...args);
128-
}
129-
130-
deletePosition(...args: Parameters<typeof deletePosition>) {
131-
return deletePosition.call(this, ...args);
132-
}
133-
134-
// Candidates
135-
getAllCandidates(...args: Parameters<typeof getAllCandidates>) {
136-
return getAllCandidates.call(this, ...args);
137-
}
138-
139-
getAllCandidatesByPosition(
140-
...args: Parameters<typeof getAllCandidatesByPosition>
141-
) {
142-
return getAllCandidatesByPosition.call(this, ...args);
143-
}
144-
145-
getCandidate(...args: Parameters<typeof getCandidate>) {
146-
return getCandidate.call(this, ...args);
147-
}
148-
149-
insertCandidate(...args: Parameters<typeof insertCandidate>) {
150-
return insertCandidate.call(this, ...args);
151-
}
152-
153-
updateCandidate(...args: Parameters<typeof updateCandidate>) {
154-
return updateCandidate.call(this, ...args);
155-
}
156-
157-
deleteCandidate(...args: Parameters<typeof deleteCandidate>) {
158-
return deleteCandidate.call(this, ...args);
159-
}
160-
161-
// Nominations
162-
getAllNominations(...args: Parameters<typeof getAllNominations>) {
163-
return getAllNominations.call(this, ...args);
164-
}
165-
166-
getNominationsForPosition(
167-
...args: Parameters<typeof getNominationsForPosition>
168-
) {
169-
return getNominationsForPosition.call(this, ...args);
170-
}
171-
172-
getNominationsForCandidate(
173-
...args: Parameters<typeof getNominationsForCandidate>
174-
) {
175-
return getNominationsForCandidate.call(this, ...args);
176-
}
177-
178-
insertNomination(...args: Parameters<typeof insertNomination>) {
179-
return insertNomination.call(this, ...args);
180-
}
181-
182-
deleteNomination(...args: Parameters<typeof deleteNomination>) {
183-
return deleteNomination.call(this, ...args);
184-
}
185-
186-
// Races
187-
countVotesForRace(...args: Parameters<typeof countVotesForRace>) {
188-
return countVotesForRace.call(this, ...args);
189-
}
190-
191-
getAllRaces(...args: Parameters<typeof getAllRaces>) {
192-
return getAllRaces.call(this, ...args);
193-
}
194-
195-
getCurrentRace(...args: Parameters<typeof getCurrentRace>) {
196-
return getCurrentRace.call(this, ...args);
197-
}
198-
199-
getRace(...args: Parameters<typeof getRace>) {
200-
return getRace.call(this, ...args);
201-
}
202-
203-
insertRace(...args: Parameters<typeof insertRace>) {
204-
return insertRace.call(this, ...args);
205-
}
206-
207-
updateRace(...args: Parameters<typeof updateRace>) {
208-
return updateRace.call(this, ...args);
209-
}
210-
211-
deleteRace(...args: Parameters<typeof deleteRace>) {
212-
return deleteRace.call(this, ...args);
213-
}
214-
215-
saveElectedForRace(...args: Parameters<typeof saveElectedForRace>) {
216-
return saveElectedForRace.call(this, ...args);
217-
}
218-
219-
// Seats
220-
getSeat(...args: Parameters<typeof getSeat>) {
221-
return getSeat.call(this, ...args);
222-
}
223-
224-
getSeatByCode(...args: Parameters<typeof getSeatByCode>) {
225-
return getSeatByCode.call(this, ...args);
226-
}
227-
228-
insertSeat(...args: Parameters<typeof insertSeat>) {
229-
return insertSeat.call(this, ...args);
230-
}
231-
232-
deleteSeat(...args: Parameters<typeof deleteSeat>) {
233-
return deleteSeat.call(this, ...args);
234-
}
235-
236-
// Users
237-
countUsers(...args: Parameters<typeof countUsers>) {
238-
return countUsers.call(this, ...args);
239-
}
240-
241-
getAllUsers(...args: Parameters<typeof getAllUsers>) {
242-
return getAllUsers.call(this, ...args);
243-
}
244-
245-
getUser(...args: Parameters<typeof getUser>) {
246-
return getUser.call(this, ...args);
247-
}
248-
249-
getUserByEmail(...args: Parameters<typeof getUser>) {
250-
return getUserByEmail.call(this, ...args);
251-
}
252-
253-
insertUser(...args: Parameters<typeof insertUser>) {
254-
return insertUser.call(this, ...args);
255-
}
256-
257-
updateUser(...args: Parameters<typeof updateUser>) {
258-
return updateUser.call(this, ...args);
259-
}
260-
261-
deleteUser(...args: Parameters<typeof deleteUser>) {
262-
return deleteUser.call(this, ...args);
263-
}
264-
265-
// Vote Preferences
266-
getAllVotePreferences(...args: Parameters<typeof getAllVotePreferences>) {
267-
return getAllVotePreferences.call(this, ...args);
268-
}
269-
270-
getVotePreference(...args: Parameters<typeof getVotePreference>) {
271-
return getVotePreference.call(this, ...args);
272-
}
273-
274-
getVotePreferencesForVote(
275-
...args: Parameters<typeof getVotePreferencesForVote>
276-
) {
277-
return getVotePreferencesForVote.call(this, ...args);
278-
}
279-
280-
getVotePreferenceForCandidate(
281-
...args: Parameters<typeof getVotePreferenceForCandidate>
282-
) {
283-
return getVotePreferenceForCandidate.call(this, ...args);
284-
}
285-
286-
insertVotePreference(...args: Parameters<typeof insertVotePreference>) {
287-
return insertVotePreference.call(this, ...args);
288-
}
289-
290-
updateVotePreference(...args: Parameters<typeof updateVotePreference>) {
291-
return updateVotePreference.call(this, ...args);
292-
}
293-
294-
deleteVotePreference(...args: Parameters<typeof deleteVotePreference>) {
295-
return deleteVotePreference.call(this, ...args);
296-
}
297-
298-
// Votes
299-
getAllVotesForRace(...args: Parameters<typeof getAllVotesForRace>) {
300-
return getAllVotesForRace.call(this, ...args);
301-
}
302-
303-
getAllVotesByUser(...args: Parameters<typeof getAllVotesByUser>) {
304-
return getAllVotesByUser.call(this, ...args);
305-
}
306-
307-
getVoteByUserAndRace(...args: Parameters<typeof getVoteByUserAndRace>) {
308-
return getVoteByUserAndRace.call(this, ...args);
309-
}
310-
311-
insertVote(...args: Parameters<typeof insertVote>) {
312-
return insertVote.call(this, ...args);
313-
}
314-
315-
updateVote(...args: Parameters<typeof updateVote>) {
316-
return updateVote.call(this, ...args);
317-
}
318-
319-
deleteVote(...args: Parameters<typeof deleteVote>) {
320-
return deleteVote.call(this, ...args);
321-
}
322-
323-
getVoteAggregateForRace(...args: Parameters<typeof getVoteAggregateForRace>) {
324-
return getVoteAggregateForRace.call(this, ...args);
325-
}
326-
327-
getVoteCollatedForRace(...args: Parameters<typeof getVoteCollatedForRace>) {
328-
return getVoteCollatedForRace.call(this, ...args);
329-
}
330-
331-
// Elected
332-
insertElected(...args: Parameters<typeof insertElected>) {
333-
return insertElected.call(this, ...args);
334-
}
335-
336-
getAllElected(...args: Parameters<typeof getAllElected>) {
337-
return getAllElected.call(this, ...args);
338-
}
339-
340-
getElectedForRace(...args: Parameters<typeof getElectedForRace>) {
341-
return getElectedForRace.call(this, ...args);
342-
}
343-
344-
deleteElectedForRace(...args: Parameters<typeof deleteElectedForRace>) {
345-
return deleteElectedForRace.call(this, ...args);
346-
}
107+
// Statically assign dbMod functions
108+
for (const mod of Object.values(dbMod)) {
109+
Object.assign(VotingObject.prototype, mod);
347110
}

0 commit comments

Comments
 (0)