{"id":25914476,"url":"https://github.com/ntdls/ntdls.sqlserverdapperwrapper","last_synced_at":"2025-03-03T11:20:53.892Z","repository":{"id":246786354,"uuid":"823197532","full_name":"NTDLS/NTDLS.SqlServerDapperWrapper","owner":"NTDLS","description":"Nuget package that makes it super easy to manage connectivity to and talk to SQL Server.","archived":false,"fork":false,"pushed_at":"2024-12-31T11:58:39.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T05:54:28.521Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/NTDLS.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-02T15:08:35.000Z","updated_at":"2024-12-31T11:58:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"b90adedf-612b-434f-be84-572fe4961405","html_url":"https://github.com/NTDLS/NTDLS.SqlServerDapperWrapper","commit_stats":null,"previous_names":["ntdls/ntdls.sqlserverdapperwrapper"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTDLS%2FNTDLS.SqlServerDapperWrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTDLS%2FNTDLS.SqlServerDapperWrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTDLS%2FNTDLS.SqlServerDapperWrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NTDLS%2FNTDLS.SqlServerDapperWrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NTDLS","download_url":"https://codeload.github.com/NTDLS/NTDLS.SqlServerDapperWrapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241652964,"owners_count":19997578,"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":"2025-03-03T11:20:53.033Z","updated_at":"2025-03-03T11:20:53.880Z","avatar_url":"https://github.com/NTDLS.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NTDLS.SqlServerDapperWrapper\n\n📦 Be sure to check out the NuGet package: https://www.nuget.org/packages/NTDLS.SqlServerDapperWrapper\n\nProvides a simple interface to a SQL Server database with automatic cleanup and stored procedure detection.\nAll managed and wrapped in Dapper (hence the name).\n\n\u003e**Examples:**\nKeep in mind that you can also use the **SqlServerManagedInstance** directly if you really want long lived processes.\n\n\n```csharp\npublic static SqlServerManagedFactory MyConnection { get; set; } = new(\"localhost\", \"tempdb\");\n```\n\n```csharp\n\n//Each time a statement/query is executed, the NTDLS.SqlServerDapperWrapper will\n//  open a connection, execute then close \u0026 dispose the connection. \nMyConnection.Execute(\"DROP TABLE IF EXISTS Test\");\n```\n\n```csharp\n//We can execure procedures, t-sql text, or embedded .sql files:\n\n//Test procedure execution.\nvar procValue = MyConnection.ExecuteScalar\u003cDateTime\u003e(\"TestProc\");\nConsole.WriteLine($\"procValue: {procValue}\");\n\n//Test tSQL execution.\nvar textValue = MyConnection.ExecuteScalar\u003cDateTime\u003e(\"SELECT GetDate()\");\nConsole.WriteLine($\"textValue: {textValue}\");\n\n//Test embedded resource script execution.\nvar sqlValue = MyConnection.ExecuteScalar\u003cDateTime\u003e(\"TestSqlFile.sql\");\nConsole.WriteLine($\"sqlValue: {textValue}\");\n```\n\n```csharp\n//Creates a table in two different databases from a script that is an embedded resource in the project.\nMyConnection.Execute(\"CREATE TABLE Test( Id int identity(1,1) not null, [Name] varchar(128) NOT NULL, [Description] varchar(128) NULL)\");\n\n```\n```csharp\n//Deletes the data from the table \"Test\".\nMyConnection.Execute(\"DELETE FROM Test\");\n\n//Insert some records using an inline statement and parameters.\nfor (int i = 0; i \u003c 100; i++)\n{\n    var param = new\n    {\n        Name = $\"Name #{i}\",\n        Description = Guid.NewGuid().ToString()\n    };\n\n    MyConnection.Execute(\"INSERT INTO Test (Name, Description) VALUES (@Name, @Description)\", param);\n}\n\n```\n```csharp\n//We can use \"Ephemeral\" to perform multiple steps on the same connection, such as here where we\n//  begin a transaction, insert data and then optionally commit or rollback the transaction.\n//  The connection is closed and disposed after Ephemeral() executes.\nMyConnection.Ephemeral(o =\u003e\n{\n    using var tx = o.BeginTransaction();\n\n    try\n    {\n        for (int i = 0; i \u003c 100; i++)\n        {\n            var param = new\n            {\n                Name = $\"Name #{i}\",\n                Description = Guid.NewGuid().ToString()\n            };\n\n            o.Execute(\"INSERT INTO Test (Name, Description) VALUES (@Name, @Description)\", param);\n        }\n\n        tx.Commit();\n    }\n    catch\n    {\n        tx.Rollback();\n        throw;\n    }\n});\n\n```\n```csharp\n\n//Just getting the results and writing them to the console.\nvar results = MyConnection.Query\u003cTestModel\u003e(\"SELECT * FROM Test\");\n//Print the results.\nforeach (var result in results)\n{\n    Console.WriteLine($\"{result.Id} {result.Name} {result.Description}\");\n}\n}\n```\n\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntdls%2Fntdls.sqlserverdapperwrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fntdls%2Fntdls.sqlserverdapperwrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntdls%2Fntdls.sqlserverdapperwrapper/lists"}