Creating a Go API using an ORM - Tutorial

  Рет қаралды 72,743

TutorialEdge

TutorialEdge

Күн бұрын

👨‍💻 For the price of a ☕ every month, sign up and gain access to a growing list of premium courses on my site - tutorialedge.net/pricing/ 👩‍💻
● SUBSCRIBE to see more of my Videos & hit that LIKE button to support the channel!
Hi Everyone, In this tutorial, we'll be creating a simple REST API that interfaces with a sqlite3 database using an ORM.
Text Tutorial: tutorialedge.net/golang/golan...
‎● My Twitter ► ⁦‪ / elliot_f
‎● My Website ► tutorialedge.net
‎--------------
🎥 Recording Setup
Microphone - amzn.to/3hvASys
Mic Boom - amzn.to/3o0cW8Q
Mouse - amzn.to/2WZMoZs
Monitor 1 - amzn.to/38IUlYy
Monitor 2 - amzn.to/3rBTZf7
Mount - amzn.to/3o3185V
USB-C Hub - amzn.to/3o2xRbw

Пікірлер: 72
@aryanshmahato
@aryanshmahato 3 жыл бұрын
Will have to say, this tutorial is really clear and to the point. I love it!
@abubelal2553
@abubelal2553 5 жыл бұрын
Another great video! I'm learning go, your channel has helped a lot.
@farazfazli
@farazfazli 6 жыл бұрын
Hey - cool video! Just a small note - you should just be opening your database once in your program, not every single time a method gets called. Once you've connected to the database in the InitialMigration method, you can use the same global db reference in other methods. Put the single defer close call in the same method as your HTTP router so that the database remains open as long as the web server is running.
@JoseGomez-yw7ws
@JoseGomez-yw7ws 5 жыл бұрын
Aside from this, I wanted to comment that it is a pretty bad idea to use data from URL to create and update models. It's best to use the response body, or form data. The routes can be more standard as well, using `/users` for listing and creating users, and `/users/{id}` to deleting and updating; all four of these using different HTTP methods.
@Suriprofz
@Suriprofz 5 жыл бұрын
@@JoseGomez-yw7ws indeed first thing i was thinking
@MrFancaR
@MrFancaR 4 жыл бұрын
What if we run all the methods asynchronously?
@davindervirk6388
@davindervirk6388 4 жыл бұрын
What does this like, and how do you call db.Find in the user.go getAllUser func
@angelemmanuel287
@angelemmanuel287 3 жыл бұрын
I know Im pretty off topic but does anybody know a good website to watch new tv shows online ?
@kristofmarsi5883
@kristofmarsi5883 4 жыл бұрын
Thank You, this tutorial was awesome. :)
@WolfBoy2700
@WolfBoy2700 5 жыл бұрын
Lovely and clear! Thank you.
@kamrannazir2563
@kamrannazir2563 5 жыл бұрын
Thanks for this great tutorial. Love your accent!
@_JS96
@_JS96 4 жыл бұрын
I've honestly been pretty "ORM is for people who can't be bothered to learn SQL" but damn is that a lot faster on projects where you don't need finely tuned SQL wizardry. Definitely going to be investing some time into GORM. Great tut! Thanks.
@danielkurniadi8805
@danielkurniadi8805 4 жыл бұрын
"ORM is for people who can't be bothered to learn SQL" is very wrong. The fact is that when you have complex application, do you really want your codebase to be littered with SQL string all over the place? No one build resource-API without ORM. Let it sink to those ignorants.
@igniz87
@igniz87 6 жыл бұрын
HI, great job on the video :) . the explanation is very clear and easy to understand.
@Tutorialedge
@Tutorialedge 6 жыл бұрын
Hi there! I am glad you liked it, thank you for your kind comment!
@JosipCodes
@JosipCodes 6 жыл бұрын
Hey, just dropping in to say great job with this video! There are some things, as Rafael mentioned, but I totally understand why you wanted to be explicit and make things really simple. Kudos, and keep it up!
@Tutorialedge
@Tutorialedge 6 жыл бұрын
Hey Josip, I really appreciate the very kind feedback! Thank you, sir!
@eduardofernandezdiaz5264
@eduardofernandezdiaz5264 4 жыл бұрын
Josip Opačić exactly... keeping the cognitive complexity low by keeping everything as simple as possible, nice tutorial... good intro to gorm, I’ll subscribe his channel now
@grzesupel
@grzesupel 5 жыл бұрын
Great tut. Thanks!
@gcstang
@gcstang 6 жыл бұрын
Great Job!
@carlosjunior5371
@carlosjunior5371 3 жыл бұрын
Very helpful! Congrats
@MainakKundu19
@MainakKundu19 3 жыл бұрын
Very good explanation. Thank u... :)
@antonioguilherme1844
@antonioguilherme1844 3 жыл бұрын
very good. Learning quickly with you! I am brazilian!
@achantas7072
@achantas7072 3 жыл бұрын
Thanks for this video. very nice explanation
@zeldris6218
@zeldris6218 3 жыл бұрын
Thanks a lot
@dayunwang5905
@dayunwang5905 4 жыл бұрын
Nice video!!!
@jjopzy
@jjopzy 5 жыл бұрын
this is great! is there nosql tutorial also? :)
@rabhisalim3357
@rabhisalim3357 4 жыл бұрын
15:00: In order to see data in postman you can insert some dummy data like this one : " insert into users values(1, time('now'), null, null, "foo","foo mail"), (2, time('now'), null, null, "bar","bar mail"); " after typing sqlite3 test.db
@naeimwtg
@naeimwtg 5 жыл бұрын
HI, great job!!! how create Longtext in sqlite if i want save big text data to database ?
@pmartin
@pmartin 5 жыл бұрын
Hello, sorry it's maybe late. But why do you declare a global Var err ? Why dont keep it in local scope ?
@KangJangkrik
@KangJangkrik 3 жыл бұрын
Things that I still confused: How do I organize Table Model, DAO, and other logic into separate .go files and directory? Is that possible? Thanks!
@donaldfrench3696
@donaldfrench3696 5 жыл бұрын
How can I get the current schema from gorm? Normally it is "SHOW search_path" and is an exec. Same with setting the current search_path normally "set search_path to newschema"
@letslearnabout4934
@letslearnabout4934 4 жыл бұрын
Great tutorial. But if you are using Windows you can't use 'go run *.go'. With Windows you should use 'go build && go-orm-tutorial.exe' (Change 'go-orm-tutorial' for your folder)
@shubhamrade9220
@shubhamrade9220 4 жыл бұрын
which is the golang best ide ..I need to learn this language.please suggest
@lfaoro
@lfaoro 5 жыл бұрын
The db is gonna close as soon as the Init function exits.
@Khisant1
@Khisant1 5 жыл бұрын
Hello, any possibility to have the code?, tnks.
@abslol8827
@abslol8827 6 жыл бұрын
ORM = object relational mapper (nitpick: you said managers)
@Tutorialedge
@Tutorialedge 6 жыл бұрын
ahh damn, good catch. Thanks for pointing that out!
@vitor90x
@vitor90x 4 жыл бұрын
Thanks
@mukhsin915
@mukhsin915 6 жыл бұрын
Why didn't you put this video into your golang playlist? :D
@Tutorialedge
@Tutorialedge 6 жыл бұрын
I completely forgot! I will add it when I get some free time! I appreciate your input
@mukhsin915
@mukhsin915 6 жыл бұрын
Great
@bvhdv
@bvhdv 5 жыл бұрын
👍
@champfisk5613
@champfisk5613 2 жыл бұрын
Where did you define the SQLite table? I see the definition when is open the table in SQLite but didn't see where it was defined in this tutorial.
@hyrdeshgangwar
@hyrdeshgangwar 2 жыл бұрын
I dont think in the code we need to define the table. It's one of the benefits of using an ORM. It maps your objects (structs in case of Go) directly to table.
@Tutorialedge
@Tutorialedge 3 жыл бұрын
Hi Folks! If you are interested, I've just recently finished a complete course on building a Production-Ready REST API in Go which you can find here - tutorialedge.net/courses/go-rest-api-course/ This covers everything from project setup and layout, testing, and best practices around things like versioning.
@mickiemouse4008
@mickiemouse4008 3 жыл бұрын
test.db contain data?
@jonasfelix7700
@jonasfelix7700 4 жыл бұрын
Amazing. But it makes me nervous that you don’t use completion most of the time :-D
@Tutorialedge
@Tutorialedge 4 жыл бұрын
I turn off code completion so that people can more easily follow what I'm demonstrating! I have gotten used to just typing everything out now thanks to it haha
@Letsboot
@Letsboot 4 жыл бұрын
@@Tutorialedge That's a good point. It's easier to follow if someone types.
@justin6173
@justin6173 4 жыл бұрын
can this also work with postgres?
@Tutorialedge
@Tutorialedge 4 жыл бұрын
It can indeed, the GORM documentation gives examples as to how you can connect to a PostgreSQL database :)
@codefun1630
@codefun1630 Жыл бұрын
problem in accessing function
@ricardoferreirasoares9693
@ricardoferreirasoares9693 2 ай бұрын
That triggers me all the noises of your keyboard and your breathing, but the content is good.
@mgd020
@mgd020 6 жыл бұрын
What editor is that?
@Tutorialedge
@Tutorialedge 6 жыл бұрын
Hi Matthew, it is visual studio code! I would highly recommend it! :)
@UAStriker
@UAStriker 6 жыл бұрын
Microsoft Visual Studio Code
@ajinkyax
@ajinkyax 6 жыл бұрын
Vscode + gocode + go plugin = ftw
@rafaelacioly3252
@rafaelacioly3252 6 жыл бұрын
You can use the init function on User file, this way you don't need to make the connection on every func. 🤓
@Tutorialedge
@Tutorialedge 6 жыл бұрын
Hi Rafael, I would agree this would be better in the long run, however for the tutorial I felt it may be better to be explicit in the way we handle the database within our functions.
@pradeep422
@pradeep422 5 жыл бұрын
10:43 THIS IS SPARTA!!!!!!!!!!!!!
@YosephTeki
@YosephTeki 5 жыл бұрын
hey what is inside the test.db? why there is no explanation about it?
@_JS96
@_JS96 4 жыл бұрын
I believe the whole idea of using ORM (Object Relational Mapper) is that you don't have to worry about what's in the DB anymore. The ORM handles that part for you, and you focus on only the data and business logic, as mentioned in the video.
@YosephTeki
@YosephTeki 4 жыл бұрын
@@_JS96 you got the point! thanks sir..
@sicko_drops
@sicko_drops 5 жыл бұрын
really bad practices shown... you dont build an app like this in real life.
@RobertoOrtis
@RobertoOrtis 4 жыл бұрын
Too many fails. LOL
@steliospapadopoulos4589
@steliospapadopoulos4589 Жыл бұрын
Can't compile this on windows 10 Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub by using go run ./
Golang Websockets with Socket.IO tutorial
11:45
TutorialEdge
Рет қаралды 50 М.
Understanding Contexts in Go in 5(-ish?) Minutes
15:14
TutorialEdge
Рет қаралды 60 М.
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 17 МЛН
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 63 МЛН
Получилось у Миланы?😂
00:13
ХАБИБ
Рет қаралды 4,6 МЛН
Working with JSON in Go - Tutorial
14:14
TutorialEdge
Рет қаралды 42 М.
Go REST API With GIN & GORM | Postgres | Docker
28:17
Mahesh Kariya
Рет қаралды 18 М.
Build a REST API in Go using Fiber + GORM
1:28:30
rithmic
Рет қаралды 39 М.
Go + Microservices = Go Kit [I] - Peter Bourgon, Go Kit
38:49
CNCF [Cloud Native Computing Foundation]
Рет қаралды 102 М.
DONT USE AN ORM | Prime Reacts
25:46
ThePrimeTime
Рет қаралды 218 М.
Go API Tutorial - Make An API With Go
38:03
Tech With Tim
Рет қаралды 173 М.
Beginners Guide to gRPC in Go!
18:15
TutorialEdge
Рет қаралды 132 М.
I Would Never Use an ORM, by Matteo Collina
25:26
JetBrains
Рет қаралды 70 М.
I would never use an ORM - Matteo Collina | NodeConf EU 2022
37:43
Create A Simple RESTful API With Golang
21:53
The Polyglot Developer
Рет қаралды 84 М.
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 17 МЛН