<commit_before>[![Codeship Status for areatech/go-fixtures](https://codeship.com/projects/f196fa10-84fb-0133-c7be-429ee0939cc9/status?branch=master)](https://codeship.com/projects/122147)

# go-fixtures

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

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:

```yaml
---

- 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:

```go
package main

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

	fixtures "github.com/areatech/go-fixtures"
	"github.com/codegangsta/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 = "<NAME>"
	cliApp.Email = "<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) {
				data, err := ioutil.ReadFile(c.Args().First())
				if err != nil {
					log.Fatal(err)
				}

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

	cliApp.Run(os.Args)
}

```<commit_msg>Reformatted README.<commit_after>[![Codeship Status for areatech/go-fixtures](https://codeship.com/projects/f196fa10-84fb-0133-c7be-429ee0939cc9/status?branch=master)](https://codeship.com/projects/122147)

# go-fixtures

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

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:

```yaml
---

- 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:

```go
package main

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

  fixtures "github.com/areatech/go-fixtures"
  "github.com/codegangsta/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 = "<NAME>"
  cliApp.Email = "<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) {
        data, err := ioutil.ReadFile(c.Args().First())
        if err != nil {
          log.Fatal(err)
        }

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

  cliApp.Run(os.Args)
}
```
{'fraction_non_alphanumeric': 0.14639423076923078, 'fraction_numerical': 0.01730769230769231, 'mean_word_length': 3.0516066212268744, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6999252', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1545, 'n_words': 367}