22 lines
706 B
TypeScript
22 lines
706 B
TypeScript
import { count, eq, getTableColumns } from 'drizzle-orm';
|
|
import { db } from '../../db';
|
|
import { companiesTable } from '../../db/schema';
|
|
import { error } from 'elysia';
|
|
|
|
export async function getCount(city?: string) {
|
|
try {
|
|
// const res = await db
|
|
// .select()
|
|
// .from(projectsTable)
|
|
// .where(city ? eq(projectsTable.city, city) : undefined)
|
|
// .groupBy(projectsTable.companyId, projectsTable.id);
|
|
// console.log('res', res);
|
|
return (
|
|
await db.select({ count: count() }).from(companiesTable).limit(1)
|
|
)[0].count;
|
|
} catch (err) {
|
|
console.log((err as Error).message);
|
|
return error(500, { error: 'Something went wrong (Postgres select)' });
|
|
}
|
|
}
|