-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b27064b
commit ba3f073
Showing
25 changed files
with
409 additions
and
25 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
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 |
---|---|---|
|
@@ -35,6 +35,7 @@ jobs: | |
GeneratedProtobuf | ||
MySqlConnectorExample | ||
NpgsqlExample | ||
SqliteExample | ||
- name: Verify pushed Dockerfile is synced | ||
run: | | ||
|
@@ -108,6 +109,7 @@ jobs: | |
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: wasm-file | ||
|
@@ -125,6 +127,11 @@ jobs: | |
- name: Updating plugin sha | ||
run: ./scripts/wasm/update_sha.sh ${SQLC_CI_FILE} | ||
|
||
- name: Verify pushed generated code is synced | ||
run: | | ||
./scripts/wasm/update_sha.sh ${SQLC_CI_FILE} | ||
sqlc -f ${SQLC_CI_FILE} diff | ||
- name: Codegen Tests against matrix of configurations | ||
run: ./scripts/tests/run_codegen_matrix.sh ${SQLC_CI_FILE} | ||
|
||
|
@@ -148,11 +155,6 @@ jobs: | |
uses: xom9ikk/[email protected] | ||
with: | ||
load-mode: strict | ||
|
||
- name: Verify pushed generated code is synced | ||
run: | | ||
./scripts/wasm/update_sha.sh ${SQLC_CI_FILE} | ||
sqlc -f ${SQLC_CI_FILE} diff | ||
|
||
- name: Docker compose | ||
uses: hoverkraft-tech/[email protected] | ||
|
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
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,72 @@ | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Plugin; | ||
using SqlcGenCsharp.Drivers.Generators; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; | ||
|
||
namespace SqlcGenCsharp.Drivers; | ||
|
||
public partial class SqliteDriver(DotnetFramework dotnetFramework) : DbDriver(dotnetFramework) | ||
{ | ||
protected override List<(string, Func<int, string>, HashSet<string>)> GetColumnMapping() | ||
{ | ||
return | ||
[ | ||
("byte[]", ordinal => $"Utils.GetBytes(reader, {ordinal})", ["blob"]), | ||
("string", ordinal => $"reader.GetString({ordinal})", ["text"]), | ||
("int", ordinal => $"reader.GetInt32({ordinal})", ["integer"]), | ||
("float", ordinal => $"reader.GetFloat({ordinal})", ["real"]), | ||
]; | ||
} | ||
|
||
public override UsingDirectiveSyntax[] GetUsingDirectives() | ||
{ | ||
return base.GetUsingDirectives() | ||
.Append(UsingDirective(ParseName("Microsoft.Data.Sqlite"))) | ||
.Append(UsingDirective(ParseName("System"))) | ||
.ToArray(); | ||
} | ||
|
||
public override (string, string) EstablishConnection(Query query) | ||
{ | ||
return ( | ||
$"var {Variable.Connection.Name()} = new SqliteConnection({Variable.ConnectionString.Name()})", | ||
$"{Variable.Connection.Name()}.Open()" | ||
); | ||
} | ||
|
||
public override string CreateSqlCommand(string sqlTextConstant) | ||
{ | ||
return $"var {Variable.Command.Name()} = new SqliteCommand({sqlTextConstant}, {Variable.Connection.Name()})"; | ||
} | ||
|
||
public override string TransformQueryText(Query query) | ||
{ | ||
return query.Params | ||
.Aggregate(query.Text, (current, currentParameter) => BindParameterRegex() | ||
.Replace(current, $"@{currentParameter.Column.Name.FirstCharToLower()}", 1)); | ||
} | ||
|
||
public override MemberDeclarationSyntax OneDeclare(string queryTextConstant, string argInterface, | ||
string returnInterface, Query query) | ||
{ | ||
return new OneDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); | ||
} | ||
|
||
public override MemberDeclarationSyntax ExecDeclare(string queryTextConstant, string argInterface, Query query) | ||
{ | ||
return new ExecDeclareGen(this).Generate(queryTextConstant, argInterface, query); | ||
} | ||
|
||
public override MemberDeclarationSyntax ManyDeclare(string queryTextConstant, string argInterface, | ||
string returnInterface, Query query) | ||
{ | ||
return new ManyDeclareGen(this).Generate(queryTextConstant, argInterface, returnInterface, query); | ||
} | ||
|
||
[GeneratedRegex(@"\?")] | ||
private static partial Regex BindParameterRegex(); | ||
} |
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,80 @@ | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
using SqliteExample; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SqlcGenCsharpTests; | ||
|
||
public class SqliteTester : SqlDriverTester | ||
{ | ||
private static string ConnectionStringEnv => "SQLITE_CONNECTION_STRING"; | ||
|
||
private QuerySql QuerySql { get; } = | ||
new(Environment.GetEnvironmentVariable(ConnectionStringEnv)!); | ||
|
||
protected override async Task<long> CreateFirstAuthorAndTest() | ||
{ | ||
var createAuthorArgs = new QuerySql.CreateAuthorArgs | ||
{ | ||
Name = DataGenerator.BojackAuthor, | ||
Bio = DataGenerator.BojackTheme | ||
}; | ||
await QuerySql.CreateAuthor(createAuthorArgs); | ||
|
||
var actualAuthors = await QuerySql.ListAuthors(); | ||
Assert.That(actualAuthors[0] is | ||
{ | ||
Id: 1, | ||
Name: DataGenerator.BojackAuthor, | ||
Bio: DataGenerator.BojackTheme | ||
}); | ||
var insertedId = actualAuthors[0].Id; | ||
var getBojackAuthorArgs = new QuerySql.GetAuthorArgs { Id = insertedId }; | ||
var bojackAuthor = await QuerySql.GetAuthor(getBojackAuthorArgs); | ||
Assert.That(bojackAuthor is | ||
{ | ||
Name: DataGenerator.BojackAuthor, | ||
Bio: DataGenerator.BojackTheme | ||
}); | ||
return insertedId; | ||
} | ||
|
||
protected override async Task CreateSecondAuthorAndTest() | ||
{ | ||
var createAuthorArgs = new QuerySql.CreateAuthorArgs | ||
{ | ||
Name = DataGenerator.DrSeussAuthor, | ||
Bio = DataGenerator.DrSeussQuote | ||
}; | ||
await QuerySql.CreateAuthor(createAuthorArgs); | ||
var actualAuthors = await QuerySql.ListAuthors(); | ||
Assert.That(actualAuthors[0] is | ||
{ | ||
Name: DataGenerator.BojackAuthor, | ||
Bio: DataGenerator.BojackTheme | ||
}); | ||
Assert.That(actualAuthors[1] is | ||
{ | ||
Name: DataGenerator.DrSeussAuthor, | ||
Bio: DataGenerator.DrSeussQuote | ||
}); | ||
ClassicAssert.AreEqual(2, actualAuthors.Count); | ||
} | ||
|
||
protected override async Task DeleteFirstAuthorAndTest(long idToDelete) | ||
{ | ||
var deleteAuthorArgs = new QuerySql.DeleteAuthorArgs | ||
{ | ||
Id = Convert.ToInt32(idToDelete) | ||
}; | ||
await QuerySql.DeleteAuthor(deleteAuthorArgs); | ||
var authorRows = await QuerySql.ListAuthors(); | ||
Assert.That(authorRows[0] is | ||
{ | ||
Name: DataGenerator.DrSeussAuthor, | ||
Bio: DataGenerator.DrSeussQuote | ||
}); | ||
ClassicAssert.AreEqual(1, authorRows.Count); | ||
} | ||
} |
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
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
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,27 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace SqlcGenCsharp; | ||
|
||
public enum DriverName | ||
{ | ||
MySqlConnector, | ||
Npgsql, | ||
Sqlite | ||
} | ||
|
||
|
||
public static class DriverNameExtensions | ||
{ | ||
private static readonly Dictionary<DriverName, string> EnumToString = new() | ||
{ | ||
{ DriverName.MySqlConnector, "MySqlConnector" }, | ||
{ DriverName.Npgsql, "Npgsql" }, | ||
{ DriverName.Sqlite, "Microsoft.Data.Sqlite" } | ||
}; | ||
|
||
public static string ToName(this DriverName me) | ||
{ | ||
return EnumToString[me]; | ||
} | ||
} |
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
Oops, something went wrong.