Creating database models

Let's write a few SQL strings for creating the tables for the preceding train, station, and route resources. We are going to create a project layout for this API. Create two directories called railAPI and dbutils in $GOPATH/src/github.com/git-user/chapter4.

Here, railAPI is our project source, and dbutils is our own package for handling database initialization utility functions. Follow these steps:

  1. Let's start with the dbutils/models.go file. Add three models each for train, station, and schedule in the models.go file:
package dbutilsconst train = `      CREATE TABLE IF NOT EXISTS train (           ID INTEGER PRIMARY KEY AUTOINCREMENT,           DRIVER_NAME VARCHAR(64) NULL,           OPERATING_STATUS BOOLEAN        )`const station = ` CREATE TABLE IF NOT ...

Get Hands-On RESTful Web Services with Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.