<commit_before># Genmai [![Build Status](https://travis-ci.org/naoina/genmai.png?branch=master)](https://travis-ci.org/naoina/genmai)

Simple, better and easy-to-use ORM library for [Golang](http://golang.org/).

## Overview

* flexibility with SQL-like API
* Transaction support
* Database dialect interface

Database dialect currently supported are:

* MySQL
* PostgreSQL
* SQLite3

## Installation

    go get -u github.com/naoina/genmai

## Schema

Schema of the table will be defined as a struct.

```go
import "database/sql"

// The struct "User" is the table name "user".
// The field name will be converted to lowercase/snakecase, and used as a column name in table.
// e.g. If field name is "CreatedAt", column name is "created_at".
type User struct {
	// PRIMARY KEY. and column name will use "tbl_id" instead of "id".
	Id int64 `db:"pk" column:"tbl_id"`

	// NOT NULL and Default is "me".
	Name string `default:"me"`

	// Nullable column should use a pointer type.
	CreatedAt *time.Time

	// UNIQUE column if specify the db:"unique" tag.
	ScreenName string `db:"unique"`

	// Ignore column if specify the db:"-" tag.
	Active bool `db:"-"`
}
```

## Query API

### Create table

```go
package main

import (
    "time"

    _ "github.com/mattn/go-sqlite3"
    // _ "github.com/go-sql-driver/mysql"
    // _ "github.com/lib/pq"
    "github.com/naoina/genmai"
)

// define a table schema.
type TestTable struct {
    Id        int64      `db:"pk" column:"tbl_id"`   // PRIMARY KEY, and column name "tbl_id" instead of "id".
    Name      string     `db:"notnull" default:"me"` // NOT NULL and DEFAULT.
    CreatedAt *time.Time                             // Nullable column should use a pointer type.
    UserName  string     `db:"unique" size:"255"`    // UNIQUE column and specify the size of string (like VARCHAR(255)).
    Active    bool       `db:"-"`                    // ignore column.
}

func main() {
    db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:")
    // db, err := genmai.New(&genmai.MySQLDialect{}, "dsn")
    // db, err := genmai.New(&genmai.PostgresDialect{}, "dsn")
    if err != nil {
        panic(err)
    }
    defer db.Close()
    if err := db.CreateTable(&TestTable{}); err != nil {
        panic(err)
    }
}
```
<commit_msg>README slight fix<commit_after># Genmai [![Build Status](https://travis-ci.org/naoina/genmai.png?branch=master)](https://travis-ci.org/naoina/genmai)

Simple, better and easy-to-use ORM library for [Golang](http://golang.org/).

## Overview

* flexibility with SQL-like API
* Transaction support
* Database dialect interface

Database dialect currently supported are:

* MySQL
* PostgreSQL
* SQLite3

## Installation

    go get -u github.com/naoina/genmai

## Schema

Schema of the table will be defined as a struct.

```go
// The struct "User" is the table name "user".
// The field name will be converted to lowercase/snakecase, and used as a column name in table.
// e.g. If field name is "CreatedAt", column name is "created_at".
type User struct {
	// PRIMARY KEY. and column name will use "tbl_id" instead of "id".
	Id int64 `db:"pk" column:"tbl_id"`

	// NOT NULL and Default is "me".
	Name string `default:"me"`

	// Nullable column should use a pointer type.
	CreatedAt *time.Time

	// UNIQUE column if specify the db:"unique" tag.
	ScreenName string `db:"unique"`

	// Ignore column if specify the db:"-" tag.
	Active bool `db:"-"`
}
```

## Query API

### Create table

```go
package main

import (
    "time"

    _ "github.com/mattn/go-sqlite3"
    // _ "github.com/go-sql-driver/mysql"
    // _ "github.com/lib/pq"
    "github.com/naoina/genmai"
)

// define a table schema.
type TestTable struct {
    Id        int64      `db:"pk" column:"tbl_id"`
    Name      string     `db:"notnull" default:"me"`
    CreatedAt *time.Time
    UserName  string     `db:"unique" size:"255"`
    Active    bool       `db:"-"`
}

func main() {
    db, err := genmai.New(&genmai.SQLite3Dialect{}, ":memory:")
    // db, err := genmai.New(&genmai.MySQLDialect{}, "dsn")
    // db, err := genmai.New(&genmai.PostgresDialect{}, "dsn")
    if err != nil {
        panic(err)
    }
    defer db.Close()
    if err := db.CreateTable(&TestTable{}); err != nil {
        panic(err)
    }
}
```

{'fraction_non_alphanumeric': 0.14681700728212357, 'fraction_numerical': 0.005402865867982147, 'mean_word_length': 2.84643179765131, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '6282474', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1445, 'n_words': 436}