Exemple #1
0
// getConfigOrUseTravis returns the parsed db.json if it exists or the
// travisCI config if it does not
func getConfigOrUseTravis() (config.Database, error) {
	conf, err := config.Parse("./db.json")
	if os.IsNotExist(err) {
		return travisCI, nil
	}
	return conf, err
}

// The sql dialect must implement the dialect interface
var _ dialect.Dialect = &PostGres{}

var things = sql.Table("things",
	sql.Column("name", types.Varchar()),
	sql.Column("created_at", Timestamp().Default(Now)),
)

type thing struct {
	Name      string
	CreatedAt time.Time `db:",omitempty"`
}

var meetings = Table("meetings",
	sql.Column("uuid", UUID().NotNull().Unique().Default(GenerateV4)),
	sql.Column("time", TimestampRange()),
)

// TODO custom type for TimestampRange

// Connect to an PostGres instance and execute some statements.
Exemple #2
0
// Table creates a new table element. It will panic on any errors.
func Table(name string, modifiers ...sol.Modifier) *TableElem {
	return &TableElem{TableElem: sol.Table(name, modifiers...)}
}
Exemple #3
0
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	sql "github.com/aodin/sol"
	"github.com/aodin/sol/dialect"
	"github.com/aodin/sol/types"
)

// The sql dialect must implement the dialect interface
var _ dialect.Dialect = &Sqlite3{}

var things = sql.Table("things",
	sql.Column("name", types.Varchar()),
	sql.Column("created_at", types.Timestamp()), // TODO auto-timestamp?
)

type thing struct {
	Name      string
	CreatedAt *time.Time `db:",omitempty"`
}

// Connect to an in-memory sqlite3 instance and execute some statements.
func TestSqlite3(t *testing.T) {
	conn, err := sql.Open("sqlite3", ":memory:")
	require.Nil(t, err, `Failed to connect to in-memory sqlite3 instance`)
	defer conn.Close()

	require.Nil(t,
		conn.Query(things.Create()),