golang-example

command module
v0.0.0-...-681f593 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2023 License: CC0-1.0 Imports: 9 Imported by: 0

README

Learn how to integrate PlanetScale with a sample Go application

This sample application demonstrates how to connect to a PlanetScale MySQL database, create and run migrations, seed the database, and display the data.

For the full tutorial, see the Go PlanetScale documentation.

Set up the Go app

  1. Clone the starter Go application:
git clone https://github.com/planetscale/golang-example
  1. Navigate into the folder:
cd golang-example
  1. Copy the .env.example file into .env:
cp .env.example .env

Set up the database

  1. Sign up for a free PlanetScale account.
  2. Create a new database. A default branch, main, will be created for you.

Connect to the Go app

  1. On the database overview page in the PlanetScale dashboard, click "Connect".
  2. Click "New password".
  3. In the "Connect to" dropdown, select Go.
  4. Copy the connection string.
  5. Open your .env file and paste the connection string in as the value for DSN. You're now connected!

Run migrations and seeder

  1. Start the Go app:
go run .
  1. Navigate to localhost:8080/seed to run the migrations and the seeder.

  2. View the product and category data as follows:

Documentation

Overview

Command golang-example demonstrates how to connect to PlanetScale from a Go application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL