Created Room model, set up database connection
This commit is contained in:
parent
7fff6d4006
commit
3533230eb1
2
back/.env.example
Normal file
2
back/.env.example
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
DATABASE_URL="postgresql://"
|
||||||
|
PORT=8081
|
3
back/.gitignore
vendored
Normal file
3
back/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
certs/
|
||||||
|
src/db/config.ts
|
||||||
|
.env
|
6
back/src/db/config.example.ts
Normal file
6
back/src/db/config.example.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export const config = {
|
||||||
|
host: "",
|
||||||
|
username: "",
|
||||||
|
password: "",
|
||||||
|
database: "",
|
||||||
|
};
|
20
back/src/db/index.ts
Normal file
20
back/src/db/index.ts
Normal 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
27
back/src/db/model.ts
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user