{"id":13412265,"url":"https://github.com/minus5/gofreetds","last_synced_at":"2025-03-14T18:31:03.965Z","repository":{"id":5824383,"uuid":"7039830","full_name":"minus5/gofreetds","owner":"minus5","description":"Go Sql Server database driver.","archived":false,"fork":false,"pushed_at":"2020-11-30T22:32:55.000Z","size":2165,"stargazers_count":113,"open_issues_count":18,"forks_count":48,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-10-25T04:09:59.216Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/minus5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2012-12-06T17:29:26.000Z","updated_at":"2024-09-12T22:50:09.000Z","dependencies_parsed_at":"2022-08-27T21:02:21.320Z","dependency_job_id":null,"html_url":"https://github.com/minus5/gofreetds","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minus5%2Fgofreetds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minus5%2Fgofreetds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minus5%2Fgofreetds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minus5%2Fgofreetds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minus5","download_url":"https://codeload.github.com/minus5/gofreetds/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243625072,"owners_count":20321227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:22.773Z","updated_at":"2025-03-14T18:31:03.628Z","avatar_url":"https://github.com/minus5.png","language":"Go","funding_links":[],"categories":["Database Drivers","Relational Databases","数据库驱动程序","数据库驱动","Generators","数据库驱动`连接和操作数据库工具`","Data Integration Frameworks","\u003cspan id=\"数据库驱动-database-drivers\"\u003e数据库驱动 Database Drivers\u003c/span\u003e"],"sub_categories":["Relational Database Drivers","Advanced Console UIs","关系数据库驱动程序","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"## gofreetds\n\nGo [FreeTDS](http://www.freetds.org/) wrapper. Native Sql Server database driver.\n\nFeatures:\n\n  * can be used as [database/sql](http://golang.org/pkg/database/sql/) driver\n  * handles calling [stored procedures](#stored-procedures)\n  * handles multiple resultsets\n  * supports database mirroring\n  * connection pooling\n  * scaning resultsets into structs\n\n## Get started\n\n### Install dependencines\n\n[FreeTDS](http://www.freetds.org/) libraries must be installed on the system.\n\nMac\n```shell\nbrew install freetds\n```\nUbuntu, Debian...\n```shell\nsudo apt-get install freetds-dev\n```\n\n### Go get\n\n```\ngo get github.com/minus5/gofreetds\n```\n\n### Docs\n\n  http://godoc.org/github.com/minus5/gofreetds\n\n\n## Using as database/sql driver\n\nName of the driver is mssql.\n```go\ndb, err := sql.Open(\"mssql\", connStr)\n...\nrow := db.QueryRow(\"SELECT au_fname, au_lname name FROM authors WHERE au_id = ?\", \"172-32-1176\")\n..\nvar firstName, lastName string\nerr = row.Scan(\u0026firstName, \u0026lastName)\n```\nFull example in example/mssql.\n\n## Stored Procedures\n\nWhat I'm missing in database/sql is calling stored procedures, handling return values and output params. And especially handling multiple result sets.\nWhich is all supported by FreeTDS and of course by gofreetds.\n\nConnect:\n```go\npool, err := freetds.NewConnPool(\"user=ianic;pwd=ianic;database=pubs;host=iow\")\ndefer pool.Close()\n...\n//get connection\nconn, err := pool.Get()\ndefer conn.Close()\n```\nExecute stored procedure:\n```go\nrst, err := conn.ExecSp(\"sp_help\", \"authors\")  \n```\nRead sp return value, and output params:\n```go\nreturnValue := rst.Status()\nvar param1, param2 int\nrst.ParamScan(\u0026param1, \u0026param2)\n```\nRead sp resultset (fill the struct):\n```go\nauthor := \u0026Author{}\nrst.Scan(author)\n```\nRead next resultset:\n```go\nif rst.NextResult() {\n    for rst.Next() {\n        var v1, v2 string\n        rst.Scan(\u0026v1, \u0026v2)\n    }\n}\n```\nFull example in example/stored_procedure\n\n## Other usage\n\nExecuting arbitrary sql is supported with Exec or ExecuteSql.\n\nExecute query:\n```go\nrst, err := conn.Exec(\"select au_id, au_lname, au_fname from authors\")\n```\nRst is array of results.\nEach result has Columns and Rows array.\nEach row is array of values. Each column is array of ResultColumn objects.\n\nFull example in example/exec.\n\nExecute query with params:\n```go\nrst, err := conn.ExecuteSql(\"select au_id, au_lname, au_fname from authors where au_id = ?\", \"998-72-3567\")\n```\n\n## Sybase Compatibility Mode\n\nGofreetds now supports Sybase ASE 16.0 through the driver. In order to support this, this post is very helpful: [Connect to MS SQL Server and Sybase ASE from Mac OS X and Linux with unixODBC and FreeTDS (from Internet Archive)](http://web.archive.org/web/20160325095720/http://2tbsp.com/articles/2012/06/08/connect-ms-sql-server-and-sybase-ase-mac-os-x-and-linux-unixodbc-and-freetds)\n\nTo use a Sybase ASE server with Gofreetds, you simply need to set a compatibility mode on your connection string after you've configured your .odbc.ini file and .freetds.conf file.\n\nThis mode uses TDS Version 5.\n\n### Connection String Parameter\n\nYou can set your connection string up for Sybase by using the 'compatibility_mode' Parameter. The parameter can be named 'compatibility', 'compatibility mode', 'compatibility_mode' or 'Compatibility Mode'. Currently this mode only supports Sybase. To specify you can use 'sybase' or 'Sybase'.\n\n```\nServer=myServerAddress;Database=myDatabase;User Id=myUsername;Password=myPassword;Failover Partner=myMirror;Max Pool Size=200;Compatibility Mode=Sybase\n```\n\n\n## Testing\n\nTests depend on the pubs database.\n\nPubs sample database install script could be [downloaded](http://www.microsoft.com/en-us/download/details.aspx?id=23654).\nAfter installing that package you will find\ninstpubs.sql on the disk (C:\\SQL Server 2000 Sample\nDatabases). Execute that script to create pubs database.\n\nTests and examples are using environment variable GOFREETDS_CONN_STR to connect to the pubs database.\n\n```shell\nexport GOFREETDS_CONN_STR=\"user=ianic;pwd=ianic;database=pubs;host=iow\"\nexport GOFREETDS_MIRROR_HOST=\"iow-mirror\"\n```\nIf you don't want to setup and test database mirroring than don't define GOFREETDS_MIRROR_HOST. Mirroring tests will be skipped.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminus5%2Fgofreetds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminus5%2Fgofreetds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminus5%2Fgofreetds/lists"}