Skip to content

Instantly share code, notes, and snippets.

View vinipachecov's full-sized avatar

Vinícius Pacheco Vieira vinipachecov

  • VPV DESENVOLVIMENTO
  • Porto Alegre
View GitHub Profile
@vinipachecov
vinipachecov / getAuthors.tsx
Last active May 30, 2020 22:20
getAuthors callback from App.tsx in React-Native TypeORM setup
const getAuthors = useCallback(async () => {
const authorRepository = getRepository(Author);
let result = await authorRepository.find();
if (result.length === 0) {
const newAuthor = new Author();
newAuthor.birthdate = '10–03–1940';
newAuthor.name = 'Chuck Norris';
await authorRepository.save(newAuthor);
result = await authorRepository.find();
}
@vinipachecov
vinipachecov / app.tsx
Created May 30, 2020 22:18
App file for React-Native with TypeORM setup
import React, { useCallback, useEffect, ReactNode, useState } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { createConnection, getRepository, Connection } from 'typeorm/browser';
import { Author } from './entities/author';
import { Category } from './entities/category';
import { Post } from './entities/post';
const AuthorTile = ({
@vinipachecov
vinipachecov / post.ts
Created May 30, 2020 22:17
Posts file for React-Native typeorm setup
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToMany,
JoinTable,
ManyToOne,
} from 'typeorm/browser';
import { Category } from './category';
import { Author } from './author';
@vinipachecov
vinipachecov / category.ts
Created May 30, 2020 22:15
Category file for React-Native typeorm setup
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm/browser';
@Entity('category')
export class Category {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
}
@vinipachecov
vinipachecov / author.ts
Created May 30, 2020 22:11
Author file for React-Native typeorm setup
import {
Entity,
Column,
PrimaryGeneratedColumn,
OneToMany,
} from 'typeorm/browser';
import { Post } from './post';
@Entity('author')
export class Author {