![]() Provided to you (eg if you are using a Heroku database).The next two on the list, user and password, are likely either: If that isn’t the case, I am going to assume you have a way to locate that information. host is almost certainly going to be localhost and port is likely 5432 if you are connecting to a Postgres database that is running on the same computer you are developing from. You probably chose the name of the database you are going to use, the user (aka role) used to login to Postgres, and you likely set a custom password for that user.ĭespite that, I am going to try to walk you through gathering this information, including giving you a few guesses as to what your information may be when working with a local database.īefore we proceed, let’s first look at the information we need to collect.Ĭonst ( host = "localhost" port = 5432 user = "postgres" password = "your-password" dbname = "calhounio_demo" ) Unfortunately, your credentials and other database information you are going to need isn’t something that is set in stone. If this info is wrong, it doesn’t matter what you try in your code You won’t be able to interact with your database without the correct credentials! I suggest you check the previous articles out :) Gather your PostgreSQL database infoīefore we can connect to our database we first need to make sure we have the correct information. This post is part of a much larger series titled, and previous articles in the series not only cover how to use Postgres with raw SQL, but they also help walk you through installing Postgres and provide a little background information about why we are doing some of the things we do. We are going to start out pretty simple and will only be connecting to a database here, but if you are familiar with SQL you will discover that once you get connected to your database you can very quickly start utilizing it with your existing SQL knowledge.ĭon’t fret if you don’t have any SQL experience. In this article we are going to explore using PostgreSQL with Go. Connecting to a PostgreSQL database with Go's database/sql package
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |