mirror of
https://github.com/khairul169/github-leaderboard.git
synced 2026-09-17 09:53:21 +07:00
feat: update language leaderboard calculation
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export { users } from "./users";
|
||||
export { repositories } from "./repositories";
|
||||
export { repositories, repositoriesRelations } from "./repositories";
|
||||
export { repoLanguages, repoLanguagesRelations } from "./repo-languages";
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { InferInsertModel, InferSelectModel, relations } from "drizzle-orm";
|
||||
import {
|
||||
text,
|
||||
sqliteTable,
|
||||
integer,
|
||||
index,
|
||||
real,
|
||||
} from "drizzle-orm/sqlite-core";
|
||||
import { repositories } from "./repositories";
|
||||
|
||||
export const repoLanguages = sqliteTable(
|
||||
"repository_languages",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
repoId: integer("repo_id")
|
||||
.notNull()
|
||||
.references(() => repositories.id),
|
||||
|
||||
name: text("name").notNull(),
|
||||
percentage: real("percentage").notNull(),
|
||||
},
|
||||
(t) => ({
|
||||
nameIdx: index("repository_languages_name_idx").on(t.name),
|
||||
})
|
||||
);
|
||||
|
||||
export const repoLanguagesRelations = relations(repoLanguages, ({ one }) => ({
|
||||
repository: one(repositories, {
|
||||
fields: [repoLanguages.repoId],
|
||||
references: [repositories.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export type RepositoryLanguage = InferSelectModel<typeof repoLanguages>;
|
||||
export type CreateRepositoryLanguage = InferInsertModel<typeof repoLanguages>;
|
||||
@@ -1,7 +1,13 @@
|
||||
import { Contributor, Language } from "@server/lib/github";
|
||||
import { InferInsertModel, InferSelectModel, sql } from "drizzle-orm";
|
||||
import { Contributor } from "@server/lib/github";
|
||||
import {
|
||||
InferInsertModel,
|
||||
InferSelectModel,
|
||||
relations,
|
||||
sql,
|
||||
} from "drizzle-orm";
|
||||
import { text, sqliteTable, integer, index } from "drizzle-orm/sqlite-core";
|
||||
import { users } from "./users";
|
||||
import { repoLanguages } from "./repo-languages";
|
||||
|
||||
export const repositories = sqliteTable(
|
||||
"repositories",
|
||||
@@ -17,7 +23,6 @@ export const repositories = sqliteTable(
|
||||
stars: integer("stars").notNull(),
|
||||
forks: integer("forks").notNull(),
|
||||
lastUpdate: text("last_update").notNull(),
|
||||
languages: text("languages", { mode: "json" }).$type<Language[]>(),
|
||||
contributors: text("contributors", { mode: "json" }).$type<Contributor[]>(),
|
||||
|
||||
isPending: integer("is_pending", { mode: "boolean" })
|
||||
@@ -39,5 +44,9 @@ export const repositories = sqliteTable(
|
||||
})
|
||||
);
|
||||
|
||||
export const repositoriesRelations = relations(repositories, ({ many }) => ({
|
||||
languages: many(repoLanguages),
|
||||
}));
|
||||
|
||||
export type Repository = InferSelectModel<typeof repositories>;
|
||||
export type CreateRepository = InferInsertModel<typeof repositories>;
|
||||
|
||||
Reference in New Issue
Block a user