mirror of https://github.com/wg-easy/wg-easy
15 changed files with 122 additions and 209 deletions
@ -1,21 +0,0 @@ |
|||||
import { sql } from 'drizzle-orm'; |
|
||||
import { sqliteTable, text } from 'drizzle-orm/sqlite-core'; |
|
||||
|
|
||||
import { wgInterface } from '../../schema'; |
|
||||
|
|
||||
export const prometheus = sqliteTable('prometheus_table', { |
|
||||
id: text() |
|
||||
.primaryKey() |
|
||||
.references(() => wgInterface.name, { |
|
||||
onDelete: 'cascade', |
|
||||
onUpdate: 'cascade', |
|
||||
}), |
|
||||
password: text().notNull(), |
|
||||
createdAt: text('created_at') |
|
||||
.notNull() |
|
||||
.default(sql`(CURRENT_TIMESTAMP)`), |
|
||||
updatedAt: text('updated_at') |
|
||||
.notNull() |
|
||||
.default(sql`(CURRENT_TIMESTAMP)`) |
|
||||
.$onUpdate(() => sql`(CURRENT_TIMESTAMP)`), |
|
||||
}); |
|
@ -1,31 +0,0 @@ |
|||||
import type { DBType } from '#db/sqlite'; |
|
||||
import { eq, sql } from 'drizzle-orm'; |
|
||||
import { prometheus } from './schema'; |
|
||||
|
|
||||
function createPreparedStatement(db: DBType) { |
|
||||
return { |
|
||||
get: db.query.prometheus |
|
||||
.findFirst({ where: eq(prometheus.id, sql.placeholder('interface')) }) |
|
||||
.prepare(), |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
export class PrometheusService { |
|
||||
#statements: ReturnType<typeof createPreparedStatement>; |
|
||||
|
|
||||
constructor(db: DBType) { |
|
||||
this.#statements = createPreparedStatement(db); |
|
||||
} |
|
||||
|
|
||||
get(infName: string) { |
|
||||
return this.#statements.get.execute({ interface: infName }); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
export class MetricsService { |
|
||||
prometheus: PrometheusService; |
|
||||
|
|
||||
constructor(db: DBType) { |
|
||||
this.prometheus = new PrometheusService(db); |
|
||||
} |
|
||||
} |
|
@ -1,4 +0,0 @@ |
|||||
import type { InferSelectModel } from 'drizzle-orm'; |
|
||||
import type { prometheus } from './schema'; |
|
||||
|
|
||||
export type PrometheusType = InferSelectModel<typeof prometheus>; |
|
Loading…
Reference in new issue