-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connection to SingleStore (#812)
* feat: connection to SingleStore * test: do not run SingleStore QA on AppVeyor * docs: update automatically generated documentation related to schemes --------- Co-authored-by: AppVeyor bot <[email protected]>
- Loading branch information
Showing
23 changed files
with
460 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using DubUrl.Querying.Dialects; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DubUrl.Mapping.Database; | ||
|
||
[Database<SingleStoreDialect>( | ||
"SingleStore" | ||
, ["singlestore", "single"] | ||
, DatabaseCategory.Warehouse | ||
)] | ||
[Brand("singlestore", "#AA00FF")] | ||
public class SingleStoreDatabase : IDatabase | ||
{ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using DubUrl.Mapping.Database; | ||
using DubUrl.Querying.Dialects; | ||
using DubUrl.Querying.Parametrizing; | ||
using DubUrl.Rewriting.Implementation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DubUrl.Mapping.Implementation; | ||
|
||
[Mapper<SingleStoreDatabase, NamedParametrizer>( | ||
"SingleStoreConnector" | ||
)] | ||
public class SingleStoreMapper : BaseMapper | ||
{ | ||
public SingleStoreMapper(DbConnectionStringBuilder csb, IDialect dialect, IParametrizer parametrizer) | ||
: base(new SingleStoreRewriter(csb), | ||
dialect, | ||
parametrizer | ||
) | ||
{ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
DubUrl.Core/Querying/Dialects/Renderers/SingleStoreRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using DubUrl.Querying.Dialects.Formatters; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DubUrl.Querying.Dialects.Renderers; | ||
|
||
internal class SingleStoreRenderer : MySqlRenderer | ||
{ | ||
public SingleStoreRenderer() | ||
: base(new ValueFormatter() | ||
.With(new FunctionFormatter<TimeSpan>("TIME", new IntervalAsTimeFormatter())) | ||
.With(new FunctionFormatter<DateOnly>("DATE", new DateFormatter())) | ||
.With(new FunctionFormatter<TimeOnly>("TIME", new TimeFormatter())) | ||
.With(new FunctionFormatter<DateTime>("TIMESTAMP", new TimestampFormatter())) | ||
) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using DubUrl.Querying.Dialects.Casters; | ||
using DubUrl.Querying.Dialects.Renderers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DubUrl.Querying.Dialects; | ||
|
||
[Renderer<SingleStoreRenderer>()] | ||
[ReturnCaster<BooleanConverter>] | ||
[ReturnCaster<DateTimeCaster<DateOnly>>] | ||
[ReturnCaster<TimeSpanCaster<TimeOnly>>] | ||
[ParentLanguage<SqlLanguage>] | ||
public class SingleStoreDialect : BaseDialect | ||
{ | ||
internal SingleStoreDialect(ILanguage language, string[] aliases, IRenderer renderer, ICaster[] casters) | ||
: base(language, aliases, renderer, casters) { } | ||
} |
71 changes: 71 additions & 0 deletions
71
DubUrl.Core/Rewriting/Implementation/SingleStoreRewriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using DubUrl.Parsing; | ||
using DubUrl.Rewriting.Tokening; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DubUrl.Rewriting.Implementation; | ||
|
||
internal class SingleStoreRewriter : ConnectionStringRewriter | ||
{ | ||
private const string EXCEPTION_DATABASE_NAME = "SingleStore"; | ||
protected internal const string SERVER_KEYWORD = "Server"; | ||
protected internal const string PORT_KEYWORD = "Port"; | ||
protected internal const string DATABASE_KEYWORD = "Database"; | ||
protected internal const string USERNAME_KEYWORD = "User ID"; | ||
protected internal const string PASSWORD_KEYWORD = "Password"; | ||
|
||
public SingleStoreRewriter(DbConnectionStringBuilder csb) | ||
: base(new UniqueAssignmentSpecificator(csb), | ||
[ | ||
new HostMapper(), | ||
new AuthentificationMapper(), | ||
new DatabaseMapper(), | ||
new OptionsMapper(), | ||
] | ||
) | ||
{ } | ||
|
||
protected SingleStoreRewriter(Specificator specificator, BaseTokenMapper[] tokenMappers) | ||
: base(specificator, tokenMappers) { } | ||
|
||
internal class HostMapper : BaseTokenMapper | ||
{ | ||
public override void Execute(UrlInfo urlInfo) | ||
{ | ||
Specificator.Execute(SERVER_KEYWORD, urlInfo.Host); | ||
if (urlInfo.Port > 0) | ||
Specificator.Execute(PORT_KEYWORD, urlInfo.Port); | ||
} | ||
} | ||
|
||
internal class AuthentificationMapper : BaseTokenMapper | ||
{ | ||
public override void Execute(UrlInfo urlInfo) | ||
{ | ||
if (!string.IsNullOrEmpty(urlInfo.Username)) | ||
Specificator.Execute(USERNAME_KEYWORD, urlInfo.Username); | ||
if (!string.IsNullOrEmpty(urlInfo.Password)) | ||
Specificator.Execute(PASSWORD_KEYWORD, urlInfo.Password); | ||
|
||
if (string.IsNullOrEmpty(urlInfo.Username)) | ||
throw new UsernameNotFoundException(); | ||
} | ||
} | ||
|
||
internal class DatabaseMapper : BaseTokenMapper | ||
{ | ||
public override void Execute(UrlInfo urlInfo) | ||
{ | ||
if (urlInfo.Segments==null || !urlInfo.Segments.Any()) | ||
throw new InvalidConnectionUrlMissingSegmentsException(EXCEPTION_DATABASE_NAME); | ||
else if (urlInfo.Segments.Length == 1) | ||
Specificator.Execute(DATABASE_KEYWORD, urlInfo.Segments.First()); | ||
else if (urlInfo.Segments.Length > 1) | ||
throw new InvalidConnectionUrlTooManySegmentsException(EXCEPTION_DATABASE_NAME, urlInfo.Segments); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select * from Customer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select FullName from Customer where CustomerId=? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select FullName from Customer where CustomerId=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
select | ||
* | ||
from | ||
Customer | ||
order by | ||
BirthDate desc | ||
limit | ||
? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using NUnit.Framework; | ||
using System.Diagnostics; | ||
using System.Data; | ||
using System.Data.Common; | ||
using DubUrl.Querying; | ||
using DubUrl.Querying.Reading; | ||
using DubUrl.Registering; | ||
using System.Reflection; | ||
|
||
namespace DubUrl.QA.SingleStore; | ||
|
||
[Category("SingleStore")] | ||
[Category("AdoProvider")] | ||
public class AdoProviderSingleStore : BaseAdoProvider | ||
{ | ||
public override string ConnectionString | ||
=> $"singlestore://root:Password12!@localhost/DubUrl"; | ||
|
||
[Test] | ||
public override void QueryCustomer() | ||
=> QueryCustomer("select FullName from Customer where CustomerId=1"); | ||
|
||
[Test] | ||
public override void QueryCustomerWithDatabase() | ||
=> QueryCustomerWithDatabase("select FullName from Customer where CustomerId=1"); | ||
|
||
[Test] | ||
public override void QueryCustomerWithParams() | ||
=> QueryCustomerWithParams("select FullName from Customer where CustomerId=@CustId"); | ||
|
||
[Test] | ||
public override void QueryCustomerWithPositionalParameter() | ||
=> QueryCustomerWithPositionalParameter("select FullName from Customer where CustomerId=?"); | ||
|
||
[Test] | ||
public override void QueryCustomerWithDapper() | ||
=> QueryCustomerWithDapper("select * from Customer"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using NUnit.Framework; | ||
using System.Diagnostics; | ||
using System.Data; | ||
using System.Data.Common; | ||
using DubUrl.Registering; | ||
|
||
namespace DubUrl.QA.SingleStore; | ||
|
||
[Category("SingleStore")] | ||
[Category("MariaDBDriver")] | ||
public class OdbcDriverMariaDb : BaseOdbcDriver | ||
{ | ||
public override string ConnectionString | ||
{ | ||
get => $"odbc+singlestore://root:Password12!@localhost/DubUrl"; | ||
} | ||
|
||
[Test] | ||
public override void QueryCustomer() | ||
=> QueryCustomer("select FullName from Customer where CustomerId=1"); | ||
|
||
[Test] | ||
public override void QueryCustomerWithParams() | ||
=> QueryCustomerWithParams("select FullName from Customer where CustomerId=?"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using NUnit.Framework; | ||
using System.Diagnostics; | ||
using System.Data; | ||
using System.Data.Common; | ||
using DubUrl.Registering; | ||
|
||
namespace DubUrl.QA.SingleStore; | ||
|
||
[Category("SingleStore")] | ||
[Category("MySQLDriver")] | ||
public class OdbcDriverMySQL : BaseOdbcDriver | ||
{ | ||
public override string ConnectionString | ||
{ | ||
get => $"odbc+singlestore://root:Password12!@localhost/DubUrl"; | ||
} | ||
|
||
[Test] | ||
public override void QueryCustomer() | ||
=> QueryCustomer("select FullName from Customer where CustomerId=1"); | ||
|
||
[Test] | ||
public override void QueryCustomerWithParams() | ||
=> QueryCustomerWithParams("select FullName from Customer where CustomerId=?"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
DROP DATABASE IF EXISTS DubUrl; | ||
CREATE DATABASE DubUrl; | ||
|
||
USE DubUrl; | ||
|
||
CREATE TABLE Customer ( | ||
CustomerId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, | ||
FullName VARCHAR(50), | ||
BirthDate DATE | ||
); | ||
|
||
INSERT INTO Customer (FullName, BirthDate) VALUES | ||
('Nikola Tesla', '1856-07-10') | ||
,('Albert Einstein', '1879-03-14') | ||
,('John von Neumann', '1903-12-28') | ||
,('Alan Turing', '1912-06-23') | ||
,('Linus Torvalds', '1969-12-28') | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Param( | ||
[switch] $force=$false | ||
, [string[]] $odbcDrivers = @("MariaDB", "MySQL") | ||
, [string] $config = "Release" | ||
, [string[]] $frameworks = @("net6.0", "net7.0") | ||
) | ||
. $PSScriptRoot\..\Run-TestSuite.ps1 | ||
. $PSScriptRoot\..\Docker-Container.ps1 | ||
. $PSScriptRoot\..\Windows-Service.ps1 | ||
|
||
if ($force) { | ||
Write-Host "Enforcing QA testing for SingleStore" | ||
} | ||
|
||
$filesChanged = & git diff --name-only HEAD HEAD~1 | ||
if ($force -or ($filesChanged -like "*singlestore*")) { | ||
Write-Host "Deploying SingleStore testing environment" | ||
|
||
# Starting docker container | ||
$previouslyRunning, $running = Deploy-Container -FullName "singlestore" | ||
if (!$previouslyRunning){ | ||
$waitForAvailable = 3 | ||
Write-host "`tWaiting $waitForAvailable seconds for the SingleStore server to be available ..." | ||
Start-Sleep -s $waitForAvailable | ||
Write-host "`tSingleStore Server is expected to be available." | ||
} | ||
|
||
# Deploying database based on script | ||
Write-host "`tCreating database using remote client on the docker container" | ||
& docker exec -it singlestoredb-dev singlestore -pPassword12! "--execute=$(Get-Content .\deploy-singlestore-database.sql)" | Out-Null | ||
Write-host "`tDatabase created" | ||
|
||
$odbcDriversInstalled = @() | ||
# Installing ODBC driver | ||
# Should call a single script to install MariaDB and MySQL ODBC drivers | ||
|
||
# Running QA tests | ||
Write-Host "Running QA tests related to SingleStore" | ||
$suites = @("SingleStore+AdoProvider") | ||
foreach ($odbcDriverInstalled in $odbcDriversInstalled) { | ||
$suites += "SingleStore+ODBC+" + $odbcDriverInstalled + "Driver" | ||
} | ||
$testSuccessful = Run-TestSuite $suites -config $config -frameworks $frameworks | ||
|
||
# Stopping DB Service | ||
if (!$previouslyRunning) | ||
{ | ||
Remove-Container $running | ||
} | ||
|
||
# Raise failing tests | ||
exit $testSuccessful | ||
} else { | ||
return -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker run -d --name singlestoredb-dev -e SINGLESTORE_LICENSE="%SINGLESTORE_LICENSE%" -e ROOT_PASSWORD="Password12!" -p 3306:3306 -p 8080:8080 -p 9000:9000 ghcr.io/singlestore-labs/singlestoredb-dev:latest |
Oops, something went wrong.