public static IObservable <List <T> > mapToList <T>(this SQLiteCursor cursor, Func <SQLiteCursor, T> mapper) { return(Observable.Create((IObserver <List <T> > x) => { List <T> items = new List <T>(); try { while (cursor.MoveNext()) { items.Add(mapper(cursor)); } x.OnNext(items); } catch (Exception e) { x.OnError(e); } finally { cursor.Dispose(); x.OnCompleted(); } return Disposable.Create(() => Trace.WriteLine($"Query Completed...Record Count {items.Count}")); })); }
public static IObservable <T> asRow <T>(this SQLiteCursor cursor, Func <SQLiteCursor, T> mapper) { return(Observable.Create <T>((IObserver <T> x) => { int affectedRecord = 0; if (cursor != null) { try { while (cursor.MoveNext()) { x.OnNext(mapper(cursor)); affectedRecord++; } } catch (Exception e) { x.OnError(e); } finally { cursor.Dispose(); x.OnCompleted(); } } return Disposable.Create(() => Trace.WriteLine($"Query Completed...Record Count {affectedRecord}")); })); }
public static IObservable <T> mapToOne <T>(this SQLiteCursor cursor, Func <SQLiteCursor, T> mapper) { return(Observable.Create((IObserver <T> x) => { if (cursor != null) { if (cursor.MoveNext()) { x.OnNext(mapper(cursor)); if (cursor.MoveNext()) { x.OnError(new InvalidOperationException("Cursor returned more than 1 row")); } cursor.Dispose(); x.OnCompleted(); } } return Disposable.Create(() => Trace.WriteLine("Query Completed")); })); }