TypeORM v0.3.x Migrations, queries, with NestJS!

Поділитися
Вставка
  • Опубліковано 5 жов 2024

КОМЕНТАРІ • 200

  • @lukramingo1496
    @lukramingo1496 Рік тому +7

    I have been stuck for two days typeorm migration generate, now you save my life...........Please create more videos about nestjs for new versions upto date👍

    • @RezHimself
      @RezHimself Місяць тому

      same happened to me, thanks

  • @mikoajrenke2985
    @mikoajrenke2985 Рік тому +4

    Thanks for sharing this!
    The documentation regarding this Topic is currently so insufficient that I was really struggling...
    With this Tutorial, it all went smoothly!

    • @mariusespejo
      @mariusespejo  Рік тому

      Yeah the typeorm docs are really bad at the moment.. glad the video helps!

  • @shakapaker
    @shakapaker Рік тому +11

    Please don't stop making videos, your way of explaining it's amazing 😻

    • @mariusespejo
      @mariusespejo  Рік тому +1

      Thanks 🙂 I’ve been a little busy lately but plan to get back into it soon!

  • @biserivanov3433
    @biserivanov3433 Рік тому +1

    I have watched many similar tutorials how to do migrations and your is by far the best one. Thanks for the great content.

  • @tkchannel5856
    @tkchannel5856 2 роки тому +2

    Thank you for this vid, after your previous one on TypeORM i had problems with migrations on CLI v0.3, finally there is a somewhat complete guide on new version

  • @Yoshgunn
    @Yoshgunn Рік тому +1

    Definitely would love a Query Builder crash course one day!!

  • @eugenematsetska8406
    @eugenematsetska8406 4 місяці тому

    after this video things with nestjs and typeorm going much better. THANK YOU MARIUS.

  • @ron-almog
    @ron-almog Рік тому +1

    Yes, it works, finally! thank you for clarifying the tricks of the new version!

  • @tonyeneh8194
    @tonyeneh8194 Рік тому +1

    you're soo good with explaining stuff. You have a way of figuring out questions that would crop up in viewers minds and then answering them just as they come up. Keep it up bro 👏👏👏

  • @syedumairnaeem6724
    @syedumairnaeem6724 2 роки тому +3

    The way you explain complex stuff is just amazing. Learned a lot about nest and testing from your videos. I was looking for a tutorial on migration and here it is. Much appreciated.

    • @mariusespejo
      @mariusespejo  2 роки тому +1

      Thanks for the feedback 🙏

    • @mohammadumar443
      @mohammadumar443 Рік тому

      @@mariusespejo how can we do DB first using typeorm and nestjs ? I just want to connect to DB and write APIs with the data in the DB.

    • @mariusespejo
      @mariusespejo  Рік тому

      Not sure what you mean by DB first. With typeorm you would typically create entities representing your database tables, then you can connect and write APIs. I have several videos on nest and typeorm if you check the channel

  • @mutaqinyusuf2190
    @mutaqinyusuf2190 Рік тому +1

    You are just amazing, straightforward and I barely can understand the points easily!!! Thanksss

  • @eugenematsetska8406
    @eugenematsetska8406 4 місяці тому

    best tutorial about migration for nestjs
    ** in my case was issue that i did use yarn+morepo - better use npm for run migrations

  • @ShadabIqbal-n2g
    @ShadabIqbal-n2g Рік тому

    I have watched your nestjs crash course in netninja's channel and from there, headed straight to your channel to learn typeorm. You have explained both of these concepts really really well. I have been a fan of yours, I would say. Thank you.

    • @mariusespejo
      @mariusespejo  Рік тому

      Thanks! Glad you’re finding the channel useful

  • @RafaelPascual
    @RafaelPascual Рік тому +3

    Hi Marius, I'm wondering why I can't find you in udemy. Your tutorial is more robust, easier to understand and more useful in real-life situations than any tutorials I found there. Thank you so much for giving us free tutorials.

    • @mariusespejo
      @mariusespejo  Рік тому

      Yes all my stuff is free at the moment on youtube. Thank you for your comment!

  • @zackOverflow
    @zackOverflow Рік тому

    WOW!!! you killed it in just 28 minutes, I am a big fan. I love the accent, I love the swag. Everything is FANTASTIC!!! 👍💥

  • @vibekdutta6539
    @vibekdutta6539 2 роки тому

    I needed that omgggggg. Been watching ur vdos recently and my migrations were failing. Thanks a ton

  • @vsevolod_zorin
    @vsevolod_zorin Рік тому

    Oh man, thank you so much! Your work was not in vain. I wish you peace and goodness!

  • @Torres158
    @Torres158 Рік тому +1

    Great video! It helped me understand TypeOrm better.

  • @loiskouninef5014
    @loiskouninef5014 Рік тому

    Just want to say a huge THANK YOU.
    Navigating through your NestJS videos (and, of course, official documentations) really helped me understand the framework and build basic APIs with Postgresql.
    Can't wait to see what's up next!
    Again, thank you and keep up the good work :)

    • @mariusespejo
      @mariusespejo  Рік тому

      You’re welcome! Thanks for stopping by to comment 🙂

  • @permanar_
    @permanar_ 2 роки тому

    Finally my favs UA-camr!! I've been waiting for your new damn videos like every day, week, month 😭😂
    Whatever it is, it's just glad I've seen your channel seems like not getting hacked! Haha.
    Cheers mate!

  • @AliAliOxenFree
    @AliAliOxenFree Рік тому

    this is a very valuable video. all the other migration guides out there are for the outdated typeorm. even chatgpt is stuck on the ormconfig.json method which has been deprecated.
    thanks for the lesson!

  • @Pedro21Torres
    @Pedro21Torres 2 роки тому

    Glad to see you back, thanks for that video!

  • @ВасилийКоннов-е2х

    Красавчик!) Хоть где-то нашелся рабочий пример! Перед этим я перерыл уйму статей и форумов.

  • @FlavienBesseau
    @FlavienBesseau 2 місяці тому

    Thanks man. Even chatgpt was bad to help me with postgres and typeorm

  • @mouadelhilali2082
    @mouadelhilali2082 2 роки тому +1

    Finally !!! LOVE YOU

  • @davidferreira3926
    @davidferreira3926 Рік тому

    finally i undertand. Thanks bro

  • @muawallaceewi8410
    @muawallaceewi8410 10 місяців тому

    Super amazing clear tutorial, thanks very much for the great job done

  • @gptwisdomtalks
    @gptwisdomtalks 2 роки тому

    Welcome back , waiting for your microservices tutorials

  • @bayalesko7956
    @bayalesko7956 Рік тому

    Great content and quality is up level. I knew you with this video @Marius Espejo and now wait new videos :) Great job!

  • @mateusz6260
    @mateusz6260 2 роки тому

    Thank You for come back.🥳🙂

  • @pierreaillet9249
    @pierreaillet9249 5 місяців тому

    Thank you so much man, very helpful

  • @emadzaheer
    @emadzaheer Рік тому

    Flawlessly explained!

  • @a.anvarbekov
    @a.anvarbekov Рік тому +1

    This was a desired update for the older video! Could you brother make a deployment tutorial as a next step for this, please?

    • @mariusespejo
      @mariusespejo  Рік тому +1

      There’s a lot of ways to deploy a node app but definitely something I’d like to cover at some point

  • @veritatas678
    @veritatas678 2 роки тому +1

    Cool explanation of typorm.
    could you maybe do a video on platformatic ?
    It recently came out and is basically an ORM that also creates CRUD endpoints + graphql.

  • @heisenbergyt49
    @heisenbergyt49 Рік тому +1

    +1 for QueryBuilder..

  • @Unifono2012
    @Unifono2012 Рік тому

    Great tutorial, thank you!

  • @soroushmadani
    @soroushmadani Рік тому +1

    That was amazing!
    I have a question though, I am using configService in datasourceOptions. I couldn't do the same for configService (new ConfigService(configOptions)).
    What am I supposed to do?

    • @mariusespejo
      @mariusespejo  Рік тому

      ConfigService (or pretty much most things in Nest) is not meant to be instantiated with “new” like that. It’s meant to be injected by nest. I suggest taking a look at the config module docs

  • @BRP-Moto-Tips
    @BRP-Moto-Tips Рік тому

    nice. thanks!

  • @NicolaMazzocato
    @NicolaMazzocato Рік тому

    Thank you for your help! :)

  • @eleshovictor1963
    @eleshovictor1963 2 місяці тому

    Please do a detailed video of the Query Builder

  • @purushothamag3898
    @purushothamag3898 Рік тому

    Very very informative please made video on dataseeder

    • @mariusespejo
      @mariusespejo  Рік тому

      Typeorm doesn’t directly support seeding, you can use migrations to pull it off or a 3rd party tool

  • @NursultanBegaliev
    @NursultanBegaliev 6 місяців тому

    Thank you!

  • @aleksazivkovic2792
    @aleksazivkovic2792 2 роки тому

    I would like a deeper dive honestly

  • @alexandrecastro9528
    @alexandrecastro9528 Рік тому

    You saved a Brazilian intern!

    • @mariusespejo
      @mariusespejo  Рік тому +1

      Haha great! Hope your internship goes well!

    • @alexandrecastro9528
      @alexandrecastro9528 Рік тому

      @@mariusespejo Man, the migrations part isn't clear on docs. The NestJS docs basically says: Go to see the typeorm docs. And the typeorm docs don't consider the Nest Pattern ( typeorm module). So, it was impossible to instantiate a datasource that both recognized and it was possible to specify to cli the typeorm where it was. I'm really grateful 👏💪🏻

  • @vincenttosinmicheal4640
    @vincenttosinmicheal4640 10 місяців тому

    Thanks a lot.

  • @IrshadahmedJakati
    @IrshadahmedJakati Рік тому

    Nice!

  • @emmanuelawolusi9343
    @emmanuelawolusi9343 Рік тому

    this helped a lot... thank you

  • @asmaakhalidy3775
    @asmaakhalidy3775 2 роки тому

    Yes, could you please make us a video about query builder 🙏!

    • @asmaakhalidy3775
      @asmaakhalidy3775 2 роки тому

      I wanna thank you for your very helpful videos 😊.

  • @nash-u6f
    @nash-u6f Рік тому

    Hi. I prefer the theme you are using! Which theme of editor and icon are you using?

  • @Medivelias
    @Medivelias Рік тому

    Hi Marius, thanks for your tutorial, it helped a lot! I was wondering which masOS terminal you were using?

    • @mariusespejo
      @mariusespejo  Рік тому

      That’s just iterm, but I use things like oh-my-zsh to add basic plugins like syntax highlighting and autocomplete. I’ve also been trying out Warp recently, check it out!

  • @beatrizpatricio9892
    @beatrizpatricio9892 Рік тому

    working fine thank you

  • @rahman9418
    @rahman9418 2 роки тому +3

    hi marius do you have udemy online classes for nest js ? are you interested in making it? because it's a good thing for developers, I want to learn it from beginner to intermediate or advance

    • @mariusespejo
      @mariusespejo  2 роки тому +1

      I don’t at the moment, you’ll find lots of free nest content in my channel though

    • @rahman9418
      @rahman9418 2 роки тому

      @@mariusespejo okay, but if you make it me and other developers might be interested in using nestjs for a real project, and it will be very good for its development, I'm looking forward to it on udemy, nestjs with a real project tutorial example, thank you

  • @eric55099
    @eric55099 Місяць тому

    U d best

  • @kakelayes1298
    @kakelayes1298 9 місяців тому

    good video

  • @sithumdilshan5878
    @sithumdilshan5878 Рік тому

    thank you

  • @kietne9251
    @kietne9251 Рік тому +1

    I dont understand why my migration ignores my entity. It does not generate newMigration. Only table "migraions" is generated in my database

  • @porbaixodospanos8989
    @porbaixodospanos8989 2 роки тому

    please don't stop

  • @fareedezzedeen8017
    @fareedezzedeen8017 Рік тому

    Thank for your unique contents and your excellent way to transfer knowledge.
    My concern about typeORM is how you trust a library when it's code repository has 1.7K open issues?
    Thank you again

    • @mariusespejo
      @mariusespejo  Рік тому +4

      Any reasonably popular open source project will have a lot of issues unless it’s backed by a good size dedicated team. For example a more modern alternative that I’d recommend also checking out is prisma. And even that has double the issues. Personally I’ve used typeorm in production enough that I think it’s a reasonable solution that works great with Nest. But nothing is perfect, you have to decide what tradeoffs you’re comfortable with.

  • @EstebanHelgueroCardiff
    @EstebanHelgueroCardiff 5 місяців тому

    Hi Marius! Question, how do you manage migrations in production? Do you run a GitHub action to apply the migrations to DB or do you have any other way to do It? Thanks

    • @mariusespejo
      @mariusespejo  5 місяців тому +1

      I’d suggest having a test or staging DB to test things out first. But then to apply it for production, pretty much yeah you can trigger in whatever pipeline tech you are using, assuming it has access to update your Database. How that is done honestly depends per company though

  • @artuturu
    @artuturu Рік тому

    Brillant :)

  • @TheBrownBox
    @TheBrownBox 2 роки тому

    Hi @marius, Thank you so much for the tutorial, but may I ask what font that you're using? :D
    Thank you very much!

    • @mariusespejo
      @mariusespejo  2 роки тому +1

      My default font at the moment is cascadia mono, it’s the same as cascadia code but without ligatures. It’s a free font check it out!

    • @TheBrownBox
      @TheBrownBox 2 роки тому

      @@mariusespejo THank you for your response!

  • @weekndninja
    @weekndninja Рік тому

    After execution of script no data is getting inserted to the migration table. Also how is the data getting inserted without any insert uery

  • @ICOReviewtoken
    @ICOReviewtoken Рік тому

    Hi bro. I want to setup multi tenancy 1 database and multiple schemas. each schema is generated from a subdomain and is unique. What I have to do ?

  • @mustafakendiguzel468
    @mustafakendiguzel468 Рік тому

    I am getting No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command error when try generate,do you know why is that happen?

    • @mariusespejo
      @mariusespejo  Рік тому

      Guessing your cli isn’t finding the entities, so there is no schema to actually compare with the database, which leads to not being able to generate anything

    • @denizsultanoglu6538
      @denizsultanoglu6538 Рік тому

      Kanka çözebildin mi sorunu?

  • @radosawhasiuk3478
    @radosawhasiuk3478 2 роки тому +1

    Hi, just a question. Why don't you use typeorm-ts-node-commonjs to run migrations on .ts files but instead you build the app and run it on .js files? Is there any reason for that or just preference?

    • @mariusespejo
      @mariusespejo  2 роки тому +1

      I did talk about that in the video actually, basically the nest app works off of dist when you’re running it, so if you reference ts files there it will error. The approach you’re suggesting is possible if you don’t share the same data source options between the app and the typeorm cli

    • @radosawhasiuk3478
      @radosawhasiuk3478 2 роки тому

      Thanks its clear to me now

  • @sarunmrzn
    @sarunmrzn Рік тому +1

    Hey Marius, great vid. I'm configuring migration for my own project and I'm stuck in this one thing.
    I've configured database object with config service, which works great in application, but for the migration cli, i cant seem to find a way to get env vars with config service, do you have idea how?

    • @sarunmrzn
      @sarunmrzn Рік тому +1

      the above doesn't work and the variable are undefined

    • @sarunmrzn
      @sarunmrzn Рік тому +1

      const configService = new ConfigService();
      const dataSource = new DataSource(databaseConfig(configService));
      export default dataSource;

    • @mariusespejo
      @mariusespejo  Рік тому +1

      hey Sarun, I don’t think the ConfigService is designed to run outside of Nest, which migrations are kind of a standalone thing if you think about it. You can install dotenv directly (which is what configservice likely uses under the hood) then just access your env variables via process.env

    • @sarunmrzn
      @sarunmrzn Рік тому +1

      @@mariusespejo Yep, apparently so. Was just wondering if there was a workaround without installing new package. Thank you so much for this!

  • @didierngabouwayo8424
    @didierngabouwayo8424 2 роки тому

    nice and simple explanation thanks, can you cover how to generate a custom auto-incrementing primary keys in typeorm such as CUST_0001?

    • @mariusespejo
      @mariusespejo  2 роки тому

      I think to pull that off you’d have to use entity listeners which allows you to add @BeforeInsert logic where you can do things like generate your own keys, add custom timestamps etc

    • @lugadev97
      @lugadev97 Рік тому

      You could create a sequence into a migration (remember the revert command into drop method) and request the sequence's next value throw typeorm query API.

  • @muratasarslan2359
    @muratasarslan2359 Рік тому

    Thank you, it's very helpful. github repo for this app?

  • @phimngantiengthai
    @phimngantiengthai 2 роки тому

    Worked, thx

  • @mehdimahmud5191
    @mehdimahmud5191 Рік тому

    Thank you for your great videos. on nestjs. Any tool available if I want to import all the stored procedures and entities from sql server database?

    • @mariusespejo
      @mariusespejo  Рік тому +1

      There are 3rd party tools like this one:
      www.npmjs.com/package/typeorm-model-generator
      Although other tools have much better first-class support for introspection, e.g. prisma, drizzle-orm, etc

    • @mehdimahmud5191
      @mehdimahmud5191 Рік тому

      @@mariusespejo thank you for the reply. I apretiate it.

  • @aleksanderradziszewski1242
    @aleksanderradziszewski1242 2 роки тому

    Hey, thanks a lot. Would you be so nice and make a video on how to set up the configuration for Postgres? Because it's not easy as seems to be.

    • @mariusespejo
      @mariusespejo  2 роки тому +2

      The only thing that would be different is you need to install pg
      npm install pg --save
      Then in your datasource config make sure to provide the required connection config
      If you need a reference you can create a sample project like this
      npx typeorm init --name MyProject --database postgres
      Compare you config with what that generates

    • @lugadev97
      @lugadev97 Рік тому

      @@mariusespejo I guess he is talking about use a .env to set the secrets and use it in datasource, that is right?

    • @mdtowhidulislam5260
      @mdtowhidulislam5260 Рік тому

      @@lugadev97 yes i am also facing the same issue with postgres.can you show an example for me?I will help me a lot.

    • @lugadev97
      @lugadev97 Рік тому

      Please let me know if I could help you to solve any doubt :) I also suffered to configure it
      PACKAGE JSON COMMANDS
      "typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli -d ./ormconfig.ts",
      "windows:migration:create": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli migration:create ./src/databases/migrations/%npm_config_name%",
      "migration:create": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli migration:create ./src/modules/databases/migrations/$npm_config_name",
      "windows:migration:generate": "npm run build && npm run typeorm -- migration:generate ./src/modules/databases/migrations/%npm_config_name%",
      "migration:generate": "npm run build && npm run typeorm -- migration:generate ./src/modules/databases/migrations/$npm_config_name",
      "migration:run": "npm run build && npm run typeorm -- migration:run",
      "migration:revert": "npm run typeorm -- migration:revert",
      "migration:show": "npm run typeorm -- migration:show",
      "schema:sync": "npm run typeorm -- schema:sync",
      "schema:log": "npm run typeorm -- schema:log",
      "schema:drop": "npm run typeorm -- schema:drop"
      ORMCONFIG.TS IN /
      import { ConfigModule } from '@nestjs/config';
      import { DataSource, DataSourceOptions } from 'typeorm';
      import dbConfiguration from './src/common/config/database.config';
      ConfigModule.forRoot({
      isGlobal: true,
      load: [dbConfiguration],
      });
      console.log(dbConfiguration());
      export default new DataSource(dbConfiguration() as DataSourceOptions);
      DATABASE CONFIG JSON
      {
      type: process.env.DB_TYPE,
      host: process.env.DB_HOST,
      port: parseInt(process.env.DB_PORT, 10) || 1433,
      username: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD,
      database: process.env.DB_NAME,
      synchronize: false,
      logging: false /*process.env.NODE_ENV !== 'production'*/,
      entities: ['dist/src/**/*.entity{.ts,.js}'],
      migrations: ['dist/src/modules/databases/migrations/**/*{.ts,.js}'],
      extra: {
      trustServerCertificate: true,
      },
      }

    • @mdtowhidulislam5260
      @mdtowhidulislam5260 Рік тому

      @@lugadev97 in package.json you use windows.migration:...
      is this solution only work for windows?
      I am using ubuntu

  • @mdtowhidulislam5260
    @mdtowhidulislam5260 Рік тому

    hey Marius Espejo, Can you please share the way for postgres? It would be really helpful for me.

  • @abolfazljalildoost766
    @abolfazljalildoost766 Рік тому

    please also make a *Microservices with Rabbitmq* tutorial , thank you

  • @simpsomk
    @simpsomk 11 місяців тому

    10:45 why do we need to use create method of repository before saving?

    • @mariusespejo
      @mariusespejo  11 місяців тому

      Save only works on actual instances of an entity

  • @randompointlessness2766
    @randompointlessness2766 2 місяці тому

    What about inmemory sqlite ?

  • @okeyshourovroy2769
    @okeyshourovroy2769 Рік тому

    How to do distance based search or geoquery in typeorm?

  • @masadamsahid
    @masadamsahid Рік тому

    Great tutorial, Marius. Big thanks
    But, how to enable .env variables in the db/data-source.ts?
    Of course we dont want to push our DB configuration to Github repo right?

    • @mariusespejo
      @mariusespejo  Рік тому +1

      Just like how you would in any node app, use process.env to access environment variables. You can also initialize a connection using TypeOrmModule.forRootAsync() which allows you to pass in either a class or a factory, both of which can inject the ConfigService (which parses values from .env, it’s basically dotenv)

    • @masadamsahid
      @masadamsahid Рік тому

      ​@@mariusespejo Oh, yeah. You're right. I think it's because of my own mistake. 😅
      I didn't import the 'dotenv' module properly using the asterisk symbol and 'as' keyword.
      The way I imported 'dotenv' before:
      import dotenv from 'dotenv'; // Not working. Bad ❌
      The right way I should did:
      import * as dotenv from 'dotenv'; // Worked successfully. Good ✅
      I dont know why both of them have different results. The first way is usually works fine in other Node projects, but does not work successfully in a Nestjs project.
      Anyway, big thanks for your tutorials and advices, Marius. 👍

    • @mariusespejo
      @mariusespejo  Рік тому

      Already gave notes above, take a moment to try and figure it out 🙂. If you rely too much on tutorials it’ll just limit your own growth. Take the time to trial & error

  • @kheangchea5689
    @kheangchea5689 Рік тому

    Thank you for your great video ! I have got questions . How can I config DataSourceOption that get value using .env ?

    • @mariusespejo
      @mariusespejo  Рік тому

      For nest specifically you would use the ConfigService for that, which needs to be injected so you need to do .forRootAsync for the typeorm module

  • @moezfazzi8337
    @moezfazzi8337 Рік тому

    thank you for the video please what is the extension of vs code to see the db

    • @mariusespejo
      @mariusespejo  Рік тому

      Sorry, I don’t remember the name of it, I’m sure if you search for database or sqlite viewer it will show up

  • @inanesilence
    @inanesilence Рік тому

    Migrations register automatically schema of the database or is it necessary to specify it in the query runner?

  • @carlosemmanuelarcosnovelo7711
    @carlosemmanuelarcosnovelo7711 11 місяців тому

    Thanks so much... I just have a question, if we have other databa different than sqlite and go to producction, how can set my password and user in the datasourceOptions. I tried to set my env variables but I got a error, it seems that the env is undefined

    • @mariusespejo
      @mariusespejo  11 місяців тому

      I suggest using the ConfigModule with nestjs, they have docs on it. It’s basically like dotenv

  • @jennifferorjuela947
    @jennifferorjuela947 Рік тому

    I'm working with providers for that conexion data getting from configService, but I can make connect to the database. Can anyone help me, pls?

  • @TylerJusCodes
    @TylerJusCodes Рік тому

    HI, i'm having issues .. when i want to create a migration , it can't find my entites. until i had to import them into the entites array.
    now i want to run migrations, and it can't find the migrations folder in the dist. but it's there

    • @mariusespejo
      @mariusespejo  Рік тому +1

      Assuming you followed the video exactly, then I’m not sure. Might want to ask in stackoverflow

  • @abrutii
    @abrutii Рік тому

    Seems like we can't pass in the config service to the DataSourceOptions object, that's really a pain in a situation where u have many Nest applications...
    e.g. I'm on a project that has libraries and many apps (not following the multirepository architecture of NestJs doc). I have a library that encapsulates TypeOrm logic and the config depends on the APP. I used to pass in configservice, but with data sources this changes everything

    • @mariusespejo
      @mariusespejo  Рік тому

      you can still do TypeOrmModule.forRootAsync(), which allows you to pass in a useClass (provider) or useFactory (function) both of which allow injection. That API is fairly standard to a lot of 3rd party modules, for cases when you need to initialize something async

    • @abrutii
      @abrutii Рік тому

      @@mariusespejo but you can’t pass it to the data source object in the data source file right ?

  • @eclipse-cmd
    @eclipse-cmd Рік тому

    It would be really kind of you if you can give us a link to the code repository.

    • @mariusespejo
      @mariusespejo  Рік тому

      Sorry no repo, this was really meant more as a quick lesson rather than a project to clone. If you need a written resource I recommend the docs

    • @eclipse-cmd
      @eclipse-cmd Рік тому

      @@mariusespejo thank you🙂

  • @afrosso
    @afrosso Рік тому

    Hi, why you don't use async/await in userService?

    • @mariusespejo
      @mariusespejo  Рік тому

      Unless you actually need to await the response and further process it before returning, there’s no need to. Nest will automatically “unwrap” your promises for you

  • @AbhinavKulshreshtha
    @AbhinavKulshreshtha Рік тому

    What would a good way to make this migration use .sql file for first import, instead of writing commands directly.

    • @mariusespejo
      @mariusespejo  Рік тому

      Don’t think it’s designed to work with sql files directly, just copy your sql into an initial migration file

  • @onrightside
    @onrightside Рік тому

    Migration:generate cmd generated a migration file which contains all the entities. it's a mess. Is there any way to generate separate migration file for each entity ?

    • @mariusespejo
      @mariusespejo  Рік тому +1

      That means you’re generating off of an empty database so that’s kind of expected. If you want it one at a time then make a new entity, generate, migrate…rinse repeat. You also can just split up that giant file yourself

  • @jonathanndambuki6216
    @jonathanndambuki6216 Рік тому +1

    Hello Take us on Query Builder Please.

  • @sumitmahajan5730
    @sumitmahajan5730 Рік тому

    Hey we are not able to create migration using nest 9.2.0 and node 16.13.0 can you tell us what is there reason

    • @mariusespejo
      @mariusespejo  Рік тому

      Not sure, did you follow the video? Otherwise please check the release notes of your dependencies

  • @KhoiNguyen-pm2jg
    @KhoiNguyen-pm2jg Рік тому

    Hello bro, thank you for your tutorial.
    I have a question, how can i create a migration using migration:create?
    I tried add "migration:create": "npm run typeorm -- migration:create", to package.json, but it not work. It throw the message "Unknown argument: d"

    • @mariusespejo
      @mariusespejo  Рік тому

      That means you didn’t provide the path to the datasource file. Take a look at how I have the typeorm script in the video

  • @biximi2625
    @biximi2625 10 місяців тому

    how do i activate the sqlite viewer in vscode, kindly reqesting for your help

    • @mariusespejo
      @mariusespejo  10 місяців тому

      It is just an extension, you can search for it in the extensions list and install the one you like

  • @samrat131
    @samrat131 Рік тому

    hi, how to use process.env.DB_HOST ... others env value in data-source.ts file? because when I use it shows undefined ! please help. thanks

    • @mariusespejo
      @mariusespejo  Рік тому

      You need to use the ConfigModule or you can use dotenv directly to populate those values for you. Basically have that environment variable actually filled and available by the time your app runs

  • @dendytbm3113
    @dendytbm3113 2 роки тому

    how to do refresh migration? start all over again at once, not revert one by one

    • @mariusespejo
      @mariusespejo  2 роки тому

      You can delete the records in the migration table and drop all your tables, or add a drop if exists on your migrations

  • @amerhamed1729
    @amerhamed1729 3 місяці тому

    Please Help after update the entities add colum or update name and try to run generate it give me create not alter and when i use migration:run i get sql error this table is already exist

    • @mariusespejo
      @mariusespejo  3 місяці тому +1

      Make sure your datasource config is setup properly. Generally how generate command works is it connects to your DB to figure out current schema, and compares it to your local entities to understand the diff. If your generate results in CREATE commands, that likely means you are connecting to a database where the tables were not yet created. Also you are still in full control of the SQL, if generate results in incorrect SQL you should correct it

    • @amerhamed1729
      @amerhamed1729 3 місяці тому

      @@mariusespejo i use "paths": {
      "@/*": ["./src/*"]
      } as config in ts config file can be this problem

  • @reymarkandog1441
    @reymarkandog1441 2 роки тому

    Which file icon and theme you are using?

    • @mariusespejo
      @mariusespejo  2 роки тому +1

      During actual work I usually use Monokai Pro, the icons come from that. However for tutorials I tend to use darker themes, in this one github dark

  • @anhuc8411
    @anhuc8411 Рік тому

    When I followed and posted I got an error "No metadata for "User" was found."

    • @mariusespejo
      @mariusespejo  Рік тому

      Double check that what you provided for entities in the datasource config matches what I have in the video. You’re likely providing the wrong path or file type, hence it can’t find the metadata for your entity

    • @anhuc8411
      @anhuc8411 Рік тому

      @@mariusespejo I succeeded, thank you very much 😍😍😍

    • @mariusespejo
      @mariusespejo  Рік тому

      Great!

  • @bombrman1994
    @bombrman1994 Рік тому

    do you have anything related to mongodb/mongoose etc how to use it with nestjs do we use it with typeorm. I am looking for some details and guidance at least minimal

    • @mariusespejo
      @mariusespejo  Рік тому

      Not at the moment. Nest does have docs on using mongo and mongoose, have you already looked at that? Although typeorm does also support mongo, I’m not sure why you’d use that over mongoose.. unless you have a need to connect to both mongo and a relational DB and want to use the same tool for both

    • @bombrman1994
      @bombrman1994 Рік тому

      @@mariusespejo thank you for clarifying it, I was not sure if they are a must to be used together or just some special cases. I just have a regular case where I need one of them. TypeORM was easy I followed you and now I’m digging MongoDB separately trying to get it work.

  • @Raihan004
    @Raihan004 Рік тому

    make one a Query Builder crash course please

  • @Cognitoman
    @Cognitoman Рік тому

    Hey quick question. I notice that in nest.js people do validation in the controller with Rules such as checking username to make sure it’s between 3-20 characters long, and then throw errors like in the pipe/controller to the front end with message like “username isn’t long enough”. My question should stuff like be conducted in the entity for validation ? Because that would be considered business rules. Wouldn’t make more sense in the controller/pipe just to check if data coming in looks correct and is of the right type ?

    • @mariusespejo
      @mariusespejo  Рік тому

      The recommended way to do validation is definitely in pipes which technically is “before” your controller, using class-validator annotations in your DTOs (which can be different from your entities)
      I covered that in this video ua-cam.com/video/2n3xS89TJMI/v-deo.html

    • @Cognitoman
      @Cognitoman Рік тому

      @@mariusespejo yeah I’m super surprised it’s done this way , because it’s business rules which should be in the domain layer . Not in the controller. Not your fault or saying your wrong it just seems like it should be done else where

    • @mariusespejo
      @mariusespejo  Рік тому

      It’s not in the controller.. the rules are defined on the DTO and the validation pipe does the check BEFORE it gets to the controller. You can register pipes on controllers or even globally, but the validation itself does not happen in the controller if you follow the recommendation. I think you’re maybe misunderstanding the flow.

    • @mariusespejo
      @mariusespejo  Рік тому

      Also important to understand that nest is really just a layer above Express, and pipes are really just middleware with a specific purpose. So if you took the same setup and did it in express, it’s like validating at the middleware that runs before your route handler / “controller”. Not sure if that comparison helps

    • @Cognitoman
      @Cognitoman Рік тому

      @@mariusespejo I watched it, yeah the DTO is the data transfer object, what I’m saying is I’m seeing people doing validation on the DTO, like checking a value for very specific things like “the date must be between this day and this day” using class validator, then they throw that value in the database, but what I was saying is that validation check on the DTO should belong on the entity not the DTO because it’s a business rule. Idk it’s just different the way I was taught. Not saying it’s wrong just different it has pros and cons