Django style fixtures for Golang's excellent built-in database/sql library.

go-fixtures

Django style fixtures for Golang's excellent built-in database/sql library. Currently only YAML fixtures are supported.

Travis Status for RichardKnop/go-fixtures godoc for RichardKnop/go-fixtures codecov for RichardKnop/go-fixtures


There are two reserved values you can use for datetime fields:

  • ON_INSERT_NOW() will only be used when a row is being inserted
  • ON_UPDATE_NOW() will only be used when a row is being updated

Example YAML fixture:

---

- table: 'some_table'
  pk:
    id: 1
  fields:
    string_field: 'foobar'
    boolean_field: true
    created_at: 'ON_INSERT_NOW()'
    updated_at: 'ON_UPDATE_NOW()'

- table: 'other_table'
  pk:
    id: 2
  fields:
    int_field: 123
    boolean_field: false
    created_at: 'ON_INSERT_NOW()'
    updated_at: 'ON_UPDATE_NOW()'

- table: 'join_table'
  pk:
    some_id: 1
    other_id: 2

Example integration for your project:

package main

import (
	"database/sql"
	"io/ioutil"
	"log"

	"github.com/RichardKnop/go-fixtures"
	"github.com/urfave/cli"
	// Drivers
	_ "github.com/lib/pq"
)

var (
	cliApp *cli.App
)

func init() {
	cliApp = cli.NewApp()
	cliApp.Name = "your-project"
	cliApp.Usage = "Project's usage"
	cliApp.Author = "Your Name"
	cliApp.Email = "your@email"
	cliApp.Version = "0.0.0"
}

func main() {
	db, err := sql.Connect("postgres", "user=foo dbname=bar sslmode=disable")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	cliApp.Commands = []cli.Command{
		{
			Name:  "loaddata",
			Usage: "load data from fixture",
			Action: func(c *cli.Context) error {
				data, err := ioutil.ReadFile(c.Args().First())
				if err != nil {
					return err
				}

				if err := fixtures.Load(data, db, "postgres"); err != nil {
					return err
				}
			},
		},
		{
			Name:  "runserver",
			Usage: "run web server",
			Action: func(c *cli.Context) error {
				// Run your web server here
				return nil
			},
		},
	}

	cliApp.Run(os.Args)
}
Owner
Richard Knop
I'm an experienced software engineer, open source contributor. I have mostly focused on backend programming in Go & Python
Richard Knop
Similar Resources

mini tools handling migrasion database from cli

mini tools handling migrasion database from cli

Dec 13, 2021

Opinionated tool for database structure management and migrations

trek Requirements At least version 13 of postgres is needed. Installation go install . Setup Create config.yaml: model_name: model_name db_name: db

Dec 14, 2022

Database migration through structures - development

goMigration 基于 Golang 的数据库迁移工具,目前仍在开发中,有兴趣的小伙伴可以联系我一起~ 食用方法 go get https://github.com/DGuang21/goMigration 手动将其安装 可通过 gom gen create_c_user_table 方法生

Dec 2, 2021

A database migration tool written in Go.

dbmagritte created by Austin Poor A database migration tool written in Go. Usage Commands: init: Set up the repo by creating a .dbmagritte.yaml file a

Jan 29, 2022

A migration engine to deploy database changes in your golang + mongodb app.

bisonmigration A migration engine to deploy database changes in your golang + mongodb app. Migration files register their UP and DOWN functions in the

Jan 30, 2022

Open Sound Control (OSC) library for Golang. Implemented in pure Go.

GoOSC Open Sound Control (OSC) library for Golang. Implemented in pure Go. This repository is a heavily modified fork of the original go-osc. Please c

Dec 22, 2021

Ruby on Rails like test fixtures for Go. Write tests against a real database

testfixtures Warning: this package will wipe the database data before loading the fixtures! It is supposed to be used on a test database. Please, doub

Jan 8, 2023

pongo2 is a Django-syntax like templating-language

Django-syntax like template-engine for Go

Dec 27, 2022

Validate Django auth session in Golang

GoDjangoSession Valid for django 3.0.5 Usage: package main import ( "encoding/base64" "fmt" "session/auth" "github.com/Kuzyashin/GoDjangoSession"

Aug 23, 2022

Database security suite. Database proxy with field-level encryption, search through encrypted data, SQL injections prevention, intrusion detection, honeypots. Supports client-side and proxy-side ("transparent") encryption. SQL, NoSQL.

Database security suite. Database proxy with field-level encryption, search through encrypted data, SQL injections prevention, intrusion detection, honeypots. Supports client-side and proxy-side (

Database protection suite with field level encryption and intrusion detection. | Acra Engineering Examples | Documentation | Installation | Examples a

Dec 28, 2022

Go binding for rpi-rgb-led-matrix an excellent C++ library to control RGB LED displays with Raspberry Pi GPIO.

Go binding for rpi-rgb-led-matrix an excellent C++ library to control RGB LED displays with Raspberry Pi GPIO.

go-rpi-rgb-led-matrix Go binding for rpi-rgb-led-matrix an excellent C++ library to control RGB LED displays with Raspberry Pi GPIO. This library incl

Dec 30, 2022

LeetCode in Go with the code style strictly follows the Google Golang Style Guide

LeetCode in Go with the code style strictly follows the Google Golang Style Guide

LeetCode in Go LeetCode Online Judge is a website containing many algorithm questions. Most of them are real interview questions of Google, Facebook,

Nov 13, 2021

Fixtures for testing standard IPLD codecs

IPLD Codec Fixtures This repository contains fixtures for standard IPLD codecs. It is used to verify the correctness, compatibility and limitations of

Nov 2, 2022

Parse data and test fixtures from markdown files, and patch them programmatically, too.

go-testmark Do you need test fixtures and example data for your project, in a language agnostic way? Do you want it to be easy to combine with documen

Oct 31, 2022

🛠 A test fixtures replacement for Go, support struct and ent, inspired by factory_bot/factory_boy

carrier - A Test Fixtures Replacement for Go Statically Typed - 100% statically typed using code generation Developer Friendly API - explicit API with

Jan 23, 2022

go-wrk - a HTTP benchmarking tool based in spirit on the excellent wrk tool (https://github.com/wg/wrk)

go-wrk - an HTTP benchmarking tool go-wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CP

Jan 5, 2023

Another excellent micro service framework

xservice [WIP] Another excellent micro service framework Features RESTful API (base on echo/v4) gRPC & gRPC gateway service & Swagger document generat

May 28, 2022

Solutions to the excellent yearly Advent Of Code puzzles

adventofcode Solutions to the excellent yearly Advent of Code puzzles - https://adventofcode.com I'll try to solve the previous years before 2022's Ad

Dec 13, 2022

An excellent tool for converting json files to structs or classes in any programming language.

An excellent tool for converting json files to structs or classes in any programming language.

Explore Usage » Report Bug · Request Feature Table of Contents About The Project Supported Languages Getting Started Usage Parameters Set Up Your Own

Dec 10, 2022
Dbmate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers.

Dbmate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers. It is a stand

Jan 1, 2023
Database schema evolution library for Go

Try browsing the code on Sourcegraph! Darwin Database schema evolution library for Go Example package main import ( "database/sql" "log" "github.

Dec 5, 2022
Database migrations. CLI and Golang library.

migrate Database migrations written in Go. Use as CLI or import as library. Migrate reads migrations from sources and applies them in correct order to

Dec 31, 2022
Dead simple Go database migration library.
Dead simple Go database migration library.

migrator Dead simple Go database migration library. Features Simple code Usage as a library, embeddable and extensible on your behalf Support of any d

Nov 9, 2022
Database migrations. CLI and Golang library.

Database migrations written in Go. Use as CLI or import as library.

May 30, 2021
SQL schema migration tool for Go.

sql-migrate SQL Schema migration tool for Go. Based on gorp and goose. Using modl? Check out modl-migrate. Features Usable as a CLI tool or as a libra

Jan 2, 2023
entimport is a tool for creating Ent schemas from existing SQL databases.

entimport entimport is a tool for creating Ent schemas from existing SQL databases. Currently, MySQL and PostgreSQL are supported. The tool can import

Dec 23, 2022
Goose database migration tool - fork of https://bitbucket.org/liamstask/goose

goose Goose is a database migration tool. Manage your database schema by creating incremental SQL changes or Go functions. Goals of this fork github.c

Dec 30, 2022
Minimalistic database migration helper for Gorm ORM

Gormigrate Gormigrate is a minimalistic migration helper for Gorm. Gorm already has useful migrate functions, just misses proper schema versioning and

Dec 25, 2022
goydb, a couchdb compatible embeddable database written in go
goydb, a couchdb compatible embeddable database written in go

goydb, a couchdb compatible embeddable database written in go Getting started (not embedded) Using docker mkdir data docker run -e GOYDB_ADMINS=admin:

Sep 14, 2022