{"id":17312255,"url":"https://github.com/zcpua/manager","last_synced_at":"2026-05-19T10:03:13.305Z","repository":{"id":57653033,"uuid":"452174720","full_name":"zcpua/manager","owner":"zcpua","description":"Manager is used for initializing a database connection pool(sql.DB in go's standard library)","archived":false,"fork":false,"pushed_at":"2022-03-16T12:01:49.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T06:27:44.054Z","etag":null,"topics":["mysql","sql"],"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/zcpua.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-26T07:09:46.000Z","updated_at":"2023-03-16T07:37:44.000Z","dependencies_parsed_at":"2022-08-31T23:02:19.412Z","dependency_job_id":null,"html_url":"https://github.com/zcpua/manager","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/zcpua%2Fmanager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcpua%2Fmanager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcpua%2Fmanager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcpua%2Fmanager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zcpua","download_url":"https://codeload.github.com/zcpua/manager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245761301,"owners_count":20667895,"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":["mysql","sql"],"created_at":"2024-10-15T12:42:52.870Z","updated_at":"2026-05-19T10:03:13.253Z","avatar_url":"https://github.com/zcpua.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Manager\n\nManager is used for initializing a database connection pool(sql.DB in go's standard library) \n\nThe original way to initialize a sql.DB is something like：\n\n```go\npool,err := sql.Open(\"mysql\", dataSourceName)\n```\nAnd the format of `dataSourceName` is：\n\n```\n[username[:password]@][protocol[(address)]]/dbname[?param1=value1\u0026...\u0026paramN=valueN]\n```\n\nWhat the manager does is providing a series of simple methods which help you setting these parameters.\n\n### Example\n```go\n\nimport (\n\t\"net/url\"\n\t\"database/sql\"\n\t\"github.com/zcpua/manager\"\n\t_ \"github.com/go-sql-driver/mysql\"\n)\n\nvar db *sql.DB\nvar err error\ndb, err = manager.New(dbName, user, password, host).Set(\n\t\tmanager.SetCharset(\"utf8\"),\n\t\tmanager.SetParseTime(true),\n\t\tmanager.SetLoc(\"Asia/Shanghai\"),\n        manager.SetTimeZone(\"Asia/Shanghai\"),\n        ).Port(3306).Open(true)\n\n```\n\n\u003e `godoc` is a great tool for scanning the API documentation\n\n### Basic API\n\n`func New(dbName, user, password, host string) *Option`\n\nNew returns an Option\n\n`func (o *Option) Driver(driver string) *Option`\n\nDriver sets the driver, default mysql\n\n`func (o *Option) Open(ping bool) (*sql.DB, error)`\n\nOpen is used for creating a *sql.DB.If ping=true,it will exec the db.Ping() after creating the db object\n\n`func (o *Option) Port(port int) *Option`\n\nPort sets the server port,default 3306\n\n`func (o *Option) Set(sets ...Setting) *Option`\n\nSet receives a series of Set*-like functions\n\n---\n\n### Setting APIs\nFor more details see [DSN-Data-Source-Name](https://github.com/go-sql-driver/mysql#dsn-data-source-name)\n\n* `SetAllowAllFiles`: allowAllFiles=true disables the file Whitelist for LOAD DATA LOCAL INFILE and allows all files. Might be insecure!\n* `SetAllowCleartextPasswords`: allowCleartextPasswords=true allows using thecleartext client side plugin if required by an account, such as one defined with the PAM authentication plugin. Sending passwords in clear text may be a security problem in some configurations.\n* `SetAllowNativePasswords`: Allows the usage of the mysql native password method\n* `SetAutoCommit`: Set it to true if you know what you are doing\n* `SetCharset`: Sets the charset used for client-server interaction\n* `SetClientFoundRows`: clientFoundRows=true causes an UPDATE to return the number of matching rows instead of the number of rows changed.\n* `SetCollation`: Sets the collation used for client-server interaction on connection. In contrast to charset, collation does not issue additional queries. If the specified collation is unavailable on the target server,the connection will fail.\n* `SetColumnsWithAlias`: When columnsWithAlias is true, calls to sql.Rows.Columns() will return the table alias and the column name separated by a dot.\n* `SetInterpolateParams`: If interpolateParams is true, placeholders (?) in calls to db.Query() and db.Exec() are interpolated into a single query string with given parameters. This reduces the number of roundtrips, since the driver has to prepare a statement, execute it with given parameters and close the statement again with interpolateParams=false.\n* `SetLoc`: SetLoc Sets the location for time.Time values (when using parseTime=true). \"Local\" sets the system's location. See time.LoadLocation in standard library for detail.\n* `SetParseTime`: SetParseTime if set true changes the DATE and DATETIME type in mysql will be stored in a time.Time object rather than the []byte / string\n* `SetReadTimeout`: SetReadTimeout I/O read timeout. timeout ∈ [1ms, 24h) \n* `SetStrict`: SetStrict strict=true enables the strict mode in which MySQL warnings are treated as errors.\n* `SetTimeout`: SetTimeout Driver side connection timeout. timeout ∈ [1ms, 24h)\n* `SetWriteTimeout`: SetWriteTimeout I/O write timeout. timeout ∈ [1ms, 24h) ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzcpua%2Fmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzcpua%2Fmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzcpua%2Fmanager/lists"}