Skip to content

Commit

Permalink
Added async functions for AbstractRecord/List (breaking interface!)
Browse files Browse the repository at this point in the history
Removed username stuff along the way
  • Loading branch information
danielgindi committed Aug 27, 2019
1 parent d0fd5ca commit 3561ec0
Show file tree
Hide file tree
Showing 10 changed files with 643 additions and 241 deletions.
303 changes: 171 additions & 132 deletions SequelNet.SchemaGenerator.VSIX/SchemaGenerator/InsertMethod.cs

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions SequelNet.SchemaGenerator.VSIX/SchemaGenerator/Parse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,10 @@ private static void ParseScript(ScriptContext context, string[] scriptLines)
{
context.InsertAutoIncrement = true;
}
else if (currentLineTrimmed.StartsWith("@NoCreatedBy", StringComparison.OrdinalIgnoreCase))
{
context.NoCreatedBy = true;
}
else if (currentLineTrimmed.StartsWith("@NoCreatedOn", StringComparison.OrdinalIgnoreCase))
{
context.NoCreatedOn = true;
}
else if (currentLineTrimmed.StartsWith("@NoModifiedBy", StringComparison.OrdinalIgnoreCase))
{
context.NoModifiedBy = true;
}
else if (currentLineTrimmed.StartsWith("@NoModifiedOn", StringComparison.OrdinalIgnoreCase))
{
context.NoModifiedOn = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,18 @@ private static void WriteRecord(StringBuilder stringBuilder, ScriptContext conte
stringBuilder.AppendFormat("public override object GetPrimaryKeyValue(){0}{{{0}return {1};{0}}}{0}{0}", "\r\n",
string.IsNullOrEmpty(context.SingleColumnPrimaryKeyName) ? "null" : context.SingleColumnPrimaryKeyName);

WriteGetInsertQuery(stringBuilder, context);
stringBuilder.Append("\r\n");
WriteGetUpdateQuery(stringBuilder, context);
stringBuilder.Append("\r\n");
WriteInsertMethod(stringBuilder, context);
stringBuilder.Append("\r\n");
WriteInsertAsyncMethod(stringBuilder, context);
stringBuilder.Append("\r\n");
WriteUpdateMethod(stringBuilder, context);
stringBuilder.Append("\r\n");
WriteUpdateAsyncMethod(stringBuilder, context);
stringBuilder.Append("\r\n");
WriteReadMethod(stringBuilder, context);

stringBuilder.AppendFormat("{0}#endregion{0}{0}", "\r\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public class ScriptContext
public bool AtomicUpdates = false;
public bool SnakeColumnNames = false;
public bool InsertAutoIncrement = false;
public bool NoCreatedBy = false;
public bool NoCreatedOn = false;
public bool NoModifiedBy = false;
public bool NoModifiedOn = false;

public string SingleColumnPrimaryKeyName = null;
Expand Down
56 changes: 40 additions & 16 deletions SequelNet.SchemaGenerator.VSIX/SchemaGenerator/UpdateMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@ namespace SequelNet.SchemaGenerator
{
public partial class GeneratorCore
{
private static void WriteUpdateMethod(StringBuilder stringBuilder, ScriptContext context)
private static void WriteGetUpdateQuery(StringBuilder stringBuilder, ScriptContext context)
{
stringBuilder.AppendFormat("public override void Update(ConnectorBase conn = null, string userName = null){0}{{{0}", "\r\n");
stringBuilder.AppendFormat("public override Query GetUpdateQuery(){0}{{{0}", "\r\n");

bool hasModifiedBy = context.Columns.Find((DalColumn c) => c.PropertyName == "ModifiedBy") != null;
bool hasModifiedOn = context.Columns.Find((DalColumn c) => c.PropertyName == "ModifiedOn") != null;

if (context.AtomicUpdates && (hasModifiedBy || hasModifiedOn))
if (context.AtomicUpdates && (hasModifiedOn))
{
stringBuilder.AppendFormat(@"if (HasMutatedColumns()){0}{{{0}", "\r\n");
}

if (!context.NoModifiedBy)
{
if (context.Columns.Find((DalColumn c) => c.PropertyName == "ModifiedBy") != null)
{
stringBuilder.AppendFormat("ModifiedBy = userName;{0}", "\r\n");
}
}

if (!context.NoModifiedOn)
{
if (context.Columns.Find((DalColumn c) => c.PropertyName == "ModifiedOn") != null)
Expand All @@ -34,12 +25,12 @@ private static void WriteUpdateMethod(StringBuilder stringBuilder, ScriptContext
}
}

if (context.AtomicUpdates && (hasModifiedBy || hasModifiedOn))
if (context.AtomicUpdates && (hasModifiedOn))
{
stringBuilder.AppendFormat(@"}}{0}", "\r\n");
}

if (hasModifiedBy || hasModifiedOn)
if (hasModifiedOn)
{
stringBuilder.Append("\r\n");
}
Expand Down Expand Up @@ -80,13 +71,46 @@ private static void WriteUpdateMethod(StringBuilder stringBuilder, ScriptContext
isFirst = false;
}

stringBuilder.AppendFormat("{0}", "\r\n");
stringBuilder.AppendFormat("{0}return qry = null;{0}", "\r\n");

stringBuilder.AppendFormat("}}{0}}}{0}", "\r\n");
}

private static void WriteUpdateMethod(StringBuilder stringBuilder, ScriptContext context)
{
stringBuilder.AppendFormat("public override void Update(ConnectorBase conn = null){0}{{{0}", "\r\n");

stringBuilder.AppendFormat("var qry = GetUpdateQuery();{0}{0}", "\r\n");

if (context.AtomicUpdates)
{
stringBuilder.AppendFormat("if (qry.HasInsertsOrUpdates){0}{{{0}", "\r\n");
}

stringBuilder.AppendFormat("qry.Execute(conn);{0}", "\r\n");

if (context.AtomicUpdates)
{
stringBuilder.AppendFormat("}}{0}", "\r\n");
stringBuilder.AppendFormat("{0}MarkAllColumnsNotMutated();{0}", "\r\n");
}

stringBuilder.AppendFormat("}}{0}", "\r\n");
}

private static void WriteUpdateAsyncMethod(StringBuilder stringBuilder, ScriptContext context)
{
stringBuilder.AppendFormat("public override Task UpdateAsync(ConnectorBase connection = null, CancellationToken? cancellationToken = null){0}{{{0}", "\r\n");

stringBuilder.AppendFormat("var qry = GetUpdateQuery();{0}{0}", "\r\n");

if (context.AtomicUpdates)
{
stringBuilder.AppendFormat("if (qry.HasInsertsOrUpdates){0}{{{0}", "\r\n");
}

stringBuilder.AppendFormat("qry.ExecuteAsync(conn, cancellationToken);{0}", "\r\n");

if (context.AtomicUpdates)
{
stringBuilder.AppendFormat("}}{0}", "\r\n");
Expand All @@ -95,5 +119,5 @@ private static void WriteUpdateMethod(StringBuilder stringBuilder, ScriptContext

stringBuilder.AppendFormat("}}{0}", "\r\n");
}
}
}
}
1 change: 1 addition & 0 deletions SequelNet/Sql/Query/Executes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public int Execute(out object lastInsertId, ConnectorBase connection = null)
/// <param name="connection">An existing connection to use.</param>
/// <param name="lastInsertId">Where to put the last inserted ROWID</param>
/// <returns>Number of affected rows</returns>
[Obsolete]
public int Execute(ConnectorBase connection, out object lastInsertId)
{
return Execute(out lastInsertId, connection);
Expand Down
Loading

0 comments on commit 3561ec0

Please sign in to comment.