Skip to content

Commit

Permalink
Fixing PG
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros committed Oct 17, 2019
1 parent 8e05dd6 commit 13b7f1b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/YesSql.Core/Commands/CreateIndexCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public override async Task ExecuteAsync(DbConnection connection, DbTransaction t
var type = Index.GetType();
var documentTable = CollectionHelper.Current.GetPrefixedName(Store.DocumentTable);

var sql = Inserts(type, dialect);
logger.LogTrace(sql);
Index.Id = await connection.ExecuteScalarAsync<int>(sql, Index, transaction);


if (Index is MapIndex)
{
var sql = Inserts(type, dialect);
logger.LogTrace(sql);
Index.Id = await connection.ExecuteScalarAsync<int>(sql, Index, transaction);
var command = "update " + dialect.QuoteForTableName(_tablePrefix + type.Name) + " set " + dialect.QuoteForColumnName("DocumentId") + " = @mapid where " + dialect.QuoteForColumnName("Id") + " = @Id";
logger.LogTrace(command);
await connection.ExecuteAsync(command, new { mapid = Index.GetAddedDocuments().Single().Id, Id = Index.Id }, transaction);
Expand All @@ -41,10 +43,6 @@ public override async Task ExecuteAsync(DbConnection connection, DbTransaction t
{
var reduceIndex = Index as ReduceIndex;

var sql = Inserts(type, dialect) + " " + dialect.IdentitySelectString + " " + dialect.QuoteForColumnName("Id");
logger.LogTrace(sql);
Index.Id = await connection.ExecuteScalarAsync<int>(sql, Index, transaction);

var bridgeTableName = type.Name + "_" + documentTable;
var columnList = dialect.QuoteForColumnName(type.Name + "Id") +", " + dialect.QuoteForColumnName("DocumentId");
var bridgeSql = "insert into " + dialect.QuoteForTableName(_tablePrefix + bridgeTableName) + " (" + columnList + ") values (@Id, @DocumentId);";
Expand Down
1 change: 0 additions & 1 deletion src/YesSql.Provider.Common/SqlBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YesSql.Sql
Expand Down
2 changes: 1 addition & 1 deletion src/YesSql.Provider.PostgreSql/PostgreSqlDialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public PostgreSqlDialect()
public override string Name => "PostgreSql";
public override string InOperator(string values) => " = any(array[" + values + "])";
public override string NotInOperator(string values) => " <> all(array[" + values + "])";
public override string IdentitySelectString => "RETURNING ";
public override string IdentitySelectString => "RETURNING";
public override string IdentityColumnString => "SERIAL PRIMARY KEY";
public override bool SupportsIfExistsBeforeTableName => true;
public override bool PrefixIndex => true;
Expand Down

0 comments on commit 13b7f1b

Please sign in to comment.