Skip to content

Commit eede380

Browse files
committed
Revert "add methods without writing them all out"
It did technically work but the typescript lsp didn't really know what to do with it. I couldn't get the class to implement the interface containing all the methods with dynamic allocation, and I couldn't work out how to force the type on the class either. This reverts commit 1834eea.
1 parent 1834eea commit eede380

File tree

2 files changed

+243
-27
lines changed

2 files changed

+243
-27
lines changed

src/models/db/index.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/models/index.ts

Lines changed: 243 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ 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";
513
import { seedMasterSeat, devSeeds, seedPositions, seedRaces } from "./seed";
614
import * as schema from "./schema";
715
import { eq } from "drizzle-orm";
8-
9-
import * as dbMod from "./db";
16+
import { deleteElectedForRace, getAllElected, getElectedForRace, insertElected } from "./db/elected";
1017

1118
export interface DOEnv {
1219
ENVIRONMENT: "dev" | "prod";
@@ -102,9 +109,239 @@ export class VotingObject extends DurableObject {
102109
connection[1].send(message);
103110
}
104111
}
105-
}
106112

107-
// Statically assign dbMod functions
108-
for (const mod of Object.values(dbMod)) {
109-
Object.assign(VotingObject.prototype, mod);
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+
}
110347
}

0 commit comments

Comments
 (0)