Skip to content

Instantly share code, notes, and snippets.

View vjrngn's full-sized avatar

Vijay Rangan vjrngn

View GitHub Profile
export async function transactionWithRetry<T>(
manager: EntityManager,
runInTx: (tx: QueryRunner) => Promise<T>,
options: TxOptions = { retries: 10 },
) {
const maxRetries = options.retries;
const backoffInterval = 100;
let tries = 1;
while (tries <= maxRetries) {
@vjrngn
vjrngn / contrived-di-example.js
Created February 13, 2022 10:36
Contrived JS DI
const User = require('./db/user');
const interface = {
find(id) {},
update(id, data) {}
}
// index.js or main.js
// const userRoute = requrie('./routes/users');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.introduction {
@vjrngn
vjrngn / Customer.java
Created April 24, 2019 13:26
Customer entity with updated relationship
package com.example.demo;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "customers")
public class Customer {
@Id
int id;
@vjrngn
vjrngn / Order.java
Last active April 24, 2019 13:27
Order entity with @OneToMany relationship
package com.example.demo;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "orders")
public class Order {
@Id
int id;
@vjrngn
vjrngn / OrderLineItem.java
Created April 24, 2019 13:07
Order line items
package com.example.demo;
import javax.persistence.*;
@Entity
@Table(name = "order_line_items")
public class OrderLineItem {
@Id
int id;
@Column(name = "book_id")
@vjrngn
vjrngn / Order.java
Created April 24, 2019 12:57
Orders of a customer
package com.example.demo;
import javax.persistence.*;
@Entity
@Table(name = "orders")
public class Order {
@Id
int id;
public Order() {
@vjrngn
vjrngn / Customer.java
Created April 24, 2019 12:54
Customer entity
package com.example.demo;
import javax.persistence.*;
@Entity
@Table(name = "customers")
public class Customer {
@Id
int id;
@vjrngn
vjrngn / BookRepository.java
Last active April 24, 2019 12:50
Book repository
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface BookRepository extends JpaRepository<Book, int> {}
@vjrngn
vjrngn / Person.java
Last active April 24, 2019 12:50
A simple model class using JPA
package com.example.demo;
import javax.persistence.*;
@Entity
@Table(name = "books")
public class Book {
@Id
int id;
public Book() {