Skip to content
Permalink
Browse files
Merge pull request #17 from jellyfin/box
Prevent boxing of ResultSetValue
  • Loading branch information
Bond-009 committed May 20, 2021
2 parents ecdf044 + 62603aa commit 93a88a38a16cb768d7db6cab9bc7e074c484e803
@@ -42,7 +42,7 @@ public T Value
{
get { return value; }

set
set
{
lock (gate)
{
@@ -261,7 +261,7 @@ public static class AsyncDatabaseConnection
this IAsyncDatabaseConnection This,
ColumnInfo columnInfo,
long rowId,
bool canWrite = false) =>
bool canWrite = false) =>
This.OpenBlobAsync(columnInfo, rowId, canWrite, CancellationToken.None);

/// <summary>
@@ -345,7 +345,7 @@ public static class AsyncDatabaseConnection
/// <param name="sql">The SQL statement to compile and Query.</param>
/// <param name="values">The bind parameter values.</param>
/// <returns>A cold observable of rows in the result set.</returns>
public static IObservable<IReadOnlyList<IResultSetValue>> Query(
public static IObservable<IReadOnlyList<ResultSetValue>> Query(
this IAsyncDatabaseConnection This,
string sql,
params object[] values)
@@ -364,7 +364,7 @@ public static class AsyncDatabaseConnection
/// <param name="This">The asynchronous database connection.</param>
/// <param name="sql">The SQL statement to compile and Query.</param>
/// <returns>A cold observable of rows in the result set.</returns>
public static IObservable<IReadOnlyList<IResultSetValue>> Query(
public static IObservable<IReadOnlyList<ResultSetValue>> Query(
this IAsyncDatabaseConnection This,
string sql)
{
@@ -499,7 +499,7 @@ public async Task DisposeAsync()
// AsyncStatementImpl's and AsyncBlobStream's and dispose them here first.
// Othewise those objects won't have their state correctly set to disposed,
// leading to some user errors.
// Two possible solutions:
// Two possible solutions:
// * Track the open AsyncStatementImpl's and AsyncBlobStream's
// * Add a disposing event, and listen to it from AsyncStatementImpl's and AsyncBlobStream's.
this.conn.Dispose();
@@ -559,7 +559,7 @@ public IObservable<T> Use<T>(Func<IDatabaseConnection, CancellationToken, IEnume
{
this.progressHandlerResult.Value = false;
var ctSubscription = ct.Register(() => this.progressHandlerResult.Value = true);

try
{
ct.ThrowIfCancellationRequested();
@@ -134,16 +134,16 @@ public static class AsyncStatement
/// <param name="This">The async statement.</param>
/// <param name="values">The position indexed values to bind.</param>
/// <returns>A cold IObservable of the rows in the result set.</returns>
public static IObservable<IReadOnlyList<IResultSetValue>> Query(this IAsyncStatement This, params object[] values) =>
This.Use<IReadOnlyList<IResultSetValue>>(stmt => stmt.Query(values));
public static IObservable<IReadOnlyList<ResultSetValue>> Query(this IAsyncStatement This, params object[] values) =>
This.Use<IReadOnlyList<ResultSetValue>>(stmt => stmt.Query(values));

/// <summary>
/// Queries the database asynchronously using the provided IStatement
/// </summary>
/// <param name="This">The async statement.</param>
/// <returns>A cold IObservable of the rows in the result set.</returns>
public static IObservable<IReadOnlyList<IResultSetValue>> Query(this IAsyncStatement This) =>
This.Use<IReadOnlyList<IResultSetValue>>(stmt => stmt.Query());
public static IObservable<IReadOnlyList<ResultSetValue>> Query(this IAsyncStatement This) =>
This.Use<IReadOnlyList<ResultSetValue>>(stmt => stmt.Query());
}

internal class AsyncStatementImpl : IAsyncStatement
@@ -273,7 +273,7 @@ public void ClearBindings()
stmt.ClearBindings();
}

public IReadOnlyList<IResultSetValue> Current
public IReadOnlyList<ResultSetValue> Current
{
get
{
@@ -33,96 +33,96 @@ public static class ResultSet
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<IResultSetValue> SelectScalar(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<ResultSetValue> SelectScalar(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.Select(x => x.First());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="int"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<int> SelectScalarInt(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<int> SelectScalarInt(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToInt());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="long"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<long> SelectScalarInt64(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<long> SelectScalarInt64(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToInt64());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="string"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<string> SelectScalarString(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<string> SelectScalarString(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToString());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="byte"/> array.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<byte[]> SelectScalarBlob(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<byte[]> SelectScalarBlob(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToBlob());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="double"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<double> SelectScalarDouble(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<double> SelectScalarDouble(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToDouble());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="bool"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<bool> SelectScalarBool(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<bool> SelectScalarBool(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToBool());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="float"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<float> SelectScalarFloat(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<float> SelectScalarFloat(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToFloat());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="TimeSpan"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<TimeSpan> SelectScalarTimeSpan(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<TimeSpan> SelectScalarTimeSpan(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToTimeSpan());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="DateTime"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<DateTime> SelectScalarDateTime(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<DateTime> SelectScalarDateTime(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToDateTime());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="DateTimeOffset"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<DateTimeOffset> SelectScalarDateTimeOffset(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<DateTimeOffset> SelectScalarDateTimeOffset(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToDateTimeOffset());


/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="uint"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<uint> SelectScalarUInt32(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<uint> SelectScalarUInt32(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToUInt32());


@@ -131,31 +131,31 @@ public static class ResultSet
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<decimal> SelectScalarDecimal(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<decimal> SelectScalarDecimal(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToDecimal());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="byte"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<byte> SelectScalarByte(this IObservable<IReadOnlyList<IResultSetValue>> This)
public static IObservable<byte> SelectScalarByte(this IObservable<IReadOnlyList<ResultSetValue>> This)
=> This.SelectScalar().Select(x => x.ToByte());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="UInt16"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<UInt16> SelectScalarUInt16(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<UInt16> SelectScalarUInt16(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToUInt16());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="short"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<short> SelectScalarShort(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<short> SelectScalarShort(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToShort());


@@ -164,23 +164,23 @@ public static IObservable<byte> SelectScalarByte(this IObservable<IReadOnlyList<
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<sbyte> SelectScalarSByte(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<sbyte> SelectScalarSByte(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToSByte());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="Guid"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<Guid> SelectScalarGuid(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<Guid> SelectScalarGuid(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToGuid());

/// <summary>
/// Selects the value in the first column of the result set row as a <see cref="Uri"/>.
/// </summary>
/// <returns>An IObservable of the scalar values.</returns>
/// <param name="This">An observable of result set rows.</param>
public static IObservable<Uri> SelectScalarUri(this IObservable<IReadOnlyList<IResultSetValue>> This) =>
public static IObservable<Uri> SelectScalarUri(this IObservable<IReadOnlyList<ResultSetValue>> This) =>
This.SelectScalar().Select(x => x.ToUri());
}
}
Loading

0 comments on commit 93a88a3

Please sign in to comment.