Created Room model, set up database connection

This commit is contained in:
Dmitriy Shishkov 2021-09-04 15:08:56 +03:00
parent 7fff6d4006
commit 3533230eb1
No known key found for this signature in database
GPG Key ID: 14358F96FCDD8060
5 changed files with 58 additions and 0 deletions

2
back/.env.example Normal file
View File

@ -0,0 +1,2 @@
DATABASE_URL="postgresql://"
PORT=8081

3
back/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
certs/
src/db/config.ts
.env

View File

@ -0,0 +1,6 @@
export const config = {
host: "",
username: "",
password: "",
database: "",
};

20
back/src/db/index.ts Normal file
View File

@ -0,0 +1,20 @@
import { Connection, createConnection } from "typeorm";
import fs from "fs";
import { Room } from "./model";
import { config } from "./config";
export const connect = () =>
createConnection({
...config,
type: "cockroachdb",
port: 26257,
ssl: {
ca: fs.readFileSync("certs/cc-ca.crt").toString(),
},
synchronize: true,
logging: false,
entities: [Room],
});
export { Room };

27
back/src/db/model.ts Normal file
View File

@ -0,0 +1,27 @@
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Room {
@PrimaryGeneratedColumn()
id: number;
@Column({
length: 100,
})
title: string;
@Column()
free: boolean;
@Column()
x: number;
@Column()
y: number;
@Column()
width: number;
@Column()
height: number;
}