Skip to content

Commit

Permalink
removed sequilize
Browse files Browse the repository at this point in the history
  • Loading branch information
omera26 committed Aug 11, 2024
1 parent fb2ef26 commit 4368df3
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 231 deletions.

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions backend/typescript/models/entity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,3 @@ const EntitySchema: Schema = new Schema({
export default model<Entity>("Entity", EntitySchema);

// } mongodb
// postgresql {
import { Column, Model, Table, DataType } from "sequelize-typescript";

import { Letters } from "../types";

@Table({ tableName: "entities" })
export default class Entity extends Model {
@Column
string_field!: string;

@Column
int_field!: number;

@Column({ type: DataType.ENUM("A", "B", "C", "D") })
enum_field!: Letters;

@Column({ type: DataType.ARRAY(DataType.STRING) })
string_array_field!: string[];

@Column
bool_field!: boolean;

@Column
file_name!: string;
}

// } postgresql
16 changes: 0 additions & 16 deletions backend/typescript/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
// postgresql {
import * as path from "path";
import { Sequelize } from "sequelize-typescript";

const DATABASE_URL =
process.env.NODE_ENV === "production"
? /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
process.env.DATABASE_URL!
: `postgres://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}@${process.env.DB_HOST}:5432/${process.env.POSTGRES_DB_DEV}`;

/* eslint-disable-next-line import/prefer-default-export */
export const sequelize = new Sequelize(DATABASE_URL, {
models: [path.join(__dirname, "/*.model.ts")],
});

// } postgresql
// mongodb {
import mongoose from "mongoose";

Expand Down
26 changes: 1 addition & 25 deletions backend/typescript/models/simpleEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,4 @@ const SimpleEntitySchema: Schema = new Schema({

export default model<SimpleEntity>("SimpleEntity", SimpleEntitySchema);

// } mongodb
// postgresql {
import { Column, Model, Table, DataType } from "sequelize-typescript";

import { Letters } from "../types";

@Table({ tableName: "simple_entities" })
export default class SimpleEntity extends Model {
@Column
string_field!: string;

@Column
int_field!: number;

@Column({ type: DataType.ENUM("A", "B", "C", "D") })
enum_field!: Letters;

@Column({ type: DataType.ARRAY(DataType.STRING) })
string_array_field!: string[];

@Column
bool_field!: boolean;
}

// } postgresql
// } mongodb
22 changes: 1 addition & 21 deletions backend/typescript/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,4 @@ const UserSchema: Schema = new Schema({

export default mongoose.model<User>("User", UserSchema);

// } mongodb
// postgresql {
import { Column, DataType, Model, Table } from "sequelize-typescript";
import { Role } from "../types";

@Table({ tableName: "users" })
export default class User extends Model {
@Column({ type: DataType.STRING })
first_name!: string;

@Column({ type: DataType.STRING })
last_name!: string;

@Column({ type: DataType.STRING })
auth_id!: string;

@Column({ type: DataType.ENUM("User", "Admin") })
role!: Role;
}

// } postgresql
// } mongodb
2 changes: 0 additions & 2 deletions backend/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
"pg": "^8.5.1",
"prisma": "5.14.0",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.5.0",
"sequelize-typescript": "^2.1.0",
"swagger-ui-express": "^4.1.6",
"ts-node": "^10.0.0",
"umzug": "^3.0.0-beta.16",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// postgresql {
import { snakeCase } from "lodash";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
// } postgresql

import UserModel from "../../../models/user.model";
Expand All @@ -10,9 +12,6 @@ import { UserDTO } from "../../../types";
// mongodb {
import db from "../../../testUtils/testDb";
// } mongodb
// postgresql {
import { testSql } from "../../../testUtils/testDb";
// } postgresql

const testUsers = [
{
Expand Down Expand Up @@ -70,18 +69,18 @@ describe("mongo userService", (): void => {
});
// } mongodb

// postgresql {
// postgresql {
describe("pg userService", () => {
let userService: UserService;

beforeEach(async () => {
await testSql.sync({ force: true });
await prisma.$connect();
await prisma.user.deleteMany(); // Clear the User table before each test
userService = new UserService();
});

afterAll(async () => {
await testSql.sync({ force: true });
await testSql.close();
await prisma.$disconnect();
});

it("getUsers", async () => {
Expand All @@ -93,7 +92,7 @@ describe("pg userService", () => {
return userSnakeCase;
});

await UserModel.bulkCreate(users);
await prisma.user.createMany({ data: users });

const res = await userService.getUsers();

Expand Down
22 changes: 1 addition & 21 deletions backend/typescript/testUtils/testDb.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// mongodb {
import mongoose from "mongoose";
// } mongodb
// postgresql {
import { resolve } from "path";
// } postgresql

// mongodb {
// eslint-disable-next-line import/no-extraneous-dependencies
import { MongoMemoryServer } from "mongodb-memory-server";
// } mongodb

// postgresql {
import { Sequelize } from "sequelize-typescript";
// } postgresql

// mongodb {
const mongo = new MongoMemoryServer();

Expand Down Expand Up @@ -44,17 +38,3 @@ const mongoTest = {

export default mongoTest;
// } mongodb

// postgresql {
const DATABASE_URL =
process.env.NODE_ENV === "production"
? /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
process.env.DATABASE_URL!
: `postgres://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}@${process.env.DB_HOST}:5432/${process.env.POSTGRES_DB_TEST}`;

/* eslint-disable-next-line import/prefer-default-export */
export const testSql = new Sequelize(DATABASE_URL, {
models: [resolve(__dirname, "../models/*.model.ts")],
logging: false,
});
// } postgresql
27 changes: 0 additions & 27 deletions backend/typescript/umzug.ts

This file was deleted.

0 comments on commit 4368df3

Please sign in to comment.