{"id":13458248,"url":"https://github.com/jonwagner/Insight.Database","last_synced_at":"2025-03-24T15:31:03.736Z","repository":{"id":3034900,"uuid":"4055382","full_name":"jonwagner/Insight.Database","owner":"jonwagner","description":"Fast, lightweight .NET micro-ORM","archived":false,"fork":false,"pushed_at":"2025-01-08T18:41:58.000Z","size":7609,"stargazers_count":877,"open_issues_count":2,"forks_count":143,"subscribers_count":65,"default_branch":"main","last_synced_at":"2025-03-20T04:08:34.429Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonwagner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","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":"2012-04-17T17:44:25.000Z","updated_at":"2025-03-03T20:46:37.000Z","dependencies_parsed_at":"2023-02-19T01:16:10.710Z","dependency_job_id":"eb70d3a8-4f02-47c1-8fed-27dc665ba15a","html_url":"https://github.com/jonwagner/Insight.Database","commit_stats":{"total_commits":872,"total_committers":38,"mean_commits":22.94736842105263,"dds":"0.10321100917431192","last_synced_commit":"954e87af59f12bbfd2bd23f509b3a2758f9ac413"},"previous_names":[],"tags_count":139,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonwagner%2FInsight.Database","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonwagner%2FInsight.Database/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonwagner%2FInsight.Database/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonwagner%2FInsight.Database/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonwagner","download_url":"https://codeload.github.com/jonwagner/Insight.Database/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245119582,"owners_count":20563763,"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-31T09:00:48.374Z","updated_at":"2025-03-24T15:31:03.710Z","avatar_url":"https://github.com/jonwagner.png","language":"C#","readme":"# Insight.Database #\r\n\r\n**Insight.Database** is a fast, lightweight, (and dare we say awesome) micro-orm for .NET. It's available as a [NuGet Package](http://www.nuget.org/packages/Insight.Database/).\r\n\r\nWhoops. Forgot to mention easy. It's easy too. And you can also take control of pieces if you want to.\r\n\r\nLet's say you have a database and a class and you want them to work together. Something like this:\r\n\r\n```sql\r\nCREATE TABLE Beer ([ID] [int], [Type] varchar(128), [Description] varchar(128)) GO\r\nCREATE PROC InsertBeer @type varchar(128), @description varchar(128) AS\r\n\tINSERT INTO Beer (Type, Description) OUTPUT inserted.ID\r\n\t\tVALUES (@type, @description) GO\r\nCREATE PROC GetBeerByType @type [varchar] AS SELECT * FROM Beer WHERE Type = @type GO\r\n```\r\n```c#\r\npublic class Beer\r\n{\r\n\tpublic int ID { get; private set; }\r\n\tpublic string Type { get; set; }\r\n\tpublic string Description { get; set; }\r\n}\r\n\r\n\tvar beer = new Beer() { Type = \"ipa\", Description = \"Sly Fox 113\" };\r\n```\r\n\r\nLet's get Insight.Database:\r\n\r\n\tPM\u003e Install-Package Insight.Database\r\n\r\nIf you have a database other than SqlServer, use one of the alternate provider packages:\r\n\r\n```\r\n\tPM\u003e Install-Package Insight.Database.Providers.Postgres\r\n```\r\n\r\nNow, wire up those stored procedures to an interface with a single `connection.As\u003cT\u003e`:\r\n\r\n```c#\r\npublic interface IBeerRepository\r\n{\r\n\tvoid InsertBeer(Beer beer);\r\n\tIList\u003cBeer\u003e GetBeerByType(string type);\r\n\tvoid UpdateBeerList(IList\u003cBeer\u003e beerList);\r\n}\r\n\r\nvar repo = connection.As\u003cIBeerRepository\u003e();\r\n\r\nrepo.InsertBeer(beer);\r\nIList\u003cBeer\u003e beerList = repo.GetBeerByType(\"ipa\");\r\nrepo.UpdateBeerList(beerList);\r\n```\r\n\r\nLook, ma! No mapping code! (Plus, you can now inject that interface with a DI framework or mock the interface for testing.)\r\n\r\nWant to work at a lower level? Let's call a stored proc with an anonymous object. (It also automatically opens and closes the connection.)\r\n\r\n```c#\r\n// auto open/close\r\nconn.Execute(\"AddBeer\", new { Name = \"IPA\", Flavor = \"Bitter\"});\r\n```\r\n\r\nObjects are mapped automatically. No config files, no attributes. Just pure, clean magic:\r\n\r\n```c#\r\n// auto object mapping\r\nBeer beer = new Beer();\r\nconn.Execute(\"InsertBeer\", beer);\r\nList\u003cBeer\u003e beers = conn.Query\u003cBeer\u003e(\"FindBeer\", new { Name = \"IPA\" });\r\n```\r\n\r\nYes, even nested objects. Insight will just figure it out for you:\r\n\r\n```c#\r\n// auto object graphs\r\nvar servings = conn.Query\u003cServing, Beer, Glass\u003e(\"GetServings\");\r\nforeach (var serving in servings)\r\n\tConsole.WriteLine(\"{0} {1}\", serving.Beer.Name, serving.Glass.Ounces);\r\n```\r\n\r\nFeel free to return multiple result sets. We can handle them:\r\n\r\n```c#\r\n// multiple result sets\r\nvar results = conn.QueryResults\u003cBeer, Chip\u003e(\"GetBeerAndChips\", new { Pub = \"Fergie's\" }));\r\nIList\u003cBeer\u003e beer = results.Set1;\r\nIList\u003cChip\u003e chips = results.Set2;\r\n```\r\n\r\nOr perhaps you want to return multiple independent recordsets, with one-to-many and one-to-one relationships. It's not possible! Or is it?\r\n\r\n```c#\r\nvar results = conn.Query(\"GetLotsOfStuff\", parameters,\r\n\tQuery.Returns(OneToOne\u003cBeer, Glass\u003e.Records)\r\n\t\t.ThenChildren(Some\u003cNapkin\u003e.Records)\r\n\t\t.Then(Some\u003cWine\u003e.Records));\r\nvar beer = results.Set1;\r\nvar glass = beer.Glass;\r\nvar napkins = beer.Napkins.ToList();\r\nvar wine = results.Set2;\r\n```\r\n\r\nBut...but how? To that, I say: it's magic! Insight can decode the records and figure out one-to-one and parent-child relationships automatically. Almost all the time, it does this with no work or configuration on your part. But if you have a wacky model, there are plenty of non-scary ways to tell Insight how to work with your data. Read the [wiki](https://github.com/jonwagner/Insight.Database/wiki) for details.\r\n\r\nFull async support. Just add `Async`:\r\n\r\n```c#\r\nvar task = c.QueryAsync\u003cBeer\u003e(\"FindBeer\", new { Name = \"IPA\" });\r\n```\r\n\r\nSend whole lists of objects to databases that support table parameters. No more multiple queries or weird parameter mapping:\r\n\r\n```sql\r\n-- auto table parameters\r\nCREATE TYPE BeerTable (Name [nvarchar](256), Flavor [nvarchar](256))\r\nCREATE PROCEDURE InsertBeer (@BeerList [BeerTable])\r\n```\r\n```c#\r\nList\u003cBeer\u003e beerList = new List\u003cBeer\u003e();\r\nconn.Execute(\"InsertBeer\", new { BeerList = beerList });\r\n```\r\n\r\nInsight can also stream objects over your database's BulkCopy protocol. \r\n\r\n```c#\r\n// auto bulk-copy objects\r\nIEnumerable\u003cBeer\u003e beerList; // from somewhere\r\nconn.BulkCopy(\"Beer\", beerList);\r\n```\r\n\r\nOh, wait. You want to inline your SQL. We do that too. Just add Sql.\r\n\r\n```c#\r\nvar beerList = conn.QuerySql\u003cBeer\u003e(\"SELECT * FROM Beer WHERE Name LIKE @Name\", new { Name = \"%ipa%\" });\r\nconn.ExecuteSql (\"INSERT INTO Beer VALUES (ID, Name)\", beer);\r\n```\r\n\r\nSeriously, everything just works automatically. But if you *really* want to control every aspect of mapping, see the [wiki](https://github.com/jonwagner/Insight.Database/wiki).\r\n\r\n## Motto ##\r\n\r\nInsight.Database is the .NET micro-ORM that nobody knows about because it's so easy, automatic, and fast, (and well-documented) that nobody asks questions about it on StackOverflow.\r\n\r\n## Licensing ##\r\n\r\nInsight.Database is available under any of the following licenses:\r\n\r\n* The \"Tell Everyone You Know How Awesome Insight Is\" License\r\n* The \"Answer Every Stackoverflow ORM question with 'Use Insight.Database'\" License\r\n* The \"Buy A Friend A Beer\" License\r\n* The \"Do Some Good\" (Karmic) License\r\n* MS-Public License (Until version 5.X.X)\r\n* MIT License (From version 6.X.X and above)\r\n\r\n## Support Insight.Database ##\r\n\r\nShop through my Amazon Affiliate Link: [Amazon - Shop. Connect. Enjoy. All from Earth's Biggest Selection.](http://www.amazon.com/ref=assoc_tag_ph_1390604847723?_encoding=UTF8\u0026camp=1789\u0026creative=9325\u0026linkCode=pf4\u0026tag=jmileswagner-20)\r\n\r\nGo ahead. You know you need to buy something anyway...\r\n\r\n\r\n## Major Insight Releases ##\r\n\r\n* v8.0 - Support for .NET 8.0. Note that many unpopular providers have been removed.\r\n* v6.3 - Microsoft.Data.SqlClient compatibility, c# 8 interface default methods, cleaned up package organization.\r\n* v6.0 - .Net Standard 2.0 compatibility. \r\n* v5.0 - Composite keys, Deep parameter binding. \r\n* v4.0 - Read one-to-one, one-to-many, and many-to-many relationships automatically, with ways to extend it.\r\n* v3.0 - Support for most common database and tools. See [the list of supported providers](https://github.com/jonwagner/Insight.Database/wiki/Insight-and-Data-Providers).\r\n* v2.1 - Automatically [implement an interface](https://github.com/jonwagner/Insight.Database/wiki/Auto-Interface-Implementation) with database calls.\r\n* v2.0 - Performance and asynchronous release.\r\n* v1.0 - Let the magic begin!\r\n\r\n## Documentation ##\r\n\r\n**Full documentation is available on the [wiki](https://github.com/jonwagner/Insight.Database/wiki)**\r\n\r\n","funding_links":[],"categories":["C\\#","C# #","ORM","Audio"],"sub_categories":["GUI - other"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonwagner%2FInsight.Database","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonwagner%2FInsight.Database","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonwagner%2FInsight.Database/lists"}