private void CreateTableRevision(IDbConnection db, IDbTransaction t, int revision) { var viewName = GetResourceName(); { var sql = SqliteBuilder.CreateTableSql(viewName, _members, revision, false); db.Execute(sql, transaction: t); } if (SupportsSearch) { var sql = SqliteBuilder.AfterInsertTriggerSql(viewName, _members, revision); db.Execute(sql, transaction: t); } foreach (var member in _members.GetValueTypeFields()) { if (member.Name.Equals(nameof(IResource.Id))) { IndexMember(db, t, revision, member, true); } if (member.HasAttribute <IndexAttribute>()) { IndexMember(db, t, revision, member, false); } } // FIXME: deal with user field name collisions { var sql = SqliteBuilder.CreateIndexSql(GetResourceName(), "IsDeleted", revision, false); db.Execute(sql, transaction: t); } if (SupportsSearch) { var sql = SqliteBuilder.CreateTableSql(viewName, _members, revision, true); db.Execute(sql, transaction: t); } }
public static Dictionary <string, object> InsertSql <T>(T resource, string resourceName, ITypeReadAccessor reads, AccessorMembers members, int revision, long?sequence, bool deleted, out string sql) { if (resource == null) { throw new NullReferenceException(); } var hash = new Dictionary <string, object> { { "Sequence", sequence ! } }; sql = Pooling.StringBuilderPool.Scoped(sb => { var fields = members.GetValueTypeFields(); sb.Append("INSERT INTO '"); sb.Append(resourceName); sb.Append("_V"); sb.Append(revision); sb.Append("' ("); for (var i = 0; i < fields.Length; i++) { if (i != 0) { sb.Append(", "); } var column = fields[i]; sb.Append("\""); sb.Append(column.Name); sb.Append("\""); } if (deleted) { sb.Append(", \"IsDeleted\""); } sb.Append(", \"Sequence\") VALUES ("); for (var i = 0; i < fields.Length; i++) { if (i != 0) { sb.Append(", "); } var column = fields[i]; sb.Append(":"); sb.Append(column.Name); } if (deleted) { sb.Append(", 1"); } sb.Append(", :Sequence)"); foreach (var member in fields) { if (!member.CanRead) { continue; } if (reads.TryGetValue(resource, member.Name, out var value)) { hash.Add(member.Name, value); } } }); return(hash); }