{"id":15002480,"url":"https://github.com/zaid-ajaj/throwawaydb","last_synced_at":"2025-10-30T08:31:19.663Z","repository":{"id":34880746,"uuid":"186654036","full_name":"Zaid-Ajaj/ThrowawayDb","owner":"Zaid-Ajaj","description":"Dead simple integration tests with SQL Server or Postgres throwaway databases that are created on the fly, used briefly then disposed of automagically.","archived":false,"fork":false,"pushed_at":"2024-01-16T19:41:55.000Z","size":79,"stargazers_count":142,"open_issues_count":5,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-02T07:22:55.884Z","etag":null,"topics":["integration-tests","sql","sql-server","testing"],"latest_commit_sha":null,"homepage":"","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/Zaid-Ajaj.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":"2019-05-14T15:49:47.000Z","updated_at":"2025-01-16T02:52:42.000Z","dependencies_parsed_at":"2024-06-19T09:17:02.060Z","dependency_job_id":null,"html_url":"https://github.com/Zaid-Ajaj/ThrowawayDb","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/Zaid-Ajaj%2FThrowawayDb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaid-Ajaj%2FThrowawayDb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaid-Ajaj%2FThrowawayDb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaid-Ajaj%2FThrowawayDb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zaid-Ajaj","download_url":"https://codeload.github.com/Zaid-Ajaj/ThrowawayDb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238945668,"owners_count":19556700,"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":["integration-tests","sql","sql-server","testing"],"created_at":"2024-09-24T18:50:39.849Z","updated_at":"2025-10-30T08:31:14.357Z","avatar_url":"https://github.com/Zaid-Ajaj.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ThrowawayDb\n\nEasily create a disposable database that integration tests dead simple for Sql server using throwaway databases.\n\n### Available Packages\n\n| Package              | Supports   | Version                                                                                                                               |\n| -------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------- |\n| ThrowawayDb          | SQL Server | [![Nuget](https://img.shields.io/nuget/v/ThrowawayDb.svg?colorB=green)](https://www.nuget.org/packages/ThrowawayDb)                   |\n| ThrowawayDb.Postgres | Postgres   | [![Nuget](https://img.shields.io/nuget/v/ThrowawayDb.Postgres.svg?colorB=green)](https://www.nuget.org/packages/ThrowawayDb.Postgres) |\n| ThrowawayDb.MySQL    | MySQL      | [![Nuget](https://img.shields.io/nuget/v/ThrowawayDb.MySql.svg?colorB=green)](https://www.nuget.org/packages/ThrowawayDb.MySql)       |\n\n## Using SQL Server\n\nInstall `ThrowawayDb` from Nuget\n```\ndotnet add package ThrowawayDb\n```\nUse from your code\n```csharp\npublic static void Main(string[] args)\n{\n    using (var database = ThrowawayDatabase.FromLocalInstance(\"localhost\\\\SQLEXPRESS\"))\n    {\n        Console.WriteLine($\"Created database {database.Name}\");\n\n        // - Apply database migrations here if necessary\n        // - Seed the database with data\n        // - Execute your code against this database\n        using var connection = new SqlConnection(database.ConnectionString);\n        connection.Open();\n        using var cmd = new SqlCommand(\"SELECT 1\", connection);\n        var result = Convert.ToInt32(cmd.ExecuteScalar());\n        Console.WriteLine(result);\n    }\n}\n```\nIn the snippet above, a dummy database with a random name is created using the current local instance of SQL Express on my machine. Moreover, the object `database` is an `IDisposable` and will drop the database at the end of the `using` clause when it's `Dispose()` is executed. It is that simple!\n\nYou can create the throwaway database in multiple ways:\n```cs\n// from Sql Express server locally with Integrated security\nThrowawayDatabase.FromLocalInstance(\"localhost\\\\SQLEXPRESS\");\n\n// Uses the default instance locally where Data Source = .\nThrowawayDatabase.FromDefaultLocalInstance();\n\n// Using SQL Authentication with user credentials and an arbibrary host\nThrowawayDatabase.Create(username: \"Zaid\", password: \"strongPassword\", host: \"192.168.1.100\");\n\n// Using a connection string where Initial Catalog is master\nThrowawayDatabase.Create(connectionString: \"Data Source=localhost\\\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True;\");\n\n// Specify a custom database prefix, otherwise it just uses ThrowawayDb\nThrowawayDatabase.FromLocalInstance(\"localhost\\\\SQLEXPRESS\", \"dbprefix_\");\n```\n\n#### SQL server snapshot\nYou can create a snapshot of the database and restore it at a later point:\n```cs\nusing var database = ThrowawayDatabase.FromLocalInstance(\"localhost\\\\SQLEXPRESS\");\n\n// execute necessary actions before initialising a snapshot\ndatabase.CreateSnapshot();\n\n// execute some other actions which modify the database\ndatabase.RestoreSnapshot();\n```\nA snapshot can also be created as a snapshot scope. This way you ensure that the RestoreSnapshot method is always called.\n```cs\nusing var database = ThrowawayDatabase.FromLocalInstance(\"localhost\\\\SQLEXPRESS\");\n\nusing(var scope = database.CreateSnapshotScope())\n{\n    // execute actions that modifies the database, and that should only last inside this scope.\n}\n```\n\n## Using PostgreSQL server\nInstall `ThrowawayDb.Postgres` from Nuget\n```\ndotnet add package ThrowawayDb.Postgres\n```\nuse from your code:\n```cs\nstatic void Main(string[] args)\n{\n    using (var database = ThrowawayDatabase.Create(username: \"postgres\", password: \"postgres\", host: \"localhost\"))\n    {\n        using var connection = new NpgsqlConnection(database.ConnectionString);\n        connection.Open();\n        using var cmd = new NpgsqlCommand(\"SELECT 1\", connection);\n        var result = Convert.ToInt32(cmd.ExecuteScalar());\n        Console.WriteLine(result);\n    }\n}\n```\n\n## Using MySQL server\nYou can create the throwaway database in multiple ways:\n```cs\n// Using SQL Authentication with user credentials and an arbibrary host\nThrowawayDatabase.Create(userName: \"Zaid\", password: \"strongPassword\", server: \"localhost\");\n\n// Using a connection string where Initial Catalog is master\nThrowawayDatabase.Create(connectionString: \"server=localhost;user id=Zaid;password=strongPassword;\");\n\n// Specify a custom database prefix, otherwise it just uses ThrowawayDb\nThrowawayDatabase.Create(userName: \"Zaid\", password: \"strongPassword\", server: \"localhost\", \"dbprefix_\");\n\n// Specify all options\nThrowawayDatabase.Create(\"server=localhost;user id=Zaid;password=strongPassword;\", new ThrowawayDatabaseOptions\n{\n    DatabaseNamePrefix = \"dbprefix_\",\n    Collation = \"ujis_japanese_ci\"\n});\n```\n#### MySQL snapshot\nYou can create a snapshot of the database and restore it at a later point:\n```cs\nusing var database = ThrowawayDatabase.Create(\"Zaid\", \"strongPassword\", \"localhost\");\n\n// execute necessary actions before initialising a snapshot\ndatabase.CreateSnapshot();\n\n// execute some other actions which modify the database\ndatabase.RestoreSnapshot();\n```\n\n### Running build targets for development\n```\n./build.sh --target {TargetName}\n```\nor\n```\nbuild --target {TargetName}\n```\nWhere `{TargetName}` is the name of a target in build/buid.cs","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaid-ajaj%2Fthrowawaydb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaid-ajaj%2Fthrowawaydb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaid-ajaj%2Fthrowawaydb/lists"}