{"id":22880940,"url":"https://github.com/vit-orm/vitorm.clickhouse","last_synced_at":"2025-05-07T02:43:05.173Z","repository":{"id":244900864,"uuid":"815786492","full_name":"Vit-Orm/Vitorm.ClickHouse","owner":"Vit-Orm","description":"a lightweight yet comprehensive ORM for ClickHouse","archived":false,"fork":false,"pushed_at":"2025-01-12T14:38:40.000Z","size":239,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-02T04:17:11.869Z","etag":null,"topics":["clickhouse","database","orm","vitorm"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Vit-Orm.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-06-16T06:36:03.000Z","updated_at":"2025-01-12T14:33:23.000Z","dependencies_parsed_at":"2024-06-18T06:50:33.725Z","dependency_job_id":"e9a8ba4a-d964-463e-afb2-d4b28f46d071","html_url":"https://github.com/Vit-Orm/Vitorm.ClickHouse","commit_stats":null,"previous_names":["vitormlib/vitorm.clickhouse","vit-orm/vitorm.clickhouse"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.ClickHouse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.ClickHouse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.ClickHouse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vit-Orm%2FVitorm.ClickHouse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vit-Orm","download_url":"https://codeload.github.com/Vit-Orm/Vitorm.ClickHouse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252802607,"owners_count":21806537,"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":["clickhouse","database","orm","vitorm"],"created_at":"2024-12-13T17:28:44.660Z","updated_at":"2025-05-07T02:43:05.149Z","avatar_url":"https://github.com/Vit-Orm.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\n# Vitorm.ClickHouse\nVitorm.ClickHouse is a lightweight yet comprehensive ORM for ClickHouse that strikes the perfect balance between simplicity and functionality.     \nSimilar to Dapper in its lightweight design, Vitorm offers an easy-to-use, efficient interface for data access.     \nHowever, it doesn't stop there; Vitorm goes beyond basic ORM capabilities to provide a rich feature set akin to Entity Framework.     \nThis means you get the best of both worlds: the performance and simplicity of Dapper with the robust features and flexibility of Entity Framework, making Vitorm an ideal choice for developers seeking a powerful yet streamlined ORM solution.\n\u003e source address: [https://github.com/Vit-Orm/Vitorm.ClickHouse](https://github.com/Vit-Orm/Vitorm.ClickHouse \"https://github.com/Vit-Orm/Vitorm.ClickHouse\")        \n\n![](https://img.shields.io/github/license/Vit-Orm/Vitorm.ClickHouse.svg)  \n![](https://img.shields.io/github/repo-size/Vit-Orm/Vitorm.ClickHouse.svg)  ![](https://img.shields.io/github/last-commit/Vit-Orm/Vitorm.ClickHouse.svg)  \n \n\n| Build | NuGet |\n| -------- | -------- |\n|![](https://github.com/Vit-Orm/Vitorm.ClickHouse/workflows/ki_devops3_build/badge.svg) | [![](https://img.shields.io/nuget/v/Vitorm.ClickHouse.svg)](https://www.nuget.org/packages/Vitorm.ClickHouse) ![](https://img.shields.io/nuget/dt/Vitorm.ClickHouse.svg) |\n\n\n\n\n# Vitorm.ClickHouse Documentation\nThis guide will walk you through the steps to set up and use Vitorm.ClickHouse.\n\nsupported features:\n\n| feature    |  method   |  remarks   |     |\n| --- | --- | --- | --- |\n|  create table   |  TryCreateTable   |     |     |\n|  drop table   |  TryDropTable   |     |     |\n| --- | --- | --- | --- |\n|  create records   |  Add AddRange   |     |     |\n|  retrieve  records |  Query Get   |     |     |\n|  delete records   |  Delete DeleteRange DeleteByKey DeleteByKeys ExecuteDelete   |     |     |\n| --- | --- | --- | --- |\n|  change table   |  ChangeTable    |  change mapping table from database   |   |\n|  change database  |  ChangeDatabase   | change database to be connected  |   |\n| --- | --- | --- | --- |\n|  collection total count   |  TotalCount    |  Collection Total Count without Take and Skip   |   |\n|  collection total count and list  |  ToListAndTotalCount   | query List and TotalCount in one request  |   |\n|     |     |   |   |\n\n\n## Installation\nBefore using Vitorm, install the necessary package:    \n``` bash\ndotnet add package Vitorm.ClickHouse\n```\n\n## Minimum viable demo\n``` csharp\nusing Vitorm;\nnamespace App\n{\n    public class Program_Min\n    {\n        static void Main2(string[] args)\n        {\n            // #1 Init\n            using var dbContext = new Vitorm.Sql.SqlDbContext();\n            dbContext.UseClickHouse(\"Host=localhost;Port=8123;Database=dev-orm;User=default;Password=;Compress=True;CheckCompressedHash=False;Compressor=lz4;\");\n\n            // #2 Query\n            var user = dbContext.Get\u003cUser\u003e(1);\n            var users = dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToList();\n        }\n\n        // Entity Definition\n        [System.ComponentModel.DataAnnotations.Schema.Table(\"User\")]\n        public class User\n        {\n            [System.ComponentModel.DataAnnotations.Key]\n            public int id { get; set; }\n            public string name { get; set; }\n            public DateTime? birth { get; set; }\n            public int? fatherId { get; set; }\n        }\n    }\n}\n```\n\n\n## Full Example\n\u003e This example provides a comprehensive guide to utilizing Vitorm for basic and advanced database operations while maintaining lightweight performance.    \n``` csharp\nusing Vitorm;\n\nnamespace App\n{\n    public class Program\n    {\n        static void Main(string[] args)\n        {\n            // #1 Configures Vitorm\n            using var dbContext = new Vitorm.Sql.SqlDbContext();\n            dbContext.UseClickHouse(\"Host=localhost;Port=8123;Database=dev-orm;User=default;Password=;Compress=True;CheckCompressedHash=False;Compressor=lz4;\");\n\n            // #2 Create Table\n            dbContext.TryDropTable\u003cUser\u003e();\n            dbContext.TryCreateTable\u003cUser\u003e();\n\n            // #3 Insert Records\n            dbContext.Add(new User { id = 1, name = \"lith\" });\n            dbContext.AddRange(new[] {\n                new User { id = 2, name = \"lith\", fatherId = 1 },\n                new User { id = 3, name = \"lith\", fatherId = 1 }\n            });\n\n            // #4 Query Records\n            {\n                var user = dbContext.Get\u003cUser\u003e(1);\n                var users = dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToList();\n                var sql = dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToExecuteString();\n            }\n\n            // #5 Update Records\n\n\n            // #6 Delete Records\n            dbContext.Delete\u003cUser\u003e(new User { id = 1, name = \"lith1\" });\n            dbContext.DeleteRange(new[] {\n                new User { id = 2, name = \"lith2\", fatherId = 1 },\n                new User { id = 3, name = \"lith3\", fatherId = 2 }\n            });\n            dbContext.DeleteByKey\u003cUser\u003e(1);\n            dbContext.DeleteByKeys\u003cUser, int\u003e(new[] { 1, 2 });\n            dbContext.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\"))\n                .ExecuteDelete();\n\n            // #7 Join Queries\n            {\n                var query =\n                        from user in dbContext.Query\u003cUser\u003e()\n                        from father in dbContext.Query\u003cUser\u003e().Where(father =\u003e user.fatherId == father.id).DefaultIfEmpty()\n                        where father != null\n                        orderby user.id\n                        select new { user, father };\n\n                var sql = query.ToExecuteString();\n                var users = query.ToList();\n            }\n\n            // #8 Transactions\n            {\n                using var tran1 = dbContext.BeginTransaction();\n                dbContext.Update(new User { id = 4, name = \"u4001\" });\n\n                using (var tran2 = dbContext.BeginTransaction())\n                {\n                    dbContext.Update(new User { id = 4, name = \"u4002\" });\n                    // will rollback\n                }\n\n                using (var tran2 = dbContext.BeginTransaction())\n                {\n                    dbContext.Update(new User { id = 4, name = \"u4002\" });\n                    tran2.Rollback();\n                }\n\n                using (var tran2 = dbContext.BeginTransaction())\n                {\n                    dbContext.Update(new User { id = 4, name = \"u4003\" });\n                    tran2.Commit();\n                }\n\n                tran1.Commit();\n            }\n        }\n\n        // Entity Definition\n        [System.ComponentModel.DataAnnotations.Schema.Table(\"User\")]\n        public class User\n        {\n            [System.ComponentModel.DataAnnotations.Key]\n            public int id { get; set; }\n            public string name { get; set; }\n            public DateTime? birth { get; set; }\n            public int? fatherId { get; set; }\n        }\n    }\n}\n```\n\n## Explanation   \n1. **Setup**: Initializes the database and configures Vitorm.\n2. **Create Table**: Drops and recreates the `User` table.\n3. **Insert Records**: Adds single and multiple user records.\n4. **Query Records**: Retrieves user records using various querying methods.\n5. **Update Records**: Updates single and multiple user records.\n6. **Delete Records**: Deletes single and multiple user records.\n7. **Join Queries**: Performs a join operation between user and father records.\n8. **Transactions**: Demonstrates nested transactions and rollback/commit operations.\n9. **Database Functions**: Uses custom database functions in queries.\n\n\n\n# Vitorm.Data Documentation    \nVitorm.Data is a static class that allows you to use Vitorm without explicitly creating or disposing of a DbContext.    \n \n## Installation    \nBefore using Vitorm.Data, install the necessary package:    \n``` bash\ndotnet add package Vitorm.Data\ndotnet add package Vitorm.ClickHouse\n```\n\n## Config settings\n``` json\n// appsettings.json\n{\n  \"Vitorm\": {\n    \"Data\": [\n      {\n        \"provider\": \"ClickHouse\",\n        \"namespace\": \"App\",\n        \"connectionString\": \"Host=localhost;Port=8123;Database=dev-orm;User=default;Password=;Compress=True;CheckCompressedHash=False;Compressor=lz4;\"\n      }\n    ]\n  }\n}\n```\n\n## Minimum viable demo\n\u003e After configuring the `appsettings.json` file, you can directly perform queries without any additional configuration or initialization, `Vitorm.Data` is that easy to use.    \n``` csharp\nusing Vitorm;\nnamespace App\n{\n    public class Program_Min\n    {\n        static void Main2(string[] args)\n        {\n            //  Query Records\n            var user = Data.Get\u003cUser\u003e(1);\n            var users = Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToList();\n        }\n\n        // Entity Definition\n        [System.ComponentModel.DataAnnotations.Schema.Table(\"User\")]\n        public class User\n        {\n            [System.ComponentModel.DataAnnotations.Key]\n            public int id { get; set; }\n            public string name { get; set; }\n            public DateTime? birth { get; set; }\n            public int? fatherId { get; set; }\n        }\n    }\n}\n\n```\n\n## Full Example    \n``` csharp\nusing Vitorm;\n\nnamespace App\n{\n    public class Program\n    {\n        static void Main(string[] args)\n        {\n            // #1 No need to init Vitorm.Data\n\n            // #2 Create Table\n            Data.TryDropTable\u003cUser\u003e();\n            Data.TryCreateTable\u003cUser\u003e();\n\n            // #3 Insert Records\n            Data.Add(new User { id = 1, name = \"lith\" });\n            Data.AddRange(new[] {\n                new User { id = 2, name = \"lith\", fatherId = 1 },\n                new User { id = 3, name = \"lith\", fatherId = 1 }\n            });\n\n            // #4 Query Records\n            {\n                var user = Data.Get\u003cUser\u003e(1);\n                var users = Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToList();\n                var sql = Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\")).ToExecuteString();\n            }\n\n            // #5 Update Records\n\n\n            // #6 Delete Records\n            Data.Delete\u003cUser\u003e(new User { id = 1, name = \"lith1\" });\n            Data.DeleteRange(new[] {\n                new User { id = 2, name = \"lith2\", fatherId = 1 },\n                new User { id = 3, name = \"lith3\", fatherId = 2 }\n            });\n            Data.DeleteByKey\u003cUser\u003e(1);\n            Data.DeleteByKeys\u003cUser, int\u003e(new[] { 1, 2 });\n            Data.Query\u003cUser\u003e().Where(u =\u003e u.name.Contains(\"li\"))\n                .ExecuteDelete();\n\n            // #7 Join Queries\n            {\n                var query =\n                        from user in Data.Query\u003cUser\u003e()\n                        from father in Data.Query\u003cUser\u003e().Where(father =\u003e user.fatherId == father.id).DefaultIfEmpty()\n                        where father != null\n                        orderby user.id\n                        select new { user, father };\n\n                var sql = query.ToExecuteString();\n                var users = query.ToList();\n            }\n\n            // #8 Transactions\n        }\n\n        // Entity Definition\n        [System.ComponentModel.DataAnnotations.Schema.Table(\"User\")]\n        public class User\n        {\n            [System.ComponentModel.DataAnnotations.Key]\n            public int id { get; set; }\n            public string name { get; set; }\n            public DateTime? birth { get; set; }\n            public int? fatherId { get; set; }\n        }\n    }\n}\n```\n\n\n[Test Example](https://github.com/Vit-Orm/Vitorm.ClickHouse/tree/master/test/Vitorm.ClickHouse.MsTest)    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvit-orm%2Fvitorm.clickhouse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvit-orm%2Fvitorm.clickhouse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvit-orm%2Fvitorm.clickhouse/lists"}