Advanced Godot | Integrating Postgres into Godot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys this is mitch with  fine point cgi and today   we're going to talk about integrating postgre into  godot so we're going to go through the process of   using docker to pull down our post gray database  and we are going to use a docker instance   to set up that database and then we are  going to go ahead and download and install   pg admin which is an admin tool that allows  us to interact with the database and then from   there we're going to pull down the add-on that  we need to use to connect to our postgre database   we're going to interact with that and do some  selections and some inserts and things like that   and that's what i have in store for you  guys today so let's go ahead and get started   okay so the first thing we have to talk about  is what is docker now docker is an open source   project for automating the deployment  of applications as like a portable   self-sufficient container that  can run on the cloud or on   premises now that's a lot of words and it's  kind of confusing what that means as a person   who did not understand docker when i first  started that made no sense to me and nobody   really made it make sense to me well the  easiest way to understand what docker is   is it's a virtual machine like you would say  virtual box or like you would say really any   other virtual machine application like hyper-v  or something like that but the big difference is   instead you have this thing called a container  engine and that container engine just emulates the   operating system that you're  running all these applications off so instead of emulating it  around you know different um   guest operating systems so  instead of you running let's say   like five linux virtual machines on your machine  instead you're running one and it makes things a   little bit easier and it's a lot more memory  efficient and it's just a better system   than the previous system with kind of an asterisk  there because it's not necessarily the best the easiest way to explain kind of  how it is is with a basic analogy so   let's say you have a deck of spreadsheets  right that each contain one paragraph   um issue these letters you need to pick some of  these sheets uh with the paragraphs you need so   you you stack them to align them and they kind  of read okay right and then you would just take   a photocopier and scan it right to be like this is  what i want and then you can make as many letters   as you would you would like that's basically what  docker is so you basically take these applications   and these layers you just kind of layer them  on top of each other to make your container   and that's pretty much docker in a nutshell why is  it better than running it locally on your machine   because when i'm done with whatever it is i'm  testing i can just crumple it up and throw it away   or i can save a state and say i like where this  is at so let me save this and then i can create   multiple versions of that exact machine  again without needing any additional work   so it saves a lot of time it's easier to work  with than virtualbox or things like that and   you know it's universally accepted so if you  were to test your application on your machine   and then you were to deploy it out on the  cloud it will work the exact same way because   it's a snapshot of your application and of the  machine environment right there so that's what   docker is so let's go ahead and download  it and install it and uh yeah go from there   okay so the first thing we're gonna do is we're  gonna go ahead and download and install docker so   let's go ahead and click download for windows  and let's save it i've already downloaded it   as you can see right here so let me just go ahead  and execute it so after you have it downloaded go   ahead and go to your downloads directory and click  on docker desktop installer and double click on it   all right so now it's going to go ahead and go  download all the packages it needs and we're   going to say hey install the required components  for wsl2 and go ahead and add a shortcut to your   desktop let's hit ok and it's going to go  ahead and unpack all the files it needs to   go ahead and install for you and it's going to  go ahead and install all of its virtual machine   goodness that you would expect from docker so i'll  be right back with you guys once it is completed   all right so we're going to go ahead and hit close  and it may or may not request you to restart in my   case it didn't but some people have been required  to restart so make sure that you go ahead restart   now for docker desktop to work you need  to have hyper-v enabled so make sure that   while you do that restart go ahead and enable  hyper-v and if you don't know how to do that   i'll leave a link in the description below for  some things that might be able to help you through   that process now let's go ahead and execute  docker desktop and let's see what happens okay   so we got an unhandled exception so it says hey  if you continue this then uh the application you   know will try to ignore this error hit continue  and you'll see that it says hey wsl install is   incomplete wsl linux kernel is now installed  under a separate msi package please click the   link and follow the instructions to get the kernel  update so let's go ahead and click on that link   let me resize this for you real quick and you'll  see that it takes us to the microsoft website now   the beauty of this is microsoft basically handles  most of this for you but first things first if   we scroll up to the top we need to enable the  subsystem for linux so let's go ahead and do that   so let's open up powershell as admin so make sure  you right click on it and run as administrator   now once you have an administrator powershell  window let's go ahead and grab our enable script   here so go ahead and copy that and paste it  and it'll go ahead and go out and uh pull all   of our subsystem for linux stuff and i'll put  the commands you need to run in the description   below so that way you guys don't have to go out  and do the docs system like what i'm doing here   now if i scroll down it says hey make sure you  check your requirements i know that i have that   let's go ahead and enable our virtual machine  features so let's go ahead and enable that   it's going to go ahead and run and download all  the stuff it needs and then we need to go ahead   and download a linux kernel update package and  what a current linux kernel update package is   is it is a install package again i will leave  a link to it in the description below so if you   double click on that and you go ahead and start  installing wsl we're gonna run through that real   quick it's a pretty quick install so it should be  five seconds there we are and we are going to come   down here and set wsl as our default version  so we'll say wsl set default version uh two   and that's going to set the default version and  the last thing that we need to do is we need to   install our linux distribution of choice so so  let's go ahead and click on this little button   here and it's going to say hey we want to open up  an application say yep and that's going to take   you directly to it now you get a choice between  the different linux distributions you want now   it really depends on what you're trying to do  ubuntu is awesome for ninety percent of the   stuff you want it's bleeding edge quote-unquote  it's not really but kind of leading edge kali   linux is offensive security testing so if you're  doing like penetration testing and hacking into   computers this is an awesome distribution for  that debian is basically ubuntu but more stable   and but the packages behind it are  less as new and then alpine wsl is   a small uh wsl based subsystem that can run linux  programs so it really depends on what you want   this is like a stripped down version of linux  this is full linux but stable and this is full   linux but less stable now i'm going to go ahead  and click ubuntu and just go ahead and install it   and go ahead and hit get and i'm not going to  sign in because i don't really want microsoft   to have my data now i'm going to hit install and  it's going to go ahead and download ubuntu or i   know some people call ubuntu or ubuntu it just  kind of depends on you know who you are and how   you want to say it i think the official way to say  it is ubuntu but i'm just gonna call upon two so   if you guys if you guys have a problem with it go  ahead and yell at me in the comments that's fine   and we are gonna go ahead and finish this  download so now we have ubuntu installed   so go ahead and click on launch and you'll see  that there is a little pop-up here that shows up   now ubuntu is going to go ahead and install all  of the things that it needs to operate so we're   going to let that run through and then we should  be good to go to actually start using docker   so it's going to ask us to enter a unix  username and i'm just going to put in   tour and my password is going to be tour tour  and that will work for me so what this does   is it gives us a full linux desktop on our  windows machine which is awesome for us in   the godot world because it allows us to test some  of our code without a gui at least on the linux   world which makes it a little easier for us to  um test if our code is platform cross-platform   which is an awesome cool little feature that  windows has now that we have all this we can   go ahead and open up docker desktop and attempt  to do it again so you can see how it says docker   engine has failed to start need to go down to the  bottom let me pan this for you guys real quick   you guys can see my little recording software so  if you come down here and we right click on docker   and we say restart docker and then you'll  see this little pop-up comes up right here and we are going to click restart and what that's  going to do is it's going to attempt to restart   our docker engine and you'll see a notification  that says hey the docker desktop is restarting great so now we have docker running you'll see  right here we have a nice little green button   here so now we can actually explore what docker  can do so this is where docker hub comes in okay   what docker hub is and if i go up here and i click  on it docker hub is a giant list of things that we   can use with docker and one of the cool things  is for instance you can see all these different   things that we have so i can ubuntu official  image right so if i wanted to create a linux   system that's running in the background right i  don't need to modify my actual machine i can just   spin up an image of that machine same thing with  like redress if i'm doing a data structure server   or a nodejs platform for doing web development or  like alpine which if you guys remember alpine wsl   is right here they have that or like my sequel  or busybox or postgres which if you guys don't   know anything about postgres it's an awesome  database you guys should definitely check it out   um they have like a python image and and all sorts  of stuff and i don't really want to get into too   crazy detail but one of the coolest things  about docker is that it allows you to spin   up multiple instances of the same thing so what  does that mean for us well what we can do is   we could make a server let's say and you could  take that server spin it up do your testing right   and then instead of needing to  uninstall your server you can just   spin up a new instance of that server as if it  was never touched so it really allows you to go in   modify stuff and then completely wipe away stuff  it also allows you to spin up multiple instances   or something so one of the things that i do at  work a lot of the times is we have to test um   our application against multiple operating systems  and we have to test our application against   multiple um interconnectivity uh operating systems  so like for instance a windows machine may need to   talk to a linux machine right so what i can do is  i can spin up a server and then spin up multiple   clients and multiple clients and have the clients  talk to each other and the servers talk to the   clients and verify that it all works and i can do  all of this on one machine instead of needing to   do this on multiple machines so enough about that  let's go ahead and just pull down our postgres   docker image which is why we're here right  so let's scroll down here let's find postgres   let's click on that and copy our command and then  let's go ahead and open up a command prompt here   and we will go ahead and paste our postgres poll  and let's go ahead and pull it and it may yep   there we go so now it's pulled down my uh postgres  image and you'll see how quick that was right it   just pulled it right down and now i have postgres  on my machine but i don't have it actually   installed because i don't need to because docker  just handles all of that for me all right now   that we have pulled our little um postgres image  we need to go ahead and create our uh container   right so we need to run our container so we're  gonna say docker run double dash name dev dash   postgres space dash e for environment variable  and we're going to say post grass gres   underscore pass word is equal to and then you go  ahead and put whatever password you want here now   in my case i'm going to put password dash p five  four three two colon five four three two and then   we are going to say postgres now what does all  this do okay so first things first we're saying   hey docker run and we're going to tell it that  we want to run the postgres image okay so there's   images and containers i believe i've already gone  through this but there's images and containers   and images are what containers are made of so  an image is what a container takes as its base   and then it builds upon that if that makes sense  we're saying we want to name it dev postgres we   want to set an environment variable in this case  it's postgres password and we want to make it   password and then we're saying hey let's link up  our ports so that this port is equal to this port   so the containers port of 4532 is equal to our  port of 4532 so let's go ahead and hit enter   and what that's going to do is it's going to go  ahead and calculate and build out our container so you'll see that's going to ask us for windows  or windows defender is going to yell at us let's   hit allow access so that way it has access  and you will see that now the database is   ready to accept connections so that's great  that means our database is up and running   so awesome now we need to get some kind of  way to administrate this tool so let's go   ahead and download pg admin so if you  come over here and then you click on   uh download and the link to this is in the  description below so go ahead and check that out   hit windows pg admin five six and then let's go  ahead and click on pg admin 5664. i've already   downloaded it so you can see it's right here  so i'm just gonna go ahead and hit cancel and   i'm gonna open up my downloads folder instead so  here's pg admin we're gonna double click on that   we're gonna click next i accept i'm not even  gonna read it because you know who reads that   and next and go ahead and hit install so let's  go ahead and let that run and i will be right   back okay we're gonna go ahead and hit finish  and then we are going to go ahead and open up   pgp admin whoops i did not click the right thing  all right now this tool takes a long time to load   so just go ahead and get a cup of coffee  or something and we'll be right back   all right so the first thing it's going to ask  is for your password just go ahead and throw in   whatever that password was and it's going  to go ahead and attempt to connect to your   postgre database which in my case  it totally did so that's awesome so   now that we have this let's go ahead  and talk a little bit about pg admin   pg admin is a tool that allows you to administrate  your postgre database like i said that's inside   that docker container so we have all these cool  little features and if you guys want me to go   through all the features i'm more than happy to  in a separate video but that would make this video   very long so our main concern is schemas  and our main concern is tables and possibly   procedures and functions but we might not get  to those so let's go ahead and go from schema   to tables let's right click create ourselves a  table and then let's go ahead and name it scores   or scoreboard it looks like it saved my stuff so  one of the things we have to know about postgre   is we need to keep our stuff lower case if  you do hot uppercase you need to use quotes   around everything and it becomes a nightmare  to manage so please use lowercases if you can   column let's go ahead and add in a column and  let's say id and then let's make it an integer   so if you just click on this integer and then  we're going to say not null primary key yes and   go ahead and add another one and then let's call  it name and let's say text and then let's go ahead   and add one more final one and say score and then  add in it as an integer awesome so the rest of   this we don't really need um most of this is just  stuff that you know can be useful like primary   keys foreign key check unique exclude things  like that how you're going to partition your data   how your data's parameters are going to be set up  how your security is going to be set up and the   actual sql that's going to be used to generate  this table now most of this is useless for us   to do just based off of what we're doing right now  but it is something that you guys could definitely   take a look at so let's go ahead and click save  and then we are going to go into our table and we   are going to right click on it and there should  be a way to query tool right here click on that   and then we are going to select star whoops star  from scoreboard if we go ahead and run that you'll   see that the table is empty so now we can do one  of two ways of putting data in we can put in data   by typing we can go one and then double click on  name and say find point cgi and say like i got a   hundred points let's say and then of course if  we click down here we can say two and we could   say something like like silent and say silent got  120 points because he's good at video games um or   we can do something like insert into scoreboard  and then we could say id comma name comma score   values and then we can go ahead and insert in our  values so we could do something like three comma nomad comma 130 right and then if we wanted to add  an additional one we could go ahead and do this   and say 4 comma victoria comma 150 right and  since these are strings we need to actually   have quotes around them and they have to be  single quote the single tick quote because if   it's the double tick quote postgre will take  it as this is a column or a table not a name   or a string so if we go ahead and hit  go whoops i clicked on the wrong thing   so because i did this out of order it's not  letting me run this query so let's just go   ahead and x run the query tool again and then  just paste this in and then we can go ahead and   run this and you'll see that it returned the  query successful so if we go ahead and select   star from scoreboard and then we go ahead and  we run that you'll see that we have our data   here so we have our little scoreboard awesome  so now that we have some data in our database   let's go ahead and jump into godot and we can  start interacting with our postgre database   okay so now that we're in godot what we're going  to do is we're going to first create a 2d scene   here and now we're going to need to go out to  pull down our post gray client here so i'm going   to be pulling it down from github and the reason  why i'm pulling it down from github is because   github has the most recent version of  this plugin and i've run into a few issues   with the one that's out in the asset library so  i'm just going to go ahead and pull this down so   let's just click on code and download our zip here  and that will pull down all of our code so now   that we have this pulled down i'm just going to  pull this into download so it gets extracted here   and you will see that we have a  bunch of different scripts here   let's go ahead and grab postgresql client open up  godot and let's go ahead and copy this down into   it so now we have postgresql client here and  we are going to right click our node 2d we're   going to add whoops we're going to right click  on our node 2d we are going to attach a script   and we'll just call this select from db so the  first thing that we're going to do is we need to   create an instance of our database so var  database is equal to post gray sqlclient.new and then we need to create our user  password our host our port and our database   connection so we will say var whoops not car var  user is equal to and i'm going to say postgre   then underneath that i'm going to say var  password is equal to password because that's   my password that's extremely secure keep  it s keep it a secret var host equal to   local host var port is equal  to 5432 and var database connection is equal to whatever  your database name is so if we look   our database name is postgrade so gray make  sure that these are all correct so they all   match up with what you have so post gray  post gray and my password is correct so that   should work now under our ready we need to  go ahead and connect some of our database   signals here so what we're going to do is  we're going to say database dot connect connection underscore establish comma self comma and then we need to come up with   our little function that's going  to be ran so it's going to be select from db all right now we're going to  have to set up our our next signal which is our   connection closed signal so database dot  connect connection error comma self comma error and finally database dot connect  connection closed comma self comma close connection so what these are doing is  they're saying hey when we connect to our   database let's go ahead and run this function here  when we have an error let's run our error function   and when we connect when we close our connection  let's go ahead and run our connection closed   now from here we need to go ahead and connect to  our database so database dot connect to host and   we need to pass in our post gray path here so what  we're going to do is we'll say quote post gray sql colon slash slash plus our user plus this little  colon here plus password plus at symbol plus host wait it didn't light up like i would  expect because the rest of them did colon plus our port plus slash plus database connection great so that's pretty much  everything that we need here   for our little database connection to  happen now there are easier ways to do this   so if i can show you another way here instead  of doing this we can actually do something like   dollar sign s colon dollar sign or i'm  sorry percent sign whoops percent sign s at   percent sign s colon percent sign d slash  percent sign s and then we can go ahead and   do a percent symbol here and then pass all  of this in here let me change this over here so you could definitely do something like  this and some people find this cleaner   some people find this less clean it's  up to you whichever one you prefer   i'm just going to keep with what we originally had  but you're welcome to do whichever one you want   both of them are valid so now that we have our  database connection happening what we need to do   is we need to say hey now we have our  connection let's go ahead and create   our connection function so we're going to say  funk select from db and we are going to oh my   c sharp is getting at me all right there we  go um and we're going to say print running select quarry oh goodness i'm running into so many troubles  there we go and now we need to go var data is equal to database dot execute so execute  right here and then i'm going to hit enter and the   reason i'm going to hit enter is because we're  going to create a little sql query inside of   here that is going to allow us to run this  stuff so if i do three quotes here like so there we go if i put three quotes like that  that'll allow me to create a multi-line   string here so that way i can put in all of my   sql query into one giant string here  so we'll go ahead and type begin and then we'll say select star from scoreboard and that's going to go ahead and allow  us to select all of our data from our scoreboard   and now we need to go through and process that  data so what we're going to do is we will go 4d   in data then let's go ahead and print our data row and that will allow us to print out our data  as we get through here now i'm going to go   ahead and put a break point here so that  way we can see the data that comes back   and one last thing that we need to make sure that  we do is we need to set up our database close so   inside of here if we hit enter and go back one  so it's part not part of our for loop and we go   database dot close and we need to make sure that  we do what's called a polling of our database we   want to make sure our database exists so we can  pull it every single frame or so so if we come   over here and we get rid of our function process  and we can go ahead and call our database poll and   the way to call it is just with database.poll and  that just basically checks if the database is live   if there's anything wrong things like that and we  need to set up our database close function so funk closed connection and we'll just say print quote database has closed   and one last little thing that we're going to  have to make sure that we do is when we close   our uh program we want to make sure that we  close our database connection because if not   that connection may stay open and if you guys know  anything about postgre if you keep that database   connection open even after the user disconnects it  keeps that slot open which is really inefficient   for the server end because it's got all those  extra users just sitting there doing nothing   so we need to say funk underscore exit tree and  now what that's going to do is it's going to say   hey when the tree when you close the program run  this function and we're going to say database dot   close so i'm going to save well i was  going to save but i guess i'm saving my   scene so i guess i'm going to save my scene  real quick and call it postgres tutorial   and we're going to go ahead and test this out and  see what it does so let's go ahead and create a   break point here and a breakpoint here and i think  that will do it so let's go ahead and run this   and see what it does all right so we're running  this little connection here so invalid operator   string to int and operator plus so we have a  slight issue here i think it's because these   are supposed to be string so it looks like i'm  wrong and actually you have to do it this way so   we'll go ahead and pull this one so we have string  string string decimal notation and then string so   the reason why it needs to be a decimal notation  is because this is a port so the port needs to be   a number not a string that's my fault let's  go ahead and retest it and see what it does okay so it's going to run its select query you can  see right here how it's running our select query   so we're going to come down here we're going to  run our little execute and it's going to pull   back some data so awesome now you can see that 4d  in data let's take a look at our data size so in   our first section here we have our data row which  is our command tag of begin now we don't need this   so this is useless to us our second return is our  actual data itself so we have command tag select   four now don't worry about what it says select  four it doesn't mean anything that's super useful   but if we look at our data row and we open up  our array size you can see here is our data which is awesome we got all the data back that  we'd expect see that also it looks like we have   a small error here if we try to run our thing we  get a little invalid index data row on base array   we actually need to put d not data row here so  that's our fault but from here we can go ahead   and pull back our first index here and then go  ahead and pass in our data row data so we can do   is we can say 4d in data 1 and that will pass back  our single index of data so if we actually print d   and we refresh this and we try it  again and we just let it run through oh it's not happy with me oh whoops dot data underscore row and let's try that this time  goodness i'm struggling over here okay so if you   go ahead and you look at your output you'll  see that it passed back all of our data here   so perfect right so now we can go ahead and use  this data however we want like if you wanted to   put data into the data or if you want to put data  into like a scoreboard or something like that   now you have your data back okay so now that we  have this right we have our ability to select   and basically run queries on here let's go  ahead and make this actually reusable right   let's make this actually usable for things other  than just a single query right so what we can do   is let's go ahead and select from db here  let's go ahead and copy this and let's paste   it down here and say insert into db right so  let's do right here we'll go with lowercase and then we're going to say insert into lowercase scoreboard and then we'll say id comma   name comma score and let's go ahead  and pass in a few parameters here   so let's say id name comma score and  then let's go ahead and say values   and we will go with percent sign s  comma quote quote percent sign s comma   percent sign s and then outside of  here we're going to go semi-colon   and then commit and what that's going to  do is that's going to allow us to commit   our data to our database and now down here we're  going to go percent sign and we're going to put in   a little array here we're going to say id  comma name comma score and that will allow   us to commit data to our database and we no  longer need this little bit here so now if we go ahead and bring our function down there we go  now we can go ahead and right click here add a   name and duplicate it and pull it down we'll say  on button down let's connect that to our node 2d   and on our button let's go ahead and connect that  also to our node 2d and we're going to say for our   second button here we're going to call this  uh select from db so we're going to say select   from db and on our button down we're going to say  insert i believe i said insert into db right here okay now that's going to  take in some parameters here   so let me go ahead and add  in a child node and add in a text edit we'll just put this over here and  i know like i said these are probably this   is pretty ugly but we'll just make it so that i  can show you guys the gist of how it all works   and then we'll go ahead and get rid of  that all right and let me grab these   three pull these three over and then i'm  just gonna go ahead and grab a label i know   that this is probably too much for what  we're trying to do but that's all right all right so for the first label we'll  call it id second one we're gonna call it   name and the third one we'll call it score awesome  and that's a little off but that's all right   now what we'll do is we'll go in here and  we will go ahead and pass in dollar sign   whoops dollar sign text edit and i believe  it's text edit one is going to be id comma dollar sign oops dollar sign text edit three dot text comma finally dollar sign text  edit four dot text and that'll be all of   our little text data so now if we scroll up to  the top and we go ahead and we comment out our   little database connection here we should be  able to run both of these commands from our   um scene here so let's go ahead and click on a  break point here and let's go ahead and click   a break point here so that way we can do our  little testing here we'll go ahead and run this   and the first thing we'll do is  we will select the first one which   in this case is insert into database so it  probably just aired out yeah syntax error   i figured considering we are not exactly doing  it this part correctly so if we'll just continue   whoops not goodness i should probably label  these eh so let's click on button and label it insert data and select data there we go that'll make things a little  easier now if we click on our little   script here and we go ahead and um run our project  after we put our two little break points in here   so let's go ahead and do that if we want  to insert data we can say something like   eight and then for our name let's just say test  number four and for our score we'll say 70 and   go ahead insert that data and we'll let that run  through whoops oh goodness i hit the wrong button   let's see if that actually worked by the way  first okay didn't run through so that's good   news so we'll say 8 test 5 and we will say 70  or 80. insert data and then let's go ahead and   run it through and it should have inserted  our data so let's go ahead and run this   so you'll see here we have an error it says  column test five does not exist so that usually   means that we have an extra pair quotes  around our name here so what i'm wondering   is if the data we're getting back  from our text edit is causing it to   have an additional quote around  it that would be my guess so   let's take a look at it real quick let's put a  break point right here and then let's go ahead and   click on this click here and go ahead and insert  our data and let's see what our name is 80 our   score is test five so that's our first problem  so we have these backwards so that's my fault   so actually this yeah so we have  these backwards so that's my fault   so that is why we're running into this problem  this is the part of the reason why you should   name your stuff properly this is my fault so  now if i go ahead and refresh this and i say 8   and i say test 4 or 5 and score is 90 and we go  insert the data and we run it through like this   and we run it all the way through when we go  ahead and we check out our post gray and we   hit play you'll see bam it's inserted our data  now if we hit select data if you go ahead and you   check out your data row let's see if we got any  errors the front end is not connected to the back   end so that did not work so i figured out the  issue that we're running into so what we need to   do is we need to make sure that we have a commit  and a semicolon here we have to make sure that our   database closed is removed so let's go ahead  and remove that and if we go up to our insert   and we do the same thing then that'll allow us  to do multiple operations on the same database   hey guys editor mitch here so i didn't really  explain why this is a problem so the reason why   this is a problem is because if you don't  have a semicolon and a commit you're not   telling the system to commit that transaction  so every single time you do a database um   operator you're saying hey go ahead and begin  this transaction like hey i'm gonna tell you   to do a thing and then here's the thing to do and  now go ahead and put it into the database and what   we were doing beforehand was not committing the  data to the database so the database was saying   hey i can't do anything while that transaction is  still open and the reason why we need to get rid   of our database closed is because if we close our  database connection we're going to need to reopen   it to go ahead and commit and do more operators  on the database you can close the database if you   want to but you're going to need to run that  database connect to host again to allow it to   re-get that connection and it really depends on if  you want to kill that database connection or not   it just kind of depends on you but there is a  spin up time between that connect host and that um   quarry that you're running so you're gonna want to  make sure that you um you know wait for that like   how we have that signal up there the connection  established you could in theory say hey i need   to run this operator so go spin off in this thread  and wait for the connection established to happen   and then once that is connection established  happens then commit my data right that would   be another way of handling this but in our case  i'm just keeping that database connection open   anyway let's go back to the uh video thanks  guys so now if i go ahead and i hit play and i   say id of i don't know 10 and test 7 and  score a 500 test 7 is very good at this game   we click insert and we go to our admin tool and we  go ahead and we select you'll see there's our data   now if we come over here and we go ahead and put  a break point i already have one so that's perfect   select data you'll see that it went and pulled  back our data here so if i go to my data rows   you'll see that we now have our inserted data so  that's how we do multiple operators on a database   we want to make sure that we keep that  database connection alive and that we   keep pulling the database like we are doing right  here awesome so the last thing that we're going   to do is we're going to go ahead and update some  data and what i'm going to do is i'm going to go   ahead and come here i'm going to copy uh my insert  data i guess so we'll go ahead and copy that and   we're gonna paste that here all right and we are  going to say insert into we're gonna say update scoreboard set name equal to  actually we'll say score equal to whatever this gets passed in so let's go ahead  and change this we'll say name comma score   and we'll say update db name score and we'll say uh name score and we'll  say uh update scoreboard set score to that s where name is equal to percent sign s and  we'll need to make sure we flip these two   all right so what this should do is it should go  ahead and set up it'll take in a name and take   in a score and then we are going to set the score  equal to score and name where the name is equal to   name so now what we can do is come over here to  our node select our data we can duplicate this   little button here and say update data and inside  of here we can actually go ahead and go into our   node right click disconnect it right click connect  it so on button down we're going to go ahead and   call update database and we need to pass in a name  and a score so we already know what our name is   right here and what our score is it's right  here so i'm just going to copy this right there   and then that should do it for us so now if i  refresh this and i say okay someone's name is   buying point cgi and he now has a score of 1 000  so if we remember and we look at our pg admin   you'll see that i have a score of a hundred so  now that's going to become 1000 when this is done   so let's go ahead and run this whoops run  this we'll click update data and you'll see   that it goes ahead and runs through syntax error  adder near commit so we have a syntax error here   what did i do wrong let's see update  scoreboard set score equal to this   that looks about right i think it might  be mad a because name is not wrapped and   b because we're missing a semicolon how much you  want to bet let's go ahead and try that again and let's say i got 800 points here this time  update data and then let's go check on it   and there we go you'll see that it has been  updated to 800. so that's all i have for you   guys today so if you like this video go ahead and  hit that like button hey you know if you dislike   this video go ahead and hit that dislike button  because i am here to make content for you guys now   this was a viewer suggested video as with pretty  much all of my videos at this point so if you guys   have any suggestions for future videos go ahead  and throw them in the comments below and i'll   be more than happy to take a look at them as you  guys know i have a huge trello board that is out   there for you guys to look at all the different  video ideas i have for the future and hey if you   have any questions about this go ahead and either  throw a comment in the video below or jump onto   my discord link is in the description and i'll be  more than happy to help you out as much as i can   but that is all i have for you guys today  so thank you so much again for watching   and i will see you all next time thanks you
Info
Channel: FinePointCGI
Views: 1,025
Rating: undefined out of 5
Keywords: godot engine, godot, godot game engine, godot engine tutorial, godot tutorial, godot 3, godot networking, godot 3 networking, godot 3.0, twitch, advanced godot | setting up sqlite with godot 3.2, godot multiplayer, godot engine multiplayer, godot network tutorial, godot instancing, godot multiplayer example, godot http requests, godot 3 tutorial, godot engine 3, godot 3.0 tutorial, godot networking tutorial, intro godot engine, Advanced Godot | Using Godot with PostGreSQL
Id: 4GgevRacFkY
Channel Id: undefined
Length: 51min 28sec (3088 seconds)
Published: Mon Aug 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.