-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 remove most typeorm classes, start work on Links to turn them into …
…objects
- Loading branch information
Showing
9 changed files
with
140 additions
and
223 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
BaseEntity, | ||
ManyToOne, | ||
type Relation, | ||
} from "typeorm" | ||
import { Chart } from "./Chart.js" | ||
import { User } from "./User.js" | ||
// import { | ||
// Entity, | ||
// PrimaryGeneratedColumn, | ||
// Column, | ||
// BaseEntity, | ||
// ManyToOne, | ||
// type Relation, | ||
// } from "typeorm" | ||
// // import { Chart } from "./Chart.js" | ||
// import { User } from "./User.js" | ||
|
||
@Entity("chart_revisions") | ||
export class ChartRevision extends BaseEntity { | ||
@PrimaryGeneratedColumn() id!: number | ||
@Column() chartId!: number | ||
@Column({ type: "json" }) config: any | ||
@Column() userId!: number | ||
// @Entity("chart_revisions") | ||
// export class ChartRevision extends BaseEntity { | ||
// @PrimaryGeneratedColumn() id!: number | ||
// @Column() chartId!: number | ||
// @Column({ type: "json" }) config: any | ||
// @Column() userId!: number | ||
|
||
@Column() createdAt!: Date | ||
@Column() updatedAt!: Date | ||
// @Column() createdAt!: Date | ||
// @Column() updatedAt!: Date | ||
|
||
@ManyToOne(() => User, (user) => user.editedCharts) | ||
user!: Relation<User> | ||
// @ManyToOne(() => User, (user) => user.editedCharts) | ||
// user!: Relation<User> | ||
|
||
@ManyToOne(() => Chart, (chart) => chart.logs) | ||
chart!: Relation<Chart> | ||
} | ||
// @ManyToOne(() => Chart, (chart) => chart.logs) | ||
// chart!: Relation<Chart> | ||
// } |
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,8 +1,8 @@ | ||
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm" | ||
// import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm" | ||
|
||
@Entity("posts_gdocs_x_images") | ||
export class GdocXImage extends BaseEntity { | ||
@PrimaryGeneratedColumn() id!: number | ||
@Column() gdocId!: string | ||
@Column() imageId!: number | ||
} | ||
// @Entity("posts_gdocs_x_images") | ||
// export class GdocXImage extends BaseEntity { | ||
// @PrimaryGeneratedColumn() id!: number | ||
// @Column() gdocId!: string | ||
// @Column() imageId!: number | ||
// } |
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,8 +1,8 @@ | ||
import { Entity, BaseEntity, PrimaryColumn } from "typeorm" | ||
// import { Entity, BaseEntity, PrimaryColumn } from "typeorm" | ||
|
||
@Entity("posts_gdocs_x_tags") | ||
export class GdocXTag extends BaseEntity { | ||
static table = "posts_gdocs_x_tags" | ||
@PrimaryColumn() gdocId!: string | ||
@PrimaryColumn() tagId!: number | ||
} | ||
// @Entity("posts_gdocs_x_tags") | ||
// export class GdocXTag extends BaseEntity { | ||
// static table = "posts_gdocs_x_tags" | ||
// @PrimaryColumn() gdocId!: string | ||
// @PrimaryColumn() tagId!: number | ||
// } |
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,64 +1,56 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
BaseEntity, | ||
ManyToOne, | ||
type Relation, | ||
In, | ||
} from "typeorm" | ||
import { getLinkType, getUrlTarget } from "@ourworldindata/components" | ||
import { OwidGdocLinkJSON, Url } from "@ourworldindata/utils" | ||
import { GdocBase } from "./Gdoc/GdocBase.js" | ||
import { formatUrls } from "../../site/formatting.js" | ||
import { OwidGdocLinkType } from "@ourworldindata/types" | ||
|
||
@Entity("posts_gdocs_links") | ||
export class Link extends BaseEntity implements OwidGdocLinkJSON { | ||
@PrimaryGeneratedColumn() id!: number | ||
@ManyToOne(() => GdocBase, (gdoc) => gdoc.id) source!: Relation<GdocBase> | ||
@Column() linkType!: OwidGdocLinkType | ||
@Column() target!: string | ||
@Column() queryString!: string | ||
@Column() hash!: string | ||
@Column() componentType!: string | ||
@Column() text!: string | ||
import { | ||
DbInsertPostGdocLink, | ||
DbPlainPostGdocLink, | ||
OwidGdocLinkType, | ||
} from "@ourworldindata/types" | ||
import { KnexReadonlyTransaction, knexRaw } from "../db.js" | ||
|
||
static async getPublishedLinksTo( | ||
ids: string[], | ||
linkType?: Link["linkType"] | ||
): Promise<Link[]> { | ||
return Link.find({ | ||
where: { target: In(ids), linkType }, | ||
relations: ["source"], | ||
}).then((links) => links.filter((link) => link.source.published)) | ||
} | ||
export async function getPublishedLinksTo( | ||
knex: KnexReadonlyTransaction, | ||
ids: string[], | ||
linkType?: OwidGdocLinkType | ||
): Promise<DbPlainPostGdocLink[]> { | ||
const rows = await knexRaw<DbPlainPostGdocLink>( | ||
knex, | ||
`-- sql | ||
select posts_gdocs_links.* from posts_gdocs_links | ||
join posts_gdocs on posts_gdocs_links.source = posts_gdocs.id | ||
where target in (?) and linkType = ? | ||
and published = true | ||
`, | ||
[ids, linkType] | ||
) | ||
return rows | ||
} | ||
|
||
static createFromUrl({ | ||
url, | ||
source, | ||
text = "", | ||
componentType = "", | ||
}: { | ||
url: string | ||
source: GdocBase | ||
text?: string | ||
componentType?: string | ||
}): Link { | ||
const formattedUrl = formatUrls(url) | ||
const urlObject = Url.fromURL(formattedUrl) | ||
const linkType = getLinkType(formattedUrl) | ||
const target = getUrlTarget(formattedUrl) | ||
const queryString = urlObject.queryStr | ||
const hash = urlObject.hash | ||
return Link.create({ | ||
target, | ||
linkType, | ||
queryString, | ||
hash, | ||
source, | ||
text, | ||
componentType, | ||
}) | ||
} | ||
export function createFromUrl({ | ||
url, | ||
source, | ||
text = "", | ||
componentType = "", | ||
}: { | ||
url: string | ||
source: GdocBase | ||
text?: string | ||
componentType?: string | ||
}): DbInsertPostGdocLink { | ||
const formattedUrl = formatUrls(url) | ||
const urlObject = Url.fromURL(formattedUrl) | ||
const linkType = getLinkType(formattedUrl) | ||
const target = getUrlTarget(formattedUrl) | ||
const queryString = urlObject.queryStr | ||
const hash = urlObject.hash | ||
return { | ||
target, | ||
linkType, | ||
queryString, | ||
hash, | ||
text, | ||
componentType, | ||
sourceId: source.id, | ||
} satisfies DbInsertPostGdocLink | ||
} |
Oops, something went wrong.