Beispiel #1
0
        /// <summary>
        /// Schedules the <see cref="Func&lt;T,TResult&gt;"/> <paramref name="f"/> on the statement's operations queue.
        /// </summary>
        /// <typeparam name="T">The result type.</typeparam>
        /// <param name="This">The async statement.</param>
        /// <param name="f">A function from <see cref="IAsyncStatement"/> to <typeparamref name="T"/>.</param>
        /// <param name="cancellationToken">Cancellation token that can be used to cancel the task.</param>
        /// <returns>A task that completes with the result of <paramref name="f"/>.</returns>
        public static Task <T> Use <T>(
            this IAsyncStatement This,
            Func <IStatement, CancellationToken, T> f,
            CancellationToken cancellationToken)
        {
            Contract.Requires(This != null);
            Contract.Requires(f != null);

            return(This.Use((conn, ct) => new[] { f(conn, ct) }).ToTask(cancellationToken));
        }
Beispiel #2
0
        /// <summary>
        /// Schedules the <see cref="Action"/> <paramref name="f"/> on the statement's operations queue.
        /// </summary>
        /// <param name="This">The async statement.</param>
        /// <param name="f">The action.</param>
        /// <param name="cancellationToken">Cancellation token that can be used to cancel the task.</param>
        /// <returns>A task that completes when <paramref name="f"/> returns.</returns>
        public static Task Use(
            this IAsyncStatement This,
            Action <IStatement, CancellationToken> f,
            CancellationToken cancellationToken)
        {
            Contract.Requires(f != null);

            return(This.Use((stmt, ct) =>
            {
                f(stmt, ct);
                return Enumerable.Empty <Unit>();
            }, cancellationToken));
        }
Beispiel #3
0
 /// <summary>
 /// Schedules the <see cref="Func&lt;T,TResult&gt;"/> <paramref name="f"/> on the statement's operations queue.
 /// </summary>
 /// <typeparam name="T">The result type.</typeparam>
 /// <param name="This">The async statement.</param>
 /// <param name="f">A function from <see cref="IAsyncStatement"/> to <typeparamref name="T"/>.</param>
 /// <returns>A task that completes with the result of <paramref name="f"/>.</returns>
 public static Task <T> Use <T>(this IAsyncStatement This, Func <IStatement, T> f) =>
 This.Use((stmt, ct) => f(stmt), CancellationToken.None);
Beispiel #4
0
 /// <summary>
 /// Schedules the <see cref="Action"/> <paramref name="f"/> on the statement's operations queue.
 /// </summary>
 /// <param name="This">The async statement.</param>
 /// <param name="f">The action.</param>
 /// <returns>A task that completes when <paramref name="f"/> returns.</returns>
 public static Task Use(this IAsyncStatement This, Action <IStatement> f) =>
 This.Use((stmt, ct) => f(stmt), CancellationToken.None);
Beispiel #5
0
 /// <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());
Beispiel #6
0
 /// <summary>
 /// Queries the database asynchronously using the provided IStatement and provided bind variables.
 /// </summary>
 /// <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));
Beispiel #7
0
 /// <summary>
 /// Executes the <see cref="IStatement"/> with provided bind parameter values.
 /// </summary>
 /// <param name="This">The async statement.</param>
 /// <param name="values">The position indexed values to bind.</param>
 /// <returns>A <see cref="Task"/> that completes when the statement is executed.</returns>
 public static Task ExecuteAsync(this IAsyncStatement This, params object[] values) =>
 This.ExecuteAsync(CancellationToken.None, values);
Beispiel #8
0
 /// <summary>
 /// Executes the <see cref="IStatement"/> with provided bind parameter values.
 /// </summary>
 /// <param name="This">The async statement.</param>
 /// <param name="cancellationToken">Cancellation token that can be used to cancel the task.</param>
 /// <param name="values">The position indexed values to bind.</param>
 /// <returns>A <see cref="Task"/> that completes when the statement is executed.</returns>
 public static Task ExecuteAsync(
     this IAsyncStatement This,
     CancellationToken cancellationToken,
     params object[] values) =>
 This.Use((stmt, ct) => { stmt.Execute(values); }, cancellationToken);
Beispiel #9
0
 /// <summary>
 /// Returns a cold IObservable which schedules the function f on the statement's database operation queue each
 /// time it is is subscribed to. The published values are generated by enumerating the IEnumerable returned by f.
 /// </summary>
 /// <typeparam name="T">The result type.</typeparam>
 /// <param name="This">The async statement.</param>
 /// <param name="f">
 /// A function that may synchronously use the provided IStatement and returns
 /// an IEnumerable of produced values that are published to the subscribed IObserver.
 /// The returned IEnumerable may block. This allows the IEnumerable to provide the results of
 /// enumerating the prepared statement for instance.
 /// </param>
 /// <returns>A cold observable of the values produced by the function f.</returns>
 public static IObservable <T> Use <T>(this IAsyncStatement This, Func <IStatement, IEnumerable <T> > f) =>
 This.Use((stmt, ct) => f(stmt));