Skip to content

Commit

Permalink
Minor changes (code cleaning)
Browse files Browse the repository at this point in the history
Some code cleaning and added the documentation
  • Loading branch information
InvaderZim85 committed Apr 23, 2020
1 parent 5cdfb9a commit df22f3c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ZimLabs.Database.MySql/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public MySqlConnection Connection
{
get
{
if (_connection == null || _connection.State == ConnectionState.Closed || _connection.State == ConnectionState.Broken)
if (_connection == null || _connection.State == ConnectionState.Closed ||
_connection.State == ConnectionState.Broken)
CreateConnection();

return _connection;
Expand Down
4 changes: 2 additions & 2 deletions ZimLabs.Database.MySql/ZimLabs.Database.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<RepositoryUrl>https://github.com/InvaderZim85/ZimLabs.Database.MySql</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Helper, Database, MySql, Connector</PackageTags>
<Version>1.0.2</Version>
<PackageReleaseNotes>Made the helper function public which provides two methods to convert a string into a secure string and the otherway round</PackageReleaseNotes>
<Version>1.0.3</Version>
<PackageReleaseNotes>Minor changes (code cleaning)</PackageReleaseNotes>
<AssemblyVersion>1.0.2.0</AssemblyVersion>
<FileVersion>1.0.2.0</FileVersion>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-slate
78 changes: 78 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ZimLabs.Database.MsSql

![Nuget](https://img.shields.io/nuget/v/ZimLabs.Database.MySql) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/InvaderZim85/ZimLabs.Database.MySql)

This project provides a simple way to create a connection to a MSSQL database.

## Installation

You can install this package via NuGet or download the sources.

```powershell
Install-Package ZimLabs.Database.MySql
```

## Usage
The usage of the connector is very easy.

The package provides for differen constructors:

```csharp
using ZimLabs.Database.MySql;

// 1: Constructor with server and database name.
var connector = new Connector("Server", "Database", "User", "Password", 3306); // The port is optional. Default value is 3306
// 2: Constructor with server, database, user and password (this time as SecureString)
var connector = new Connector("Server", "Database", "User", "Password".ToSecureString(), 3306);

// 3: Constructor with a defined connection string
var conString = new MySqlConnectionStringBuilder
{
Server = "Server",
Database = "Database",
UserID = "User",
Password = "Password",
Port = 3306
}.ConnectionString.ToSecureString();

var connector = new Connector(conString);

// 4: Constructor with settings class
var settings = new DatabaseSettings
{
Server = "127.0.0.1",
Database = "MyFancyDatabase",
UserId = "Username",
Password = "Password".ToSecureString(),
Port = 3306
};

var connector = new Connector(settings);
```

> **NOTE**: If you use the constructor `Connector(string dataSource, string initialCatalog)` the value for the parameter `IntegratedSecurity` will be set to `true`.
> **NOTE**: The extension method `ToSecureString()` is located in the `Helper` class, which is a part of the package.
## Example
Here a small example (with usage of [Dapper](https://dapper-tutorial.net))

```csharp
// The settings
var settings = new DatabaseSettings
{
Server = "127.0.0.1",
Database = "MyFancyDatabase",
UserId = "Username",
Password = "Password".ToSecureString(),
Port = 3306
};

var connector = new Connector(settings);

// Perform a query
const string query = "SELECT Id, Name, Mail FROM person AS p";

var personList = connector.Connection.Query<Person>(query).ToList();
```

0 comments on commit df22f3c

Please sign in to comment.