1.0.81 • Published 1 year ago

@redcap-konex/neat-orm v1.0.81

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Setup orm neat

Basic usage with typeorm 0.2

need to use the following ormconfig.js in the root of project

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const config = {

	type: process.env.TYPE,
	host: process.env.NODE_ENV === 'test' ? process.env.DB_HOST_LOCAL : process.env.DB_HOST,
	port: process.env.DB_PORT,
	username: process.env.NODE_ENV === 'test' ? process.env.DB_USER_LOCAL : process.env.DB_USER,
	password: process.env.NODE_ENV === 'test' ? process.env.DB_PASSWORD_LOCAL : process.env.DB_PASSWORD,
	database: process.env.NODE_ENV === 'test' ? process.env.DB_TEST : process.env.DB_NAME,
	entities: ['node_modules/@redcap-konex/neat-orm/dist/entity/**/*{.ts,.js}']
}
module.exports = config
import { Countries, OrmManagement,getRepository } from '@redcap-konex/neat-orm';

const { createConexionOrm } = OrmManagement;
createConexionOrm()
  .then(async () => {
    console.log("SE CONECTO EL ORM");
    const countryRepository = getRepository(Countries);
    const buildCountries = countryRepository.createQueryBuilder("Country");
    const res = await buildCountries
      .leftJoin("Country.banks", "banks")
      .addSelect(["banks.id", "banks.name"])
      .addSelect(["Country.id", "Country.name"])
      .getMany();
    console.log(res);
  })
  .catch((error) => {
    console.log(error);
  });

Basic usage with typeorm 0.3

import { Countries, OrmManagement,getRepository } from '@redcap-konex/neat-orm';

const neatOrm = new OrmManagement({
  type: process.env.TYPE as any,
  host:
    process.env.NODE_ENV === "test"
      ? process.env.DB_HOST_LOCAL
      : process.env.DB_HOST,
  port: Number(process.env.DB_PORT),
  username:
    process.env.NODE_ENV === "test"
      ? process.env.DB_USER_LOCAL
      : process.env.DB_USER,
  password:
    process.env.NODE_ENV === "test"
      ? process.env.DB_PASSWORD_LOCAL
      : process.env.DB_PASSWORD,
  database:
    process.env.NODE_ENV === "test" ? process.env.DB_TEST : process.env.DB_NAME,
});
const { createConexionOrm } = neatOrm;
createConexionOrm()
  .then(async () => {
    console.log("SE CONECTO EL ORM");
    const countryRepository = getRepository(Countries);
    const buildCountries = countryRepository.createQueryBuilder("Country");
    const res = await buildCountries
      .leftJoin("Country.banks", "banks")
      .addSelect(["banks.id", "banks.name"])
      .addSelect(["Country.id", "Country.name"])
      .getMany();
    console.log(res);
  })
  .catch((error) => {
    console.log(error);
  });

Get Conection usage

import { getConnection } from '@redcap-konex/neat-orm';

const conn = getConnection()

close Db Conection usage

import { getConnection } from '@redcap-konex/neat-orm';

const conn = getConnection();
if (conn.isInitialized) {
  conn
    .destroy()
    .then(() => {
      console.log("DB conn closed");
    })
    .catch((err) => {
      console.log("Error clossing conn to DB", err);
    });
} else {
  console.log("DB conn already closed.");
}

help migrations

npm run typeorm -- -help

init migrations

npm run typeorm:migrate init -- -d src/migrations

run migrations pendings

npm run typeorm:run

after this execute run

dont forgot update de package.json version

npm run deploy

When get migrations test db

put cross-env NODE_ENV=test in package.json ahead of typeorm:migrate and typeorm:run

Creating the initial data for superadmin

  1. npm run seed:config
  2. npm run seed:run

well practice when change or add field to table in database

npm run typeorm:migrate added_column_hola_to_users -- -d src/migrations

run test only one file example in windows

npm test src/tests/cities/cities.service.test.ts

1.0.81

1 year ago

1.0.80

1 year ago

1.0.79

1 year ago

1.0.78

1 year ago

1.0.77

1 year ago

1.0.76

1 year ago

1.0.75

1 year ago

1.0.74

1 year ago

1.0.73

1 year ago

1.0.72

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.60

1 year ago

1.0.59

1 year ago

1.0.58

1 year ago

1.0.57

1 year ago

1.0.56

1 year ago

1.0.55

1 year ago

1.0.54

1 year ago

1.0.53

1 year ago

1.0.52

1 year ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.49

1 year ago

1.0.48

1 year ago

1.0.47

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.40

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago