Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Tomlinson committed Jul 29, 2023
1 parent ef4f74c commit 204ba92
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 49 deletions.
28 changes: 0 additions & 28 deletions src/Pgsql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,6 @@ public Pgsql(string schema, string table, NpgsqlConnection connection, ILogger l
_connection = connection;
}

// public async Task CreateTenantMetadataTableIfNotExistsAsync(NpgsqlTransaction transaction = null){
// var sql =
// @$"CREATE SCHEMA IF NOT EXISTS ""pluggable_metadata""
// AUTHORIZATION postgres;

// CREATE TABLE IF NOT EXISTS ""pluggable_metadata"".""tenant""
// (
// tenant_id text NOT NULL PRIMARY KEY COLLATE pg_catalog.""default""
// ,schema_id text NOT NULL
// ,table_id text NOT NULL
// ,insert_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
// ,last_expired_at TIMESTAMP WITH TIME ZONE NULL
// )
// TABLESPACE pg_default;
// ALTER TABLE IF EXISTS ""pluggable_metadata"".""tenant"" OWNER to postgres;

// CREATE INDEX IF NOT EXISTS pluggable_metadata_tenant_last_expired_at ON ""pluggable_metadata"".""tenant"" (last_expired_at ASC NULLS FIRST);
// ";

// _logger.LogDebug($"{nameof(CreateTenantMetadataTableIfNotExistsAsync)} - {sql}");

// await using (var cmd = new NpgsqlCommand(sql, _connection, transaction))
// await cmd.ExecuteNonQueryAsync();

// _logger.LogDebug($"{nameof(CreateTenantMetadataTableIfNotExistsAsync)} - Schema & Table Created : {_SafeSchema}");

// }

public async Task CreateSchemaIfNotExistsAsync(NpgsqlTransaction transaction = null)

Check warning on line 45 in src/Pgsql.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
var sql =
Expand Down
28 changes: 14 additions & 14 deletions src/Services/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ public async Task SetAsync(StateStoreSetRequest request, CancellationToken cance
return;
}

private int GetTTLfromOperationMetadata(IReadOnlyDictionary<string,string> metadata)
{
if (metadata.TryGetValue("ttlInSeconds", out string ttl))
return Convert.ToInt32(ttl);
return 0;
}

public async Task TransactAsync(StateStoreTransactRequest request, CancellationToken cancellationToken = default)
{
_logger.LogInformation($"{nameof(TransactAsync)} - Set/Delete");
Expand All @@ -151,17 +144,17 @@ public async Task TransactAsync(StateStoreTransactRequest request, CancellationT
foreach(var op in request.Operations)
{
await op.Visit(
onDeleteRequest: async (x) => {
var db = dbfactory(x.Metadata);
await db.DeleteAsync(x.Key, x.ETag ?? String.Empty, tran);
onDeleteRequest: async (delete) => {
var db = dbfactory(delete.Metadata);
await db.DeleteAsync(delete.Key, delete.ETag ?? String.Empty, tran);
},
onSetRequest: async (x) => {
var db = dbfactory(x.Metadata);
onSetRequest: async (set) => {
var db = dbfactory(set.Metadata);
// TODO : Need to implement 'something' here with regards to 'isBinary',
// but I do not know what this is trying to achieve. See existing pgSQL built-in component
// https://github.com/dapr/components-contrib/blob/d3662118105a1d8926f0d7b598c8b19cd9dc1ccf/state/postgresql/postgresdbaccess.go#L135
var value = System.Text.Encoding.UTF8.GetString(x.Value.Span);
await db.UpsertAsync(x.Key, value, x.ETag ?? String.Empty, GetTTLfromOperationMetadata(request.Metadata), tran);
var value = System.Text.Encoding.UTF8.GetString(set.Value.Span);
await db.UpsertAsync(set.Key, value, set.ETag ?? String.Empty, GetTTLfromOperationMetadata(request.Metadata), tran);
}
);
}
Expand All @@ -184,6 +177,13 @@ public async Task PingAsync(CancellationToken cancellationToken = default)
await _stateStoreInitHelper.PerformDatabaseProbeAsync();
}
}

private int GetTTLfromOperationMetadata(IReadOnlyDictionary<string,string> metadata)
{
if (metadata.TryGetValue("ttlInSeconds", out string ttl))
return Convert.ToInt32(ttl);
return 0;
}
}

public static class LoggerExtensions
Expand Down
7 changes: 0 additions & 7 deletions src/StateStoreInitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ Why is this a func?
};
}

public string GetDatabaseConnectionString()
{
if (_connectionString == null)
return "";
else return _connectionString;
}

public async Task PerformDatabaseProbeAsync()
{
var connection = new NpgsqlConnection(_connectionString);
Expand Down

0 comments on commit 204ba92

Please sign in to comment.