Esempio n. 1
0
func InitPostgreSQL() (ITransactionManager, *sql.DB) {
	logger.Infof("******* Using PostgreSQL *******\n")

	common.RAW_SQL = "SELECT name FROM book WHERE name LIKE $1"

	translator := trx.NewPostgreSQLTranslator()
	translator.RegisterTranslation(
		common.TOKEN_SECONDSDIFF,
		func(dmlType DmlType, token Tokener, tx Translator) string {
			m := token.GetMembers()
			return fmt.Sprintf(
				"EXTRACT(EPOCH FROM (%s - %s))",
				tx.Translate(dmlType, m[0]),
				tx.Translate(dmlType, m[1]),
			)
		},
	)

	return common.InitDB("postgres", "dbname=gosql user=postgres password=postgres sslmode=disable", translator)
}
Esempio n. 2
0
func InitFirebirdSQL() (ITransactionManager, *sql.DB) {
	logger.Infof("******* Using FirebirdSQL *******\n")

	common.RAW_SQL = "SELECT name FROM book WHERE name LIKE ?"

	translator := trx.NewFirebirdSQLTranslator()
	translator.RegisterTranslation(
		common.TOKEN_SECONDSDIFF,
		func(dmlType DmlType, token Tokener, tx Translator) string {
			m := token.GetMembers()
			return fmt.Sprintf(
				"DATEDIFF(SECOND, %s, %s)",
				tx.Translate(dmlType, m[1]),
				tx.Translate(dmlType, m[0]),
			)
		},
	)

	return common.InitDB("mgodbc", "dsn=FbGoSQL;uid=SYSDBA;pwd=masterkey", translator)
}
Esempio n. 3
0
func InitOracle() (ITransactionManager, *sql.DB) {
	logger.Infof("******* Using Oracle *******\n")

	common.RAW_SQL = "SELECT name FROM book WHERE name LIKE ?"

	translator := trx.NewOracleTranslator()
	translator.RegisterTranslation(
		common.TOKEN_SECONDSDIFF,
		func(dmlType DmlType, token Tokener, tx Translator) string {
			m := token.GetMembers()
			return fmt.Sprintf(
				"(SYSDATE - ( %s - %s) - SYSDATE)*86400",
				tx.Translate(dmlType, m[1]),
				tx.Translate(dmlType, m[0]),
			)
		},
	)

	//var sid = oracle.MakeDSN("oracleserver", 1521, "", "XE")
	var sid = oracle.MakeDSN("192.168.56.101", 1521, "", "XE")
	return common.InitDB("goracle", "gosql/gosql@"+sid, translator)
}
Esempio n. 4
0
func InitMySQL5() (ITransactionManager, *sql.DB) {
	logger.Infof("******* Using MySQL5 *******\n")

	common.RAW_SQL = "SELECT `NAME` FROM `BOOK` WHERE `NAME` LIKE ?"

	translator := trx.NewMySQL5Translator()
	/*
		registering custom function.
		A custom translator could be created instead.
	*/
	translator.RegisterTranslation(
		common.TOKEN_SECONDSDIFF,
		func(dmlType DmlType, token Tokener, tx Translator) string {
			m := token.GetMembers()
			return fmt.Sprintf(
				"TIME_TO_SEC(TIMEDIFF(%s, %s))",
				tx.Translate(dmlType, m[0]),
				tx.Translate(dmlType, m[1]),
			)
		},
	)

	return common.InitDB("mysql", "root:root@/gosql?parseTime=true", translator)
}
Esempio n. 5
0
func initDb() (db.ITransactionManager, *sql.DB) {
	translator := translators.NewMySQL5Translator()
	return common.InitDB("mysql", "tb:tb@/taskboard?parseTime=true", translator)
}