mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-24 22:46:41 +07:00
#4 added entities and synchronization to project
This commit is contained in:
parent
c5c3c013ba
commit
50db549cbe
5 changed files with 33 additions and 4 deletions
|
@ -7,7 +7,7 @@ telegram:
|
|||
url: https://something.org:3002/webhook
|
||||
enabled: false
|
||||
postgres:
|
||||
uri: postgres://user:password@db/test
|
||||
uri: postgres://user:password@db/bot
|
||||
logger:
|
||||
level: info
|
||||
vk:
|
||||
|
|
16
docker-compose.yml
Normal file
16
docker-compose.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
version: '3.4'
|
||||
services:
|
||||
db:
|
||||
container_name: bot-db
|
||||
image: postgres:11-alpine
|
||||
ports:
|
||||
- 5432:5432
|
||||
environment:
|
||||
POSTGRES_USER: user
|
||||
POSTGRES_PASSWORD: password
|
||||
POSTGRES_DB: bot
|
||||
volumes:
|
||||
- bot-db:/var/lib/postgresql/data
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
volumes:
|
||||
bot-db: {}
|
|
@ -1,5 +1,6 @@
|
|||
import { VkEvent } from "../vk/types";
|
||||
import { StoredEvent, StoredLike } from "./types";
|
||||
import { Like } from "./postgres/entities/Like";
|
||||
|
||||
export interface Storage {
|
||||
getEvent(
|
||||
|
@ -9,7 +10,9 @@ export interface Storage {
|
|||
channel: string
|
||||
): Promise<StoredEvent>;
|
||||
|
||||
createEvent(event: StoredEvent): Promise<StoredEvent>;
|
||||
createEvent(event: Partial<StoredEvent>): Promise<StoredEvent>;
|
||||
|
||||
createOrUpdateLike(like: Partial<StoredLike>): Promise<Like>;
|
||||
|
||||
getLikesFor(channel: string, messageId: number): Promise<StoredLike[]>;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
import { StoredLike } from "../../types";
|
||||
|
||||
@Entity()
|
||||
class Like implements StoredLike {
|
||||
export class Like implements StoredLike {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
@Column()
|
||||
|
|
|
@ -3,6 +3,10 @@ import { VkEvent } from "../../vk/types";
|
|||
import { StoredEvent } from "../types";
|
||||
import { PostgresConfig } from "./types";
|
||||
import { Connection, createConnection } from "typeorm";
|
||||
import logger from "../../logger";
|
||||
import path from "path";
|
||||
|
||||
const entities = [path.join(__dirname, "./entities/*")];
|
||||
|
||||
export class PostgresDB implements Storage {
|
||||
private connection: Connection;
|
||||
|
@ -12,8 +16,14 @@ export class PostgresDB implements Storage {
|
|||
this.connection = await createConnection({
|
||||
type: "postgres",
|
||||
url: this.config.uri,
|
||||
entities: ["./entities/*.ts"],
|
||||
entities,
|
||||
logging: true,
|
||||
synchronize: true,
|
||||
});
|
||||
|
||||
await this.connection.synchronize();
|
||||
|
||||
logger.info(`db connected to ${this.config.uri}`);
|
||||
};
|
||||
|
||||
getEvent = async (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue