diff --git a/adminSiteServer/adminRouter.tsx b/adminSiteServer/adminRouter.tsx index 5796e9f7a84..02f3ed9cfe4 100644 --- a/adminSiteServer/adminRouter.tsx +++ b/adminSiteServer/adminRouter.tsx @@ -43,7 +43,7 @@ import { } from "../baker/GrapherBaker.js" import { Chart } from "../db/model/Chart.js" import { getVariableMetadata } from "../db/model/Variable.js" -import { DatasetFilesRow, DatasetsRow } from "@ourworldindata/types" +import { DatasetFilesRow, DbPlainDataset } from "@ourworldindata/types" // Used for rate-limiting important endpoints (login, register) to prevent brute force attacks const limiterMiddleware = ( @@ -139,7 +139,7 @@ adminRouter.get("/datasets/:datasetId.csv", async (req, res) => { const datasetId = expectInt(req.params.datasetId) const datasetName = ( - await db.knexRawFirst>( + await db.knexRawFirst>( `SELECT name FROM datasets WHERE id=?`, [datasetId] ) diff --git a/adminSiteServer/apiRouter.ts b/adminSiteServer/apiRouter.ts index ff30d3cf682..2c16df16187 100644 --- a/adminSiteServer/apiRouter.ts +++ b/adminSiteServer/apiRouter.ts @@ -51,10 +51,10 @@ import { OwidGdoc, } from "@ourworldindata/utils" import { - DatasetTagsRow, + DatasetDbPlainTag, GrapherInterface, OwidGdocLinkType, - TagsRow, + DbPlainTag, grapherKeysToSerialize, } from "@ourworldindata/types" import { @@ -1706,7 +1706,7 @@ apiRouter.get("/datasets.json", async (req) => { `) const tags = await db.knexRaw< - Pick & Pick + Pick & Pick >(` SELECT dt.datasetId, t.id, t.name FROM dataset_tags dt JOIN tags t ON dt.tagId = t.id diff --git a/adminSiteServer/exportGitData.ts b/adminSiteServer/exportGitData.ts index 4bac27c4c31..33bc697f0b9 100644 --- a/adminSiteServer/exportGitData.ts +++ b/adminSiteServer/exportGitData.ts @@ -1,10 +1,10 @@ import * as db from "../db/db.js" import { syncDatasetToGitRepo } from "./gitDataExport.js" -import { DatasetsRow, DatasetsRowTableName } from "@ourworldindata/types" +import { DbPlainDataset, DbPlainDatasetTableName } from "@ourworldindata/types" const main = async () => { const knex = db.knexInstance() - const datasets = await knex(DatasetsRowTableName).where({ + const datasets = await knex(DbPlainDatasetTableName).where({ namespace: "owid", }) for (const dataset of datasets) { diff --git a/adminSiteServer/gitDataExport.ts b/adminSiteServer/gitDataExport.ts index f707a4470db..ec41d900a60 100644 --- a/adminSiteServer/gitDataExport.ts +++ b/adminSiteServer/gitDataExport.ts @@ -16,13 +16,13 @@ import * as db from "../db/db.js" import filenamify from "filenamify" import { execFormatted } from "../db/execWrapper.js" import { JsonError } from "@ourworldindata/utils" -import { DatasetsRow } from "@ourworldindata/types" +import { DbPlainDataset } from "@ourworldindata/types" import { Knex } from "knex" import { getSourcesForDataset } from "../db/model/Source.js" const datasetToReadme = async ( knex: Knex, - dataset: DatasetsRow + dataset: DbPlainDataset ): Promise => { // TODO: add origins here const source = (await getSourcesForDataset(knex, dataset.id))[0] diff --git a/db/model/Dataset.ts b/db/model/Dataset.ts index 506e3af4536..b6457ffe2f6 100644 --- a/db/model/Dataset.ts +++ b/db/model/Dataset.ts @@ -16,9 +16,9 @@ import * as db from "../db.js" import { VariableRow, variableTable, writeVariableCSV } from "./Variable.js" import _ from "lodash" import { - DatasetsRow, - DatasetsRowTableName, - TagsRow, + DbPlainDataset, + DatasetsTableName, + DbPlainTag, } from "@ourworldindata/types" import { Knex } from "knex" @@ -45,8 +45,8 @@ export class Dataset extends BaseEntity { export async function getDatasetById( knex: Knex, datasetId: number -): Promise { - const dataset = await knex(DatasetsRowTableName) +): Promise { + const dataset = await knex(DatasetsTableName) .where({ id: datasetId }) .first() if (!dataset) return undefined @@ -116,7 +116,7 @@ export async function datasetToDatapackage( const variables = (await db .knexTable(variableTable) .where({ datasetId })) as VariableRow[] - const tags = await db.knexRaw>( + const tags = await db.knexRaw>( `SELECT t.id, t.name FROM dataset_tags dt JOIN tags t ON t.id=dt.tagId WHERE dt.datasetId=?`, [datasetId], knex @@ -159,7 +159,7 @@ export async function datasetToDatapackage( } export function isDatasetWithName( - dataset: DatasetsRow -): dataset is DatasetsRow & { name: NonNullable } { + dataset: DbPlainDataset +): dataset is DbPlainDataset & { name: NonNullable } { return dataset.name !== undefined && dataset.name !== null } diff --git a/db/model/Source.ts b/db/model/Source.ts index b95c4fd400f..28db13fda1d 100644 --- a/db/model/Source.ts +++ b/db/model/Source.ts @@ -1,9 +1,9 @@ import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm" import { Knex } from "knex" import { - SourcesRowEnriched, - SourcesRowRaw, - SourcesRowTableName, + DbEnrichedSource, + DbRawSource, + SourcesTableName, parseSourcesRow, } from "@ourworldindata/types" @@ -18,8 +18,8 @@ export class Source extends BaseEntity { export async function getSourceById( knex: Knex, sourceId: number -): Promise { - const rawSource = await knex(SourcesRowTableName) +): Promise { + const rawSource = await knex(SourcesTableName) .where({ id: sourceId }) .first() if (!rawSource) return undefined @@ -34,8 +34,8 @@ export async function getSourceById( export async function getSourcesForDataset( knex: Knex, datasetId: number -): Promise { - const rawSources = await knex(SourcesRowTableName).where({ +): Promise { + const rawSources = await knex(SourcesTableName).where({ datasetId, }) const sources = rawSources.map((rawSource) => @@ -49,7 +49,7 @@ export async function getSourcesForDataset( } export async function sourceToDatapackage( - source: SourcesRowEnriched + source: DbEnrichedSource ): Promise { return Object.assign({}, { name: source.name }, source.description) }