examples

package
v0.0.0-...-52d38b8 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Code first example of agoradb

This packge is an example of a code first approach.

The schema for the database is defined first in the schema.go source file.

Before running go generate ./...
  1. Make sure at least one database node is running
  2. Create test_users database in the database
  3. It is recommended to log in with the cli before running go generate
    agoradb login localhost:5750 [--user u1 --password p1]
    
  4. Run go generate ./... which will execute two things: First it will migrate the database and deploy the schema Second it will download the protobuf definition and generate the client code

Trying out

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	TableName `db:"user_addresses"`

	UserId      string `db:"primary_key,type=uuid"`
	MainAddress bool   `db:"primary_key,type=bit"`
	Street      string
	City        string
	ZipCode     int

	// Relational data
	User User `db:"one=users,by=UserId"`
}

Address with composite primary key and a custom table name

type Car

type Car struct {
	UserId string `db:"primary_key,type=uuid"`
	Model  string `db:"primary_key"`
	Color  Colors `db:"enum"`

	// Relational data
	User User `db:"one=users,by=UserId"`
}

Car with composite primary key

type Colors

type Colors int
const (
	Red Colors = iota
	Green
	Blue
	Black
)

func (Colors) String

func (c Colors) String() string

type User

type User struct {
	Id        string `db:"primary_key,type=uuid"`
	FirstName string
	LastName  string
	Gender    string
	Age       int

	// Relational data
	Friends []User  `db:"manyToMany=users,by=Id"`
	Address Address `db:"one=user_addresses,by=Id,having=mainAddress;true"`
	Cars    []Car   `db:"many=userCars,by=Id"`
}

User with related objects: 1:1, 1:n, n:n relations

Jump to

Keyboard shortcuts

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