1- using BotSharp . Plugin . SqlDriver . Models ;
21using Microsoft . Data . SqlClient ;
32using MySqlConnector ;
3+ using Npgsql ;
44using static Dapper . SqlMapper ;
55
66namespace BotSharp . Plugin . SqlDriver . Functions ;
@@ -26,12 +26,15 @@ public async Task<bool> Execute(RoleDialogModel message)
2626 }
2727
2828 // check if need to instantely
29- var settings = _services . GetRequiredService < SqlDriverSetting > ( ) ;
30- var result = settings . DatabaseType switch
29+ var dbHook = _services . GetRequiredService < ISqlDriverHook > ( ) ;
30+ var dbType = dbHook . GetDatabaseType ( message ) ;
31+
32+ var result = dbType switch
3133 {
32- "MySql" => RunQueryInMySql ( args ) ,
33- "SqlServer" => RunQueryInSqlServer ( args ) ,
34- _ => throw new NotImplementedException ( $ "Database type { settings . DatabaseType } is not supported.")
34+ "mysql" => RunQueryInMySql ( args ) ,
35+ "sqlserver" => RunQueryInSqlServer ( args ) ,
36+ "redshift" => RunQueryInRedshift ( args ) ,
37+ _ => throw new NotImplementedException ( $ "Database type { dbType } is not supported.")
3538 } ;
3639
3740 if ( result == null )
@@ -70,4 +73,16 @@ private IEnumerable<dynamic> RunQueryInSqlServer(SqlStatement args)
7073 }
7174 return connection . Query ( args . Statement , dictionary ) ;
7275 }
76+
77+ private IEnumerable < dynamic > RunQueryInRedshift ( SqlStatement args )
78+ {
79+ var settings = _services . GetRequiredService < SqlDriverSetting > ( ) ;
80+ using var connection = new NpgsqlConnection ( settings . RedshiftConnectionString ) ;
81+ var dictionary = new Dictionary < string , object > ( ) ;
82+ foreach ( var p in args . Parameters )
83+ {
84+ dictionary [ "@" + p . Name ] = p . Value ;
85+ }
86+ return connection . Query ( args . Statement , dictionary ) ;
87+ }
7388}
0 commit comments