Exemplo n.º 1
0
func main() {
	db := sqlx.MustOpen("sqlite3", ":memory:")

	db.MustExec(`CREATE TABLE Products (
                        id INTEGER PRIMARY KEY, 
                        name TEXT
                );
                INSERT INTO Products VALUES (1, 'TV');
                INSERT INTO Products VALUES (2, 'Microwave');`)

	inventory := &DatabaseInventoryRepository{db}

	env := &Env{
		inventory: inventory,
		decoder:   schema.NewDecoder(),
	}

	r := mux.NewRouter()

	r.Handle("/products", handlers.LoggingHandler(os.Stdout, Handler{env, ProductsHandler}))
	r.Handle("/products/search", handlers.LoggingHandler(os.Stdout, Handler{env, SearchHandler}))
	r.Handle("/docs/", http.StripPrefix("/docs/", http.FileServer(http.Dir("docs"))))

	http.ListenAndServe(":8080", r)
}
Exemplo n.º 2
0
func NewDatabase(driver string, dataSource string) *Database {
	db := &Database{}

	db.DB = sqlx.MustOpen(driver, dataSource)

	return db
}
Exemplo n.º 3
0
// New creates a new App based on the config. Exits if an error is encountered.
func New(conf config.Config) *App {
	db := sqlx.MustOpen("sqlite3", conf.DBPath)
	db.MustExec("PRAGMA foreign_keys=ON;")

	store := sessions.NewCookieStore(conf.CookieAuthenticationKey, conf.CookieEncryptionKey)

	templates, err := libtemplate.Load(conf.TemplatesPath)
	if err != nil {
		log.Fatal(err)
	}

	return &App{&conf, db, store, templates}
}
Exemplo n.º 4
0
func main() {
	db := sqlx.MustOpen("sqlite3", os.Getenv("DATABASE_PATH"))
	database.DB = db

	db.MustExec(`
		create table if not exists user (
			id integer primary key,
			telegram_id integer not null,
			name text
		);

		create table if not exists selection (
			id integer primary key,
			user_id integer not null,
			chat_id integer not null,
			title text,
			active integer
		);

		create table if not exists selection_item (
			id integer primary key,
			selection_id integer not null,
			item text not null
		);

		create table if not exists selection_vote (
			id integer primary key,
			user_id integer not null,
			selection_id integer not null,
			selection_item_id integer not null
		);
	`)

	f := finch.NewFinch(os.Getenv("TELEGRAM_APITOKEN"))

	f.API.Debug = os.Getenv("DEBUG") == "true"

	f.Start()
}
Exemplo n.º 5
0
func init() {
	db = sqlx.MustOpen("postgres", "user=ian dbname=expense_test password=wedge89")
	s = MustCreate(db)
}
Exemplo n.º 6
0
func NewDatastore() *Datastore {
	log.Println("Connecting to postgres")
	db := sqlx.MustOpen("postgres", "user=tuukka password=tuukka port=5433 dbname=peuranie sslmode=disable")
	return &Datastore{db}
}