Fix: Replace SQLite .get() with array indexing for PostgreSQL compatibility
swadhinbiswas committed 9 months ago
517f67d
1 parent a7662cd
commit 517f67d
14 files changed
+34 -23
Showing 14 changed files+34-23
fix_get_calls.shsrc/pages/[owner]/[repo]/branches/index.astrosrc/pages/[owner]/[repo]/index.astrosrc/pages/[owner]/[repo]/insights/index.astrosrc/pages/[owner]/[repo]/merge-queue.astrosrc/pages/[owner]/[repo]/pulls/[number].astrosrc/pages/[owner]/[repo]/pulls/index.astrosrc/pages/[owner]/[repo]/pulls/new.astrosrc/pages/[owner]/[repo]/security/index.astrosrc/pages/[owner]/[repo]/tree/[...ref].astrosrc/pages/[owner]/[repo]/tree/[branch]/[...path].astrosrc/pages/admin/audit.astrosrc/pages/admin/repositories.astrosrc/pages/admin/users.astro
▼fix_get_calls.sh
+13-0
| @@ -0,0 +1,13 @@ | ||
1 | +#!/bin/bash | |
2 | + | |
3 | +# Fix admin/repositories.astro | |
4 | +sed -i 's/\.get(),$/,/g; s/countResult\.count/countResult?.[0]?.count/g' src/pages/admin/repositories.astro | |
5 | + | |
6 | +# Fix admin/audit.astro | |
7 | +sed -i 's/\.get(),$/,/g; s/countResult\.count/countResult?.[0]?.count/g' src/pages/admin/audit.astro | |
8 | + | |
9 | +# Fix admin/users.astro | |
10 | +sed -i 's/\.get() as { count: number } | undefined,$/,/g' src/pages/admin/users.astro | |
11 | +sed -i 's/countResult\.count/countResult?.[0]?.count/g' src/pages/admin/users.astro | |
12 | + | |
13 | +echo "Fixed .get() in admin files" | |
0 | 14 | |
▼src/pages/[owner]/[repo]/branches/index.astro
+1-1
| @@ -89,7 +89,7 @@ const issueCountResult = await (db as any) | ||
89 | 89 | eq(schema.issues.state, "open"), |
90 | 90 | ), |
91 | 91 | ) |
92 | - .get(); | |
92 | + ; | |
93 | 93 | |
94 | 94 | const openIssueCount = issueCountResult?.count || 0; |
95 | 95 | |
96 | 96 | |
▼src/pages/[owner]/[repo]/index.astro
+2-3
| @@ -64,10 +64,9 @@ const issueCountResult = await (db as any) | ||
64 | 64 | eq(schema.issues.repositoryId, repoData.id), |
65 | 65 | eq(schema.issues.state, "open"), |
66 | 66 | ), |
67 | - ) | |
68 | - .get(); | |
67 | + ); | |
69 | 68 | |
70 | -const openIssueCount = issueCountResult?.count || 0; | |
69 | +const openIssueCount = issueCountResult?.[0]?.count || 0; | |
71 | 70 | |
72 | 71 | // 2. Git Operations |
73 | 72 | const currentBranch = repoData.defaultBranch; |
74 | 73 | |
▼src/pages/[owner]/[repo]/insights/index.astro
+5-5
| @@ -71,7 +71,7 @@ const issueCountResult = (await db | ||
71 | 71 | eq(schema.issues.state, "open"), |
72 | 72 | ), |
73 | 73 | ) |
74 | - .get()) as { count: number } | undefined; | |
74 | + ) as { count: number }[]; | |
75 | 75 | |
76 | 76 | repo.openIssueCount = issueCountResult?.count || 0; |
77 | 77 | |
| @@ -97,7 +97,7 @@ const [recentIssues] = await (db as any) | ||
97 | 97 | gte(schema.issues.createdAt, thirtyDaysAgo.toISOString()), |
98 | 98 | ), |
99 | 99 | ) |
100 | - .get(); | |
100 | + ; | |
101 | 101 | |
102 | 102 | const [recentPRs] = await (db as any) |
103 | 103 | .select({ count: count() }) |
| @@ -108,7 +108,7 @@ const [recentPRs] = await (db as any) | ||
108 | 108 | gte(schema.pullRequests.createdAt, thirtyDaysAgo.toISOString()), |
109 | 109 | ), |
110 | 110 | ) |
111 | - .get(); | |
111 | + ; | |
112 | 112 | |
113 | 113 | const [closedIssues] = await (db as any) |
114 | 114 | .select({ count: count() }) |
| @@ -120,7 +120,7 @@ const [closedIssues] = await (db as any) | ||
120 | 120 | gte(schema.issues.updatedAt, thirtyDaysAgo.toISOString()), |
121 | 121 | ), |
122 | 122 | ) |
123 | - .get(); | |
123 | + ; | |
124 | 124 | |
125 | 125 | const [mergedPRs] = await (db as any) |
126 | 126 | .select({ count: count() }) |
| @@ -132,7 +132,7 @@ const [mergedPRs] = await (db as any) | ||
132 | 132 | gte(schema.pullRequests.updatedAt, thirtyDaysAgo.toISOString()), |
133 | 133 | ), |
134 | 134 | ) |
135 | - .get(); | |
135 | + ; | |
136 | 136 | --- |
137 | 137 | |
138 | 138 | <BaseLayout title={`Insights · ${repo.owner}/${repo.name}`}> |
139 | 139 | |
▼src/pages/[owner]/[repo]/merge-queue.astro
+1-1
| @@ -68,7 +68,7 @@ const issueCountResult = await (db as any) | ||
68 | 68 | eq(schema.issues.state, "open"), |
69 | 69 | ), |
70 | 70 | ) |
71 | - .get(); | |
71 | + ; | |
72 | 72 | |
73 | 73 | const openIssueCount = issueCountResult?.count || 0; |
74 | 74 | |
75 | 75 | |
▼src/pages/[owner]/[repo]/pulls/[number].astro
+1-1
| @@ -106,7 +106,7 @@ const issueCountResult = (await db | ||
106 | 106 | eq(schema.issues.state, "open"), |
107 | 107 | ), |
108 | 108 | ) |
109 | - .get()) as { count: number } | undefined; | |
109 | + ) as { count: number }[]; | |
110 | 110 | |
111 | 111 | const openIssueCount = issueCountResult?.count || 0; |
112 | 112 | |
113 | 113 | |
▼src/pages/[owner]/[repo]/pulls/index.astro
+1-1
| @@ -47,7 +47,7 @@ const issueCountResult = (await db | ||
47 | 47 | eq(schema.issues.state, "open"), |
48 | 48 | ), |
49 | 49 | ) |
50 | - .get()) as { count: number } | undefined; | |
50 | + ) as { count: number }[]; | |
51 | 51 | |
52 | 52 | const openIssueCount = issueCountResult?.count || 0; |
53 | 53 | |
54 | 54 | |
▼src/pages/[owner]/[repo]/pulls/new.astro
+1-1
| @@ -105,7 +105,7 @@ const issueCountResult = (await db | ||
105 | 105 | eq(schema.issues.state, "open"), |
106 | 106 | ), |
107 | 107 | ) |
108 | - .get()) as { count: number } | undefined; | |
108 | + ) as { count: number }[]; | |
109 | 109 | |
110 | 110 | const openIssueCount = issueCountResult?.count || 0; |
111 | 111 | |
112 | 112 | |
▼src/pages/[owner]/[repo]/security/index.astro
+1-1
| @@ -47,7 +47,7 @@ const openIssueCount = | ||
47 | 47 | eq(schema.issues.state, "open"), |
48 | 48 | ), |
49 | 49 | ) |
50 | - .get()) as { count: number } | undefined | |
50 | + ) as { count: number }[] | |
51 | 51 | )?.count || 0; |
52 | 52 | |
53 | 53 | const repoInfo = { |
54 | 54 | |
▼src/pages/[owner]/[repo]/tree/[...ref].astro
+2-3
| @@ -65,11 +65,10 @@ const issueCountResult = await db | ||
65 | 65 | eq(schema.issues.repositoryId, repoData.id), |
66 | 66 | eq(schema.issues.state, "open"), |
67 | 67 | ), |
68 | - ) | |
69 | - .get(); | |
68 | + ); | |
70 | 69 | |
71 | 70 | const openIssueCount = |
72 | - (issueCountResult as { count: number } | undefined)?.count || 0; | |
71 | + (issueCountResult as { count: number }[])?.[0]?.count || 0; | |
73 | 72 | |
74 | 73 | // 2. Git Operations |
75 | 74 | // Extract branch and path from [...ref] |
76 | 75 | |
▼src/pages/[owner]/[repo]/tree/[branch]/[...path].astro
+1-1
| @@ -59,7 +59,7 @@ const issueCountResult = await db | ||
59 | 59 | eq(schema.issues.state, "open"), |
60 | 60 | ), |
61 | 61 | ) |
62 | - .get(); | |
62 | + ; | |
63 | 63 | |
64 | 64 | const openIssueCount = |
65 | 65 | (issueCountResult as { count: number } | undefined)?.count || 0; |
66 | 66 | |
▼src/pages/admin/audit.astro
+1-1
| @@ -73,7 +73,7 @@ const [logs, totalResult] = await Promise.all([ | ||
73 | 73 | .select({ count: sql<number>`count(*)` }) |
74 | 74 | .from(schema.auditLogs) |
75 | 75 | .where(whereClause) |
76 | - .get(), | |
76 | + , | |
77 | 77 | ]); |
78 | 78 | |
79 | 79 | const total = (totalResult as { count: number } | undefined)?.count || 0; |
80 | 80 | |
▼src/pages/admin/repositories.astro
+1-1
| @@ -48,7 +48,7 @@ const [repos, totalResult] = await Promise.all([ | ||
48 | 48 | .select({ count: sql<number>`count(*)` }) |
49 | 49 | .from(schema.repositories) |
50 | 50 | .where(whereClause) |
51 | - .get(), | |
51 | + , | |
52 | 52 | ]); |
53 | 53 | |
54 | 54 | const total = (totalResult as { count: number } | undefined)?.count || 0; |
55 | 55 | |
▼src/pages/admin/users.astro
+3-3
| @@ -63,19 +63,19 @@ const [totalUsers, activeUsers, adminUsers] = await Promise.all([ | ||
63 | 63 | // @ts-expect-error: count argument mismatch |
64 | 64 | .select({ count: sql<number>`count(*)` }) |
65 | 65 | .from(schema.users) |
66 | - .get() as { count: number } | undefined, | |
66 | + , | |
67 | 67 | db |
68 | 68 | // @ts-expect-error: count argument mismatch |
69 | 69 | .select({ count: sql<number>`count(*)` }) |
70 | 70 | .from(schema.users) |
71 | 71 | .where(eq(schema.users.isActive, true)) |
72 | - .get() as { count: number } | undefined, | |
72 | + , | |
73 | 73 | db |
74 | 74 | // @ts-expect-error: count argument mismatch |
75 | 75 | .select({ count: sql<number>`count(*)` }) |
76 | 76 | .from(schema.users) |
77 | 77 | .where(eq(schema.users.isAdmin, true)) |
78 | - .get() as { count: number } | undefined, | |
78 | + , | |
79 | 79 | ]); |
80 | 80 | --- |
81 | 81 | |
82 | 82 | |