Introduction to SQLC and how to use it with Fiber

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Just a simple video about how to use sqlc. Really love this lib so far and did want to share it with you :) sorry for the mistakes was live code :)

👍︎︎ 1 👤︎︎ u/EQuimper 📅︎︎ Aug 11 2020 🗫︎ replies
Captions
hello everyone welcome back to my channel in this video i'm gonna give you a little introduction about sqlc so it's a new package to help you working with sql uh it's pretty nice i'm gonna show you that plus i'm gonna just show you or you can install that to uh fiber so this is the library i've showed you in some of the past video so uh see uh sql c it's a way for you to finally you're gonna write your sql query and they're gonna do the sql code you will have done by yourself if you would have done it with the standard library it's pretty nice really good work really well and i've started using it like maybe three weeks ago and i'm gonna just show you how you can use it and doing some stuff with that so um for this video i'm gonna just use this youtube go fiber introduction a video i've give you uh 17 days ago and you're gonna just need to clone this code so after it's cloned uh for me i decided just to delete the git and restart but after that uh the only thing you're gonna need to do it's a rinse install your dependency you can do a go mode tidy or go mod install whatever you want to go and after that when it's done you can open that inside your um your um text editor of choice in my case i'm using a golan and you're gonna sit like you just have like a uh just one package so it's pretty simple and we're gonna also need postman and we're gonna need also another tool called go migrate so uh we're gonna start with that so in the video we've done a plain to-do list application where we are able to if we look at the route get the to-do's create the to-do's get it to do delete the to-do and updated to do so finally the crowd so now we would like that to not be uh in memory but doing this from a database perspective so for that all we're going to start is by working first with the migration so um the way um though with this go migrate work it's we're gonna make use of the cli so if you go to go migrate and you make use of the cli you can install that by doing brew install gold and migrate i've already done that you should do you should do this but if you if you have already you don't need so windows or whatever you can just follow that and for that also what we're gonna do for helping us is we're gonna create a file and make a file file finally and what is a make file file it's gonna let you use uh your command you're gonna create there so for those examples who like me come from node.js and stuff like that we do a lot of the script from the package.json and stuff like that but now we make file you can kind of do the same thing but with that and what i like about this make file it's it's really easy to do like something like uh make migrate and stuff like that and this is what we're gonna do so the first thing i want to do is i want to create a command called migration so we we need to create migration and this command is going to be about creating a migration to our database but before that you should create a database and for this tutorial i'm going to use postgres uh you can use my sequel whatever but i'm gonna use postgres plus sequel c work much better with postgres i know they have start to add some my sequel thing you see in version 1.5 they add my sequel engine but you should go with puzzle grass so this is something i forget to say you want to use sql c if you use postgres and my sequel just start to get this uh some love from them so for the migration here what i'm gonna type you can read that online and all that's gonna work but uh the first thing i'm gonna just create a db so we're gonna just say a fiber to do that something like that okay so here that's gonna create a db uh fiber to do that and if i open that with postico so if i go to localhost and i go to a fiber to those dev you see as nothing so for the migration the way that's going to work i'm going to just use read so read here i'm going to let the you find it i'm going to prompt the user enter a migration name this name here i'm going to be able to prompt that to the user the user going to be able to after that input some value and we're going to use this value to do some stuff and we're gonna call this uh variable name after that if you want to create a new line you put this uh i have no idea what is the name in english but that's backslash maybe and after that here i'm going to use migrate create so my great is going to be the goal and migrate so you see after you install gold and migrate you can do whatever you want from here so go and migrate create extension sql and now i need to say which directory i'm gonna call this directory postgres and i'm gonna put that inside a folder called migration and i want to use the name like that so the variable name so now i can run this command by doing make migration so for those who came from like arubian rails laravel django whatever you uh i don't think django but like laravel and stuff like that you can create a migration and put your name like that so this is what i'm gonna do from here and now i'm gonna simply be like uh create to do stable and all that's going to create the file for us and now you see for already they've create a folder postgres with a migration with to-do's up to those down perfect now here i'm gonna just configure i don't know why okay configure my data sorry it's just because i used golan so i'm gonna just use plus grass and i'm gonna connect my database my user is postgres my username is password postgres and my database it's fiber to do stuff i'm gonna test the connection when it's done perfect i'm gonna apply and okay perfect for the down i'm going to say drop table if exists to do that's going to be the name we're going to create the table here i'm going to create the table if not exist to do and now here i'm going to say the value i want to put so for the id that's going to be a big cereal and that's going to be a primary key so that they're going to um with big cereal they're gonna uh auto increment it up for us and we if we look back to the main that go we just add name incomplete so if we go back to the up name we're gonna say uh it's gonna be a text and we don't want that to be new and complete it's gonna be of type of boolean and by default it's to be false like that now i'm going to go back to my make file and i'm going to create here another command called migrate marguerite is going to be almost the same exact stuff but now we don't gonna create but we're gonna just migrate up the the the the financing the uh the migration so migrate we need to say which source and now i'm gonna say file slash postgres slash migration so this is the folder we want to get the the the element i'm going to create another line just to make it cleaner and i'm going to see the database it's equal to postgres slash postgres it's it's that for me so it's uh postgres locally postgres my username postgres my password uh after that one one two seven that one that's that's zero that root that want to be localhost the port 5432 and the database name it's fiber to do dev and we want the ssl mode to be disabled and we're gonna call up so up it's the command to migrate and just because we are there i'm gonna already show you how you can roll back so if you want to roll back just one you just need to call down finally and another one you can do also i like to do it's when i do dev i drop my db a lot of the time so i can restart from scratch and you just need to call drop perfect after that what i'm gonna do it's here i'm gonna create a sqlc command and we're gonna do this after that and uh here just because it's a typo but we don't care perfect so now we have our db and stuff like that so now i can migrate by doing my migrate who's going to call this thing now your secret table to do stable perfect and now i'm connect to this database so you're going to see if i go to the schema table i have my to-do's right there and i'm going to show you that in position for those who don't want to go land it's like that id and if you look at the structure we have here a big in because that was a big cereal we have a text for the name and boolean who default to be false perfect we're gonna create some to do for now uh walk the dog perfect and i'm gonna do another one here i don't know like a boy shoot i don't know i'm really bad in that so perfect so now we're gonna have two that's gonna be easier for us you know after that so all the wins are sqlc it's pretty simple you uh you can install that with uh go get the mac uh with ombre and everything so you should just follow this installation package [Music] in that package but stuff and for me i i did that with brew so you should do that or go get whatever the way you want to deal with that and after that what you want to do is go back to the setting and copy this stuff after that you need to create with sqlc in it this thing is going to create a sql cml file now from there you can add those package right there so i'm going to delete that and i'm going to put this thing you need to put in which package that's going to go so for our case that's going to go to postgres for that pad that's going to be postgresql the crew is going to be inside a postgres crew folder and for the skimmer that's going to be the um that's gonna be the uh migration uh finally the migration folder so migrations perfect after that the engine keep it as posgress images and tag for uh our case we're gonna say uh we can say that for true for now uh all the other stuff you can keep it as default and now after that what you need to do is go to postgres and now right there you're gonna be able to create a folder called query and inside this folder called truey you're going to be able to create your sql query right from here so inside this folder i'm going to create a file called to do's that sql and this to do that sequel gonna do all the query about the to-do's so finally you can create a sql file for each of your kind of models so here i'm gonna say and and the way that orphanage i forget to say that it's you do a comment and all you do i comment is by doing two dash you say name and now here i'm gonna say get all to do's so here that's gonna be the name of the function and go length i want after that here i need to say what i want to return if i say one that's going to be that's going to return only one to do but if i say many that's going to return us a slice now here i can say select out from to do's that's it so finally this query is going to be create and this job of the screen is going to be to get just everything from the table to do that's it and now because we did add inside a make file the sqlc generate now we can call that by doing make sequel c and now if you see sequel c generate looks like everything is working and now you're gonna see they're gonna create three file one of them is gonna be called model.go and model let go as you see it's the model create from the database so they have looked at your database so the one we have right there and they've looked at the thing you have inside that and they figure out the new id because you did use bigint is going to be equal to n64 their name now is going to be comment string and the complete because the complete if you look back at your migration can have a default file then it's nullable finally now they give you back sorry they give you back a new uh a sql new boolean because we did say in the sequel cml image is untagged to be true they've created this json tag right there so we're gonna use those it's gonna be easier for us after that they have created to do sequel that go so the to do sql that go is the code generate by sqlc1 from your query we just have one query so the one crew with this carl finally is this one all to do and as you can see they did select the id name and complete because that was everything from this table and they use the name we give in the um command get all to do and now get out to do just take the contacts and gonna return you back to do slides or whenever as you can see this code is what you will have create if you will have done the plain sql you will have need to get the rows after that to make sure you differ the rows after your error after that you will have initialized a slice of to-do's you will have look over each of the rows finally you will have create your row you will have scan each of the item finally and you will have append to your item checking your error and everything and after that you will have written everything so you see they just give you back 35 not 35 but like 20 line of code just for this query so it's really awesome and after that they have create a file called db that go oh this one don't gonna change a lot but his job finally it just to give you the abstraction over the sql package so the database sql package finally where they give you the new so they function new it's the important one the function new finally gonna give you back as truck queries would take the db so finally the thing you need to pass the new it's a connection database after you have your connection database inside the query this is where you're gonna have after that access to everything you need you're gonna see that in a moment it's pretty simple to use so now the thing i want to do it's for for me i don't want to use this db directly so what i like to do it's i like to create a file inside the repo called repo i'm inside the progress called repo and this is warfare and i'm gonna create a sorry a type repo struck and inside that this is where i'm going to put the currys and here this is how you can in go finally composite your strap so finally you're gonna kind of inject all the function from the queries inside your uh struct right there and inside that i want also to have a connection to my db who's going to be equal to a sequel that that db now after that here i'm going to create a constructor from this repo so i'm going to say generate constructor i want to pass only the database so i'm gonna pass this db i don't like the upper case in this case i'm gonna say db and this job of the repo is gonna be to create here a new uh repo pointer and for the queries this is where you're gonna call new and new ear just need to take the db because the new ear want to have an interface who accept the exact context prepare context query context and query context and these sql database sql database do have that if you follow ddb sql database they have uh they follow finally the interface asks for the new so it's pretty nice after that or you can connect that so if we go to the main.go here where we did a app where we have our function main this is finally where we're going to connect to the database and pass this db stuff so that way that's going to work it's going to be like that so i'm going to do before that i'm going to say db error it's going to be equal to sql that open and here i need to pass the driver so i'm going to say postgres and after that here i need to pass the data source name for the data source name that take a string so i'm gonna we're gonna construct that with the fmt spin f and inside this case we're gonna say db name equal print uh percent s because we're gonna pass a string password equal to percent s after that we're gonna pass user equal to percent s after that we're gonna pass sl cell mode equal disable and now we just need to pass the element we do one so in the case of the db name it's fiber to do dev become pretty messy i know that just because my phone is really really big so uh after that here we want to pass the password so in my case it's postgres after that the user is going to be postgres and you know what i'm going to just do this right from here so postgres great and now in this case we can just pass the the bit name after that i'm gonna check for the error so if we have an error in this case i'm gonna panic and pass the error i really want my db to connect and after that i have access to this dv now i want to create finally this repo i'm gonna say repo equal postgres that new repo and i'm gonna pass this db and now this is where i'm gonna manage now my uh database oh i'm gonna manage that so what we're gonna use it's what we call dependency injection finally or i mean i don't i'm not quite sure in go how they call that but finally we just want to pass this dependency all around our api stuff and the way that's gonna work to make it easier is we're going to create a struct here at the top called endlers and this truck handlers here is going to have a repo who's going to be equal to this postgresql i'm gonna create a constructor from that and now here i'm gonna create my handler right there so handler equal new handler and i'm gonna pass my repo now what i'm gonna do is you see all this route with this get to do create to do get to doing everything now they are gonna extend this they are going to came from this truck so if we go to get to do's now this is going to be a method from the h that antlers and what this thing's gonna do now if we go here and fix i'm gonna say um for this function here now what i'm gonna do is i'm gonna pass the antlers setup api one now i'm gonna receive here and large to be a type of anglers i'm gonna pass it there i know it's not the best don't worry you can change it and do it much better it just in this case we do the uh this way and now and there is going to be a tile available okay now it's fixed and now this get to doing glass now we want to return the to-do so how can we do that it's pretty simple we can say to do's and in this case i'm gonna say t [Music] it's because the to-do is a global variable okay we've done that here and i don't want to uh break all the code before we run it so i'm gonna say in this case tts for to do so i know it's really bad but and now i can say h repo and from my repo now i'm gonna have access to get all repo and now i need to have a context and now inside the fiber context we have access to a context and this context is the same context asked by get out to do and now i can check for the error if we have an error we can return status fiber http server error http server error maybe send i know it's not the best thing but we're gonna send the error we're gonna return else we're gonna return the tts here i'm gonna check for the error because i forget so uh what i can do to make it easier it's um doing something like that if we have another error here i'm gonna do like this perfect so now now if we go back to the top we get handler cannot use type pointer and layers too sorry about that that was a pointer type here it's a pointer type also sorry about that and now here no new variable on left replace with equal because the error now is create here at the top perfect so now i can create i can start the server now we get this error all new driver postgres now what happened is we forget to finally not really forget but the sql package here when they they start they need to uh i don't know if i'm gonna find it but they need to check at uh which driver you're gonna use so they don't have the driver like the sql package it's kind of like generic like they can use mysql sql line and everything like that and you need to tell them like which one you use and i don't gonna find it and it looks like i have a low memory so i'm gonna stop to looking at the code but the way that works finally is you need to say hey i want to use postgres uh you want to pass the postgres and for that what you can do it's in getup.com now leakedpq gonna sing the league pq to my uh project so you can just do go get uh get up that comedy pq and now i wanna i i don't gonna use nothing from them so because i don't want to use nothing i'm gonna just put the underscore because if i don't do that go gonna delete this import and the id is the lip pq it's gonna have an init method i'm not quite sure where i can show you but they're gonna have an in method where they're gonna um finally go with the sql package here and say hey use a r driver so now if i restart the project and i go back to postman and i do a get request now this is what we got we get what the dog and boy shoe so two things we get from the uh database but i think it's we get those uh those jason complete bull falls valley true and bullfar's valid true okay so the issue is because if you remember in the model we returned a sql null bull in a sequel you'll return a boolean and a valid valid is true if bull is not new so finally it's a way for you to check if null because i think it's null it's also falsies so so don't worry we can deal with that finally and the way i want it it's now inside my sql see i'm gonna image json to be false i don't want to deal with this thing anymore and now what i'm gonna do here is i'm gonna create a function called map to do's his job's gonna be here to receive a to-do who's gonna be uh it's gonna be a type of postgres to do and this thing's gonna return an empty interface because i don't really care about that type and his job here is going to be to return an inline struct where here i want to return the id as an n64 in the json i want to return id so i'm going to return a name a string json name complete a bull json complete and now here i can fill the element so in this case it's going to be to do that id to do that name and finally to do that complete the boot that's it and if you don't like to do uh this way of naming you can do like that and it's the same exact thing so map to do his job here is going to be is going to be my function who's going to be about creating the the response to the end user from the json stuff so now when i receive my to-do right there and that earbud in my main.go i mean i mean main netgo where is the stuff okay get to do it's right there when i return the tts now i need to look over each of them so i'm gonna create here a new slice and i'm gonna encrypt i'm gonna call that that's the thing i had the naming now it's getting really really bad but that's gonna be fixed when we're gonna remove those global variable and if i remember we can even no yeah we can't so uh i'm gonna call that interfaces is really bad i know it's gonna be a size of empty interface and here now finally i'm gonna arrange over the uh tts or the to-do's here we're gonna add the uh index and here i'm gonna receive that to do plus here i just think about that sorry i forget to do this it's we can make it much better by saying hey make a size on interface and for the length just use the length of the tts because that's going to be the same exact length so we don't need to have more to take more memories so now for the tts interface [Music] at this index is gonna be equal to map to do to do that's it and now this is what we return and you know what i just figured out a name as you can see i do this live with you so result and result i'm gonna restart the project i'm gonna go back to postman i'm gonna run and now you see it looks much much better so now if i go to postico and i change it to be true and i go back to postman and i click send now you see i get two and four as you can see the order is bad but you know what you just go to your sql and you can just say order by id example you we run your main sql c you rerun your server we shall have no change because the order by id don't take any argument and now if i send boom it always gonna stay like that it's equal so now how can we create a to-do so for that we're gonna say name create to do and this thing is going to only return one to do because you can rate just one finally and that would work it's pretty simple you goodness it's equal so insert into to-do's i want to insert name and i don't care about complete because by default i want always that to be false because what you will added to do if already complete and for the values you just put like a dollar sign one returning everything this is what i want to do because i want to return one so value one and now if i run the sql c generate what's gonna happen is this one is gonna become an argument we can pass so now if you go back to your to-do sequel now they've created a new function called create to do and i'll agree to do take the context as the other one but also take a name a type string and this is gonna return her to do n or an error and as you can see they do all the job for you so now you go back to your main.go you find where you did create the to-do you're gonna wrap that as a method to a pointer anglers and now the way you're gonna create the to-do you remember we did that right there last time so now what you can do it's remove this logic and just do to do error is going to be from h.repo the create to do you pass it the context from fiber for the name you pass it from the body that name it's from this uh right there with the body parts or stuff if you have an error is not nil you can finally send a ctx status uh fiber that i don't know in this case we're gonna still send that you should work with this those errors it's really bad i know our error we don't care in this tutorial and finally we have back the to-do but we don't want to return the to-do we want to return a map of the to-do like that and now here i'm going to just make back the return error best practice like that and now if you rerun i think we're gonna have an error you get on the front grid to do because the crit to do now came from the end logs i'm gonna rerun perfect now i'm going to go to postman i'm going to go to the body as you remember if we send remember it's a post if you send nothing we should get cannot parse json because where that fail right now is this place we get a fan on the body part store so i'm returning a better request with cannot force json so that just told the end user then the json is bad so now if i send an empty object we get id name complete because we don't do any kind of validation so now if you look to your database you see we get name and everything uh with nothing i'm gonna say i don't know like it walk the cat i know i i did say that last time so so now you can do some check yeah whatever and doing like like if land that name it's smaller or equal of two uh just do back this error and you say name not long enough something like that you save i know it's bad but for this tutorial now if i send back that name long enough perfect now i can pass a name sorry name walk the fish you know so perfect and now it's safe to database that's perfect they're complete it's false because remember it's plain sequel or migration we did say default false that's it now i would like to be able to get one to do by id because right now if i say to do one we get cannot we get walk the dog but the to do two it's about the cat but in real world it's boy shoes the issue it's because we still use the the global to-do's right there right there so what we're gonna do we're gonna go to get to do we're gonna add that to h and learn and now we didn't create the query yet so go back to your query i'm pretty sure now you're getting better get to do by id that's gonna be returning only one and now that's gonna be select everything from todos where id equal dollar sign one limit one we don't want to return more than one go back to your terminal makes equal c discrete to do sql uh to do sql um curry called get ba to do by id they know the id is gonna be in 64 because the id is a big cereal so they do this it's pretty simple go back to you get to do you don't need to do any more this bad logic stuff we did in the last one to do error you do age that repo that get to do by id you pass your contacts from five bar you pass the id you did create from the atoy but the issue is the id it's only a hint so what you can do is wrap that inside in 64 to create it in 64. after that you check for the error if you have any kind of error i don't know like if you have any kind of error just return like error that error in this case really okay and else we have the to-do so now we can do cd x okay yeah so if we have an error we can return that else ctx etc fiber okay the json map to do to do and now you do your error and if we have an error ctx status fiber server internal error send error that error perfect refresh your screen we can add another get to do it's not that fun because now it came from the endler we start your project go back to postman now if i go to the two boy shoots but it shoots perfect so if i go to three walk the cap perfect and now if i go to something we don't exist 99 we get status 4404 that's perfect so now delete to do and update to do so it's plain sequel so again you start go back to your query delete to do by id and now in this case i don't want to return nothing so i'm going to go with exec and now here uh you you we're going to finally delete the element to do that it's delete from to-do's where id equal dollar sign what that's it so now go back to terminal mx equals c they're gonna generate go back that's the thing okay always make sure you after you generate you always go back that's the thing will generate code sometimes that thing can happen when you create new thing maybe something is gonna be not like what you think so go and look so they need to do delete from to do daily to do we're gonna just exit as you can see gonna just exit don't gonna do nothing else than returning an error now you go back to human.go now you go back to delete to do this thing now gonna take the h handler and now you go back here now you check for the error because the error variable is already created we can just do it like that now you see repo delete by id we pass the context and now remember we need to do the id in 64. if we have an error must be because it's not fun else if everything is working we're gonna send status sorry also here that should be sent that is fiber that no content that's it i'm gonna restart the project we're gonna have an error under finally to do go to this line because it don't came from the handler restart your server and now in post score i want to delete what the cat because it makes no sense i'm going to go back here do the delete and go with number three now we get two formal content if i refresh postcode number three is now delete if i go there and i delete 99 we get no uh no content but you should delete nothing we just get nowhere so that's a thing to check but yeah it's uh yeah something to check also one of the things i think will be better in this case sorry about that would be to do sorry i'm sorry i never work with this 20 font size so it's really really big you see here ideally one thing i think it would be much more better is to get the to do first and see if the to-do exists so you should do something more like that you get further to do if the to-do exists but we don't want it and something like that and now you can run this code so you make you you're going to make sure finally then he exists so if i send 99 now we're getting a 404 but if i want to delete what the fish would don't make any sense also it's uh four two four and it's the that's perfect and now the last one is the update so in the update we're gonna say name update to do and i'm gonna want to return one finally and now what i'm gonna do gonna be update if you pass your table and now here you say the set like which value you can update so we can update the name after that we can also uh sorry i think i make a mistake once a name like that after that we can update the complete to be equal to the second one and don't forget you're aware because if you don't that's gonna update everything so that's gonna be number three and i think i like more the id number three the complete number two and the name number the name number to complete number three perfect go back to your terminal makes equal c now we get an error uh we thought okay yeah uh returning uh everything sorry perfect go back to you sqlc query now we should have an update update to do so they create this to do params as you can see take an id a name and a complete so you see they decide then now we have three arguments become bigger so why not create a struct it's easier and to uh to work with so now go back to humane go to your update to do we must be somewhere right there h and lar right there i'm gonna see to do error h dot repo the update to do context first argument is the id so that's gonna be the id again it's an hint we want it in 64. i know it's not a sorry about that it's a postgres the update to the params i'm gonna fill all fill so for the id is going to be now in 64 id the name is going to be equal to birdie that name and for the complete now that's the thing uh i know it's not the best thing for the value we're gonna see true and for the boolean yeah finally for the boolean here that's gonna be body dot complete the value and i know it's the best thing you can fix it and make it much more better for the valid it's what i mean by that is because this thing can become an available so you can check if if it's valid so you can do something like your body completely is not nail something like that so you can see if it's valid so now i'm gonna just remove all of those check for the error sorry if i have a lot of issue with the code here the code first was not created to show you this so sensations i don't know like [Music] not fun and i'm gonna return else map to do to do and i'm gonna return with the error and i'm gonna cctx and status fiber that internal server error that's send not sensory stories that is send error that error start a server i'm gonna have an error update to do don't exist go to update to do you add that you go back there you save and now make sure you check so by choose perfect so we're going to say by choose so i'm going to put back what the dog to be false perfect just to make sure it work i'm gonna do a get request you see what the dog is falls and boy choose so now i'm gonna say avwork the dog so i think it's a patcher i think we did a patch request yeah it's a patch request so patch request i want to update the one and i'm gonna say uh complete to be now true so now if i run invalid address of neil the reference okay i don't know what happened so as you can see we have an error and the error came from uh i think it's coming from this case so what happened here let me check really think it's because of like i think it's coming from this case okay so what you can do in this case it's i'm gonna add a debugger i'm gonna run that in debug mode it's live live code so sorry about that i have some mistakes i'm gonna run and now d-body it's name it's a pointer okay so i think this is here uh the issue okay it's because the name need to be passed so uh what you can do in this case i think i've done that in a bad way it's first thing i will get the to do i'm gonna copy this code you should create a helper get the to do first after that you should do what we've done before so if body that name it's not neil i'm gonna say to do that name equal the value of buddy name okay so now here what i'm gonna pass the name is going to be already a string now i can do equal and for the new bull i think we can go with just that so i'm going to save back and rerun the code and now if i run it now you work and now complete is true so you see we've debugged that together so now if i want because i don't know i have done a mistake it's supposed to be false perfect so i'm gonna do something to test i'm gonna do set to true and i'm gonna put name to be walk the fish and now we get back another error and now i think is this issue right there so what happened is this thing it's nil so we should go with the same idea so if buddy that complete it's not nil we should do to do that complete equal a sql new bull okay and for the bull now we know it's not nil finally so what i'm gonna do is i'm gonna say first it's valiant we know it's not nil and for the bull is going to be equal to now the d reference right there the value and now you can change that to be to do that complete that's it now you rerun your call and now if i send we get vulgar fish and complete stitu so if you understand what was the issue it's when i did that that to the pointer of the boolean with snail we did some nil and that was the issue so that's the way you can do this and it's better to do this to do get to buy id because you will update only if you can find this to do plus doing this to do get request with authorization gonna see if the user can update the to-do so i know the code is not all best practice but you have a better id so i'm gonna delete this to do slice and i'm gonna even delete this to do struck we don't need that i'm gonna rerun the code to see if something is breaking perfect nothing is break but now because i have the to do's delete i'm going to change here to be to-do it's going to make more sense i'm going to save i'm going to go back to postman i'm going to do a get request to get all the to-do's and i'll get walgreens and body choose so it sounds good so i'm gonna push the code in a repo and i'm gonna put the link in the description uh i hope you enjoy i really love sequel c as you can see i don't have the best experience yet but i just find like we missed some tutorial online so i think uh it's pretty nice uh in other tutorial i've used gopg i think now i will just use sequel c because that's the thing it's i like doing my sequel when i do my sequel i feel i have the full control and i don't want to have issue where i'm fighting against kind of like a oran ish where i'm looking for some function so this is the thing to check if i will um if you want to do something like more complicated than what you can do with sequel c sometime i'm going to just use the plain sql package because now we have the database connection because remember if we go with the repo inside the repo we have access to db so i can use that to make myself my own kind of curry and i'm going to use something like squirrel it's a way for you to do a creep builder if you want to help you like example you want you have some stuff you want to add only if some parents it's out from the user so this is one of the package i will have used if you have questions about the join and stuff like that i'm planning right now a video series about doing like a full stack application with next gs and golan for the api with fiber surely and we're gonna have the join with sequel c the way the joint work is it's the flat the structure so what's gonna happen it's example if you have a to-do and a user and you want to get the to-do's and you join the user to get all the information about the user that's all gonna be flat so they're gonna return you a struck we're gonna have to be like the name complete from the to-do and the id but after that they're gonna have the user id the user name and everything also it's gonna be flat so your job that's why like i show you the map to do you're gonna receive here the value example flat and after that you're going to just do something like maybe creating like a struck user right there something like that so this is the thing so hope you enjoy and let me know in the comment if you have any kind of question i'm sorry for all the mistake i've done uh but yeah it's uh that's the the beauty of live cutting so i hope you enjoy i'm gonna talk in the next one bye
Info
Channel: EQuimper
Views: 3,781
Rating: undefined out of 5
Keywords: javascript, react-native, reactjs, es6, nodejs, javascript (programming language), learn to code, coding, programmer, mobile app, application, equimper, graphql, golang, golang tutorial, sqlc, golang sqlc, golang fiber, go fiber
Id: xIqulnDQwp0
Channel Id: undefined
Length: 55min 2sec (3302 seconds)
Published: Tue Aug 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.