tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
DatabaseConnectionFactory.cs
Go to the documentation of this file.
1using System;
2using System.Data.Common;
3
4using Microsoft.Data.SqlClient;
5using Microsoft.Data.Sqlite;
6
7using MySqlConnector;
8
9using Npgsql;
10
12
14{
17 {
19 public DbConnection CreateConnection(string connectionString, DatabaseType databaseType)
20 {
21 ArgumentNullException.ThrowIfNull(connectionString);
22
23 return databaseType switch
24 {
25 DatabaseType.MariaDB or DatabaseType.MySql => new MySqlConnection(connectionString),
26 DatabaseType.SqlServer => new SqlConnection(connectionString),
27 DatabaseType.Sqlite => new SqliteConnection(connectionString),
28 DatabaseType.PostgresSql => new NpgsqlConnection(connectionString),
29 _ => throw new ArgumentOutOfRangeException(nameof(databaseType), databaseType, "Invalid DatabaseType!"),
30 };
31 }
32 }
33}
DbConnection CreateConnection(string connectionString, DatabaseType databaseType)
Create a DbConnection.A new DbConnection.
DatabaseType
Type of database to user.