Skip to content

Instantly share code, notes, and snippets.

View jidesakin's full-sized avatar
🪴

Babajide Owosakin jidesakin

🪴
View GitHub Profile
@jidesakin
jidesakin / uow-example.ts
Last active July 19, 2021 23:08
UoW Example
unitOfWork: IUnitOfWork = UnitOfWorkFactory::makeUnitOfWork('typeorm');
unitOfWork.start();
var work = () {
teamRepository = unitOfWork.getRepository(TeamRepository);
teamMemberRepository = unitOfWork.getRepository(TeamMemberRepository);
team = new Team('name');
teamMember1 = new TeamMember('John');
@Injectable()
export class UnitOfWorkFactory {
private readonly connection: Connection;
constructor(@Inject(TYPES.AsyncDatabaseConnection) connection: Connection) {
this.connection = connection;
}
static makeUnitOfWork(ormType: string): IUnitOfWork {
if (ormType === 'typeorm') {
return new TypeOrmUnitOfWork(this.connection);
@jidesakin
jidesakin / typeorm-unit-of-work.ts
Last active February 16, 2021 15:04
typeorm-unit-of-work.ts
export class TypeOrmUnitOfWork implements IUnitOfWork {
private readonly asyncDatabaseConnection: Connection;
private readonly queryRunner: QueryRunner;
private transactionManager: EntityManager;
constructor(
@Inject(TYPES.AsyncDatabaseConnection) asyncDatabaseConnection: Connection,
) {
this.asyncDatabaseConnection = asyncDatabaseConnection;
this.queryRunner = this.asyncDatabaseConnection.createQueryRunner();
@jidesakin
jidesakin / unit-of-work.interface.ts
Created April 20, 2019 12:49
Unit of Work Pattern + Repository Pattern
export interface IUnitOfWork {
start(): void;
complete(work: () => void): Promise<void>;
getRepository<T>(R: new (transactionManager: any) => T): T;
}
@jidesakin
jidesakin / postgres-brew.md
Created April 2, 2019 13:09 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@jidesakin
jidesakin / solution.php
Created March 2, 2019 19:24
Task 3 Solution
function solution($A, $K, $L) {
$maxAliceSum = getMaxSum($A, $K);
$maxBobSum = getMaxSumForBob($A, $K, $L, $maxAliceSum[1]);
return $maxAliceSum[0] + $maxBobSum;
}
function getMaxSum($A, $K) {
@jidesakin
jidesakin / utils.js
Last active March 26, 2018 09:32
Utility functions in JS
/**
Stringify null values in the an object
*/
const stringifyNullValues = item => {
const stringifiedItem = Object.keys(item).reduce(
(result, key) => {
result[key] = item[key] || "";
return result;
},
@jidesakin
jidesakin / slim-redux.js
Created January 29, 2018 11:49 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {