The easiest way to install sqac is to use go get on the command-line to pull the latest version from github, as shown below:
go get -u github.com/1414C/sqac
The ‘go get’ command will pull the sqac github repository into your $GOPATH/src/github.com folder, as well as any dependencies referenced by the sqac source code. The -u flag is included to instruct go get to check for and pull updates to sqac and it’s dependencies. Sqac uses go modules and will pull the required versions its dependencies based on the content of the go.mod file.
Ensure that you have also installed the drivers for the databases you plan to use. Supported drivers include:
Driver Name | Driver Location |
---|---|
SAP Hana Database Driver | github.com/SAP/go-hdb/driver |
MSSQL Database Driver | github.com/denisenkom/go-mssqldb |
MySQL Database Driver | github.com/go-sql-driver/mysql |
PostgreSQL Database Driver | github.com/lib/pq |
SQLite3 Database Driver | github.com/mattn/go-sqlite3 |
Verify the installation by running the included test suite against sqlite. Test execution will create a ‘testdb.sqlite’ database file in the sqac directory. The tests are not entirely idempotent and the testdb.sqlite file will not be cleaned up. This is by design as the tests were used for debugging purposes during the development. It would be a simple matter to tidy this up.
go test -v -db sqlite
If all goes well, you should see the following:
2018/12/20 11:50:47 package sqac init is running
=== RUN TestGetDBDriverName
--- PASS: TestGetDBDriverName (0.00s)
=== RUN TestGetDBName
--- PASS: TestGetDBName (0.00s)
=== RUN TestExistsTableNegative
--- PASS: TestExistsTableNegative (0.00s)
=== RUN TestCreateTableBasic
--- PASS: TestCreateTableBasic (0.00s)
=== RUN TestDropTablesBasic
--- PASS: TestDropTablesBasic (0.00s)
=== RUN TestCreateTableCompoundKey
--- PASS: TestCreateTableCompoundKey (0.01s)
=== RUN TestCreateTableNonIncKey
--- PASS: TestCreateTableNonIncKey (0.00s)
=== RUN TestCreateTableNoKey
--- PASS: TestCreateTableNoKey (0.00s)
=== RUN TestCreateTableWithAlterSequence
--- PASS: TestCreateTableWithAlterSequence (0.00s)
=== RUN TestCreateTablesWithInclude
--- PASS: TestCreateTablesWithInclude (0.00s)
=== RUN TestCreateUniqueColumnConstraintFromModel
--- PASS: TestCreateUniqueColumnConstraintFromModel (0.00s)
=== RUN TestExistsIndexNegative
--- PASS: TestExistsIndexNegative (0.00s)
=== RUN TestCreateSingleUniqueIndexFromModel
--- PASS: TestCreateSingleUniqueIndexFromModel (0.00s)
=== RUN TestCreateSingleNonUniqueIndexFromModel
--- PASS: TestCreateSingleNonUniqueIndexFromModel (0.00s)
=== RUN TestCreateSimpleCompositeIndex
--- PASS: TestCreateSimpleCompositeIndex (0.00s)
=== RUN TestExistsIndexPositive
--- PASS: TestExistsIndexPositive (0.00s)
=== RUN TestDropIndex
--- PASS: TestDropIndex (0.00s)
=== RUN TestCreateCompositeIndexFromModel
--- PASS: TestCreateCompositeIndexFromModel (0.00s)
=== RUN TestExistsColumn
--- PASS: TestExistsColumn (0.00s)
=== RUN TestAlterTables
--- PASS: TestAlterTables (0.01s)
=== RUN TestDestructiveResetTables
--- PASS: TestDestructiveResetTables (0.01s)
=== RUN TestQueryOps
--- PASS: TestQueryOps (0.01s)
=== RUN TestNullableValues
--- PASS: TestNullableValues (0.00s)
=== RUN TestNonPersistentColumn
--- PASS: TestNonPersistentColumn (0.00s)
=== RUN TestTimeSimple
--- PASS: TestTimeSimple (0.00s)
=== RUN TestCRUDCreate
--- PASS: TestCRUDCreate (0.00s)
=== RUN TestCRUDUpdate
--- PASS: TestCRUDUpdate (0.01s)
=== RUN TestCRUDDelete
--- PASS: TestCRUDDelete (0.00s)
=== RUN TestCRUDGet
--- PASS: TestCRUDGet (0.00s)
=== RUN TestCRUDGetEntities
--- PASS: TestCRUDGetEntities (0.01s)
=== RUN TestCRUDGetEntities2
--- PASS: TestCRUDGetEntities2 (0.01s)
=== RUN TestCRUDGetEntities4
--- PASS: TestCRUDGetEntities4 (0.01s)
=== RUN TestNullString
--- PASS: TestNullString (0.00s)
=== RUN TestNullInt
--- PASS: TestNullInt (0.00s)
=== RUN TestNullUint
--- PASS: TestNullUint (0.00s)
=== RUN TestNullFloat
--- PASS: TestNullFloat (0.00s)
=== RUN TestNullBool
--- PASS: TestNullBool (0.00s)
=== RUN TestCamelToSnake
--- PASS: TestCamelToSnake (0.00s)
=== RUN TestCRUDGetEntitiesWithCommandsOpenSelect
--- PASS: TestCRUDGetEntitiesWithCommandsOpenSelect (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsSelectUint
--- PASS: TestCRUDGetEntitiesWithCommandsSelectUint (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsSelectString
--- PASS: TestCRUDGetEntitiesWithCommandsSelectString (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsSelectCount
--- PASS: TestCRUDGetEntitiesWithCommandsSelectCount (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsLimit
--- PASS: TestCRUDGetEntitiesWithCommandsLimit (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsLimitDesc
--- PASS: TestCRUDGetEntitiesWithCommandsLimitDesc (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsLimitAsc
--- PASS: TestCRUDGetEntitiesWithCommandsLimitAsc (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOffset
--- PASS: TestCRUDGetEntitiesWithCommandsOffset (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOffsetDesc
--- PASS: TestCRUDGetEntitiesWithCommandsOffsetDesc (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOffsetLimit
--- PASS: TestCRUDGetEntitiesWithCommandsOffsetLimit (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOffsetLimitDesc
--- PASS: TestCRUDGetEntitiesWithCommandsOffsetLimitDesc (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOrderBy
--- PASS: TestCRUDGetEntitiesWithCommandsOrderBy (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOrderByDesc
--- PASS: TestCRUDGetEntitiesWithCommandsOrderByDesc (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsParamOrderBy
--- PASS: TestCRUDGetEntitiesWithCommandsParamOrderBy (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsParamOrderByDesc
--- PASS: TestCRUDGetEntitiesWithCommandsParamOrderByDesc (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOrderByDescLimit
--- PASS: TestCRUDGetEntitiesWithCommandsOrderByDescLimit (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOrderByDescLimitOffset
--- PASS: TestCRUDGetEntitiesWithCommandsOrderByDescLimitOffset (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsOrderByAscLimitOffset
--- PASS: TestCRUDGetEntitiesWithCommandsOrderByAscLimitOffset (0.01s)
=== RUN TestCRUDGetEntitiesWithCommandsTestOffsetOrderByAscLimitOffset
--- PASS: TestCRUDGetEntitiesWithCommandsTestOffsetOrderByAscLimitOffset (0.01s)
=== RUN TestForeignKeyCreate
--- PASS: TestForeignKeyCreate (0.01s)
=== RUN TestForeignKeyDrop
--- PASS: TestForeignKeyDrop (0.01s)
=== RUN TestGetForeignKeyName
--- PASS: TestGetForeignKeyName (0.00s)
=== RUN TestExistsForeignKeyByName
--- PASS: TestExistsForeignKeyByName (0.01s)
=== RUN TestExistsForeignKeyByFields
--- PASS: TestExistsForeignKeyByFields (0.01s)
=== RUN TestForeignKeyCreateFromModel
--- PASS: TestForeignKeyCreateFromModel (0.01s)
=== RUN TestForeignKeyCreateTwoFromModel
--- PASS: TestForeignKeyCreateTwoFromModel (0.01s)
=== RUN TestForeignKeyCreateTwoDelOneFromModel
--- PASS: TestForeignKeyCreateTwoDelOneFromModel (0.00s)
=== RUN TestForeignKeyDelFromModel
--- PASS: TestForeignKeyDelFromModel (0.00s)
=== RUN TestForeignKeyCreateViaAlterTable
--- PASS: TestForeignKeyCreateViaAlterTable (0.01s)
=== RUN TestCRUDGetEntitiesCPOpenSelect
--- PASS: TestCRUDGetEntitiesCPOpenSelect (0.01s)
=== RUN TestCRUDGetEntitiesCPSelectUint
--- PASS: TestCRUDGetEntitiesCPSelectUint (0.01s)
=== RUN TestCRUDGetEntitiesCPSelectString
--- PASS: TestCRUDGetEntitiesCPSelectString (0.01s)
=== RUN TestCRUDGetEntitiesCPSelectMultiParam
--- PASS: TestCRUDGetEntitiesCPSelectMultiParam (0.01s)
=== RUN TestCRUDGetEntitiesCPSelectCount
--- PASS: TestCRUDGetEntitiesCPSelectCount (0.01s)
=== RUN TestCRUDGetEntitiesCPLimit
--- PASS: TestCRUDGetEntitiesCPLimit (0.01s)
=== RUN TestCRUDGetEntitiesCPLimitDesc
--- PASS: TestCRUDGetEntitiesCPLimitDesc (0.01s)
=== RUN TestCRUDGetEntitiesCPLimitAsc
--- PASS: TestCRUDGetEntitiesCPLimitAsc (0.01s)
=== RUN TestCRUDGetEntitiesCPOffset
--- PASS: TestCRUDGetEntitiesCPOffset (0.01s)
=== RUN TestCRUDGetEntitiesCPOffsetDesc
--- PASS: TestCRUDGetEntitiesCPOffsetDesc (0.01s)
=== RUN TestCRUDGetEntitiesCPOffsetLimit
--- PASS: TestCRUDGetEntitiesCPOffsetLimit (0.01s)
=== RUN TestCRUDGetEntitiesCPOffsetLimitDesc
--- PASS: TestCRUDGetEntitiesCPOffsetLimitDesc (0.01s)
=== RUN TestCRUDGetEntitiesCPOrderBy
--- PASS: TestCRUDGetEntitiesCPOrderBy (0.01s)
=== RUN TestCRUDGetEntitiesCPOrderByDesc
--- PASS: TestCRUDGetEntitiesCPOrderByDesc (0.01s)
=== RUN TestCRUDGetEntitiesCPParamOrderBy
--- PASS: TestCRUDGetEntitiesCPParamOrderBy (0.01s)
=== RUN TestCRUDGetEntitiesCPParamOrderByDesc
--- PASS: TestCRUDGetEntitiesCPParamOrderByDesc (0.01s)
=== RUN TestCRUDGetEntitiesCPOrderByDescLimit
--- PASS: TestCRUDGetEntitiesCPOrderByDescLimit (0.01s)
=== RUN TestCRUDGetEntitiesCPOrderByDescLimitOffset
--- PASS: TestCRUDGetEntitiesCPOrderByDescLimitOffset (0.01s)
=== RUN TestCRUDGetEntitiesCPOrderByAscLimitOffset
--- PASS: TestCRUDGetEntitiesCPOrderByAscLimitOffset (0.01s)
=== RUN TestCRUDGetEntitiesCPTestOffsetOrderByAscLimitOffset
--- PASS: TestCRUDGetEntitiesCPTestOffsetOrderByAscLimitOffset (0.01s)
PASS
ok github.com/1414C/sqac 0.724s
If running against sqlite is not an option, the test suite may be run against any of the supported database systems. When running against a non-sqlite db, a connection string must be supplied via the cs flag. See the Connection Strings section for database-specific connection string formats. The following invocation of the test suite is targeting as PostgreSQL database via the -db postgres and corresponding -cs “connection_string” flags:
go test -v -db postgres -cs "host=127.0.0.1 user=my_uname dbname=my_dbname sslmode=disable password=my_passwd"