-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Timescale for Usage tables
- Loading branch information
Showing
12 changed files
with
102 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { customerRouter } from '~/server/trpc/routers/customer'; | ||
import { licenseRouter } from '~/server/trpc/routers/license'; | ||
import { licenseUsageRouter } from '~/server/trpc/routers/licenseUsage'; | ||
import { productRouter } from '~/server/trpc/routers/product'; | ||
import { router, t } from '~/server/trpc/trpc'; | ||
|
||
export const appRouter = router({ | ||
license: licenseRouter, | ||
product: productRouter, | ||
customer: customerRouter, | ||
licenseUsage: licenseUsageRouter, | ||
}); | ||
|
||
export type AppRouter = typeof appRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { schema } from '@getlicensed/db'; | ||
import {and, desc, eq, sql} from 'drizzle-orm'; | ||
import { z } from 'zod'; | ||
import { protectedProcedure, t } from '~/server/trpc/trpc'; | ||
import { generateLicenseKey } from '~/server/utils/license'; | ||
|
||
const GetByIdShape = z.object({ | ||
id: z.string(), | ||
}); | ||
|
||
export const licenseUsageRouter = t.router({ | ||
getById: protectedProcedure.input(GetByIdShape).query(({ input, ctx }) => { | ||
return useDB().execute(sql`SELECT time_bucket('5 minutes', created_at) AS time, count(action), action | ||
FROM "License_usage" | ||
WHERE license_id = ${input.id} AND type = 'LICENSE_VALIDATE' | ||
GROUP BY time,action | ||
ORDER BY time DESC LIMIT 10;`) | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.