/// <summary> /// To avoid spiky INSERT performance, an application can run the /// "merge=X,Y" command periodically, possibly in an idle thread or /// idle process. /// The idle thread that is running the merge commands can know when /// it is done by checking the difference in sqlite3_total_changes() /// before and after each "merge=X,Y" command and stopping the loop /// when the difference drops below two. /// </summary> /// <param name="database">The database to use.</param> /// <param name="type"> /// The table on which to perform the merges. /// </param> public static int RunMergeUntilOptimal(this SqliteSession database, Type type) { int changes = 0; int i; while ((i = database.Merge(type)) >= 2) { changes += i; } return(changes); }
public Task <int> ExecuteAsync(string query, params object[] args) { return(Task <int> .Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.Execute(query, args); } })); }
public Task <T> GetAsync <T>(object pk, params object[] primaryKeys) where T : new() { return(Task.Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.Get <T>(pk, primaryKeys); } })); }
public Task <T> ExecuteScalarAsync <T>(string sql, params object[] args) { return(Task <T> .Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.ExecuteScalar <T>(sql, args); } })); }
public Task <int> DeleteAsync <T>(T item) { return(Task.Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.Delete(item); } })); }
public Task <int> UpdateAllAsync <T>(string propertyName, object propertyValue) { return(Task.Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.UpdateAll <T>(propertyName, propertyValue); } })); }
public Task <int> InsertAllAsync <T>(IEnumerable <T> items) { return(Task.Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.InsertAll(items); } })); }
public Task <List <T> > QueryAsync <T>(string sql, params object[] args) where T : new() { return(Task <List <T> > .Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.Query <T>(sql, args); } })); }
public Task <int> InsertAsync <T>(T item, ConflictResolution extra) { return(Task.Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.Insert(item, extra); } })); }
public Task <int> ClearTableAsync <T>() where T : new() { return(Task.Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.ClearTable <T>(); } })); }
public Task <T> GetAsync <T>(Expression <Func <T, bool> > expression) where T : new() { return(Task.Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.Get(expression); } })); }
public Task <int> InsertDefaultsAsync <T>() where T : class { return(Task.Factory.StartNew( () => { SqliteSession conn = this.GetAsyncConnection(); using (conn.Lock()) { return conn.InsertDefaults <T>(); } })); }
public TableQuery(SqliteSession conn) { Session = conn; Table = Session.GetMapping <T>(); }
/// <summary> /// To avoid spiky INSERT performance, an application can run the /// "merge=X,Y" command periodically, possibly in an idle thread or /// idle process. /// The idle thread that is running the merge commands can know when /// it is done by checking the difference in sqlite3_total_changes() /// before and after each "merge=X,Y" command and stopping the loop /// when the difference drops below two. /// </summary> /// <typeparam name="T"> /// The table on which to perform the merges. /// </typeparam> /// <param name="database">The database to use.</param> public static int RunMergeUntilOptimal <T>(this SqliteSession database) { return(database.RunMergeUntilOptimal(typeof(T))); }
/// <summary> /// The "rebuild" command causes SQLite to discard the entire FTS3/4 /// table and then rebuild it again from original text. /// The concept is similar to REINDEX. /// </summary> /// <param name="database">The database to use.</param> /// <param name="type">The table to rebuild.</param> public static int Rebuild(this SqliteSession database, Type type) { var map = database.GetMapping(type); return(database.Execute(String.Format(RebuildCommand, map.TableName))); }
/// <summary> /// The "rebuild" command causes SQLite to discard the entire FTS3/4 /// table and then rebuild it again from original text. /// The concept is similar to REINDEX. /// </summary> /// <typeparam name="T">The table to rebuild.</typeparam> /// <param name="database">The database to use.</param> public static int Rebuild <T>(this SqliteSession database) { return(database.Rebuild(typeof(T))); }
/// <summary> /// The "optimize" command causes FTS3/4 to merge together all of its /// inverted index b-trees into one large and complete b-tree. /// </summary> /// <typeparam name="T">The table to optimize.</typeparam> /// <param name="database">The database to use.</param> public static int Optimize <T>(this SqliteSession database) { return(database.Optimize(typeof(T))); }
/// <summary> /// The "automerge=B" command disables or enables automatic /// incremental inverted index merging for an FTS3/4 table. /// Enabling automatic incremental merge causes SQLite to do a small /// amount of inverted index merging after every INSERT operation to /// prevent spiky INSERT performance. /// </summary> /// <param name="database">The database to use.</param> /// <param name="type"> /// The table on which to enable/disable the merges. /// </param> /// <param name="enable"> /// True to enable automatic incremental inverted index. False to /// disable. /// </param> public static int AutoMerge(this SqliteSession database, Type type, bool enable = false) { var map = database.GetMapping(type); return(database.Execute(String.Format(AutoMergeCommand, map.TableName, enable ? 1 : 0))); }
/// <summary> /// The "automerge=B" command disables or enables automatic /// incremental inverted index merging for an FTS3/4 table. /// Enabling automatic incremental merge causes SQLite to do a small /// amount of inverted index merging after every INSERT operation to /// prevent spiky INSERT performance. /// </summary> /// <typeparam name="T"> /// The table on which to enable/disable the merges. /// </typeparam> /// <param name="database">The database to use.</param> /// <param name="enable"> /// True to enable automatic incremental inverted index. False to /// disable. /// </param> public static int AutoMerge <T>(this SqliteSession database, bool enable = false) { return(database.AutoMerge(typeof(T), enable)); }
/// <summary> /// The "merge=X,Y" command (where X and Y are integers) causes /// SQLite to do a limited amount of work toward merging the various /// inverted index b-trees of an FTS3/4 table together into one large /// b-tree. /// </summary> /// <typeparam name="T"> /// The table on which to perform the merge. /// </typeparam> /// <param name="database">The database to use.</param> /// <param name="x"> /// The X value is the target number of "blocks" to be merged. /// The value of X can be any positive integer but values on the /// order of 100 to 300 are recommended. /// </param> /// <param name="y"> /// The Y is the minimum number of b-tree segments on a level /// required before merging will be applied to that level. /// The value of Y should be between 2 and 16 with a recommended /// value of 8. /// </param> public static int Merge <T>(this SqliteSession database, int x = 100, int y = 8) { return(database.Merge(typeof(T), x, y)); }
/// <summary> /// The "integrity-check" command causes SQLite to read and verify /// the accuracy of all inverted indices in an FTS3/4 table by /// comparing those inverted indices against the original content. /// </summary> /// <typeparam name="T">The table to check.</typeparam> /// <param name="database">The database to use.</param> public static int IntegrityCheck <T>(this SqliteSession database) { return(database.IntegrityCheck(typeof(T))); }
/// <summary> /// The "merge=X,Y" command (where X and Y are integers) causes /// SQLite to do a limited amount of work toward merging the various /// inverted index b-trees of an FTS3/4 table together into one large /// b-tree. /// </summary> /// <param name="database">The database to use.</param> /// <param name="type">The table on which to perform the merge.</param> /// <param name="x"> /// The X value is the target number of "blocks" to be merged. /// The value of X can be any positive integer but values on the /// order of 100 to 300 are recommended. /// </param> /// <param name="y"> /// The Y is the minimum number of b-tree segments on a level /// required before merging will be applied to that level. /// The value of Y should be between 2 and 16 with a recommended /// value of 8. /// </param> public static int Merge(this SqliteSession database, Type type, int x = 100, int y = 8) { var map = database.GetMapping(type); return(database.Execute(String.Format(MergeXyCommand, map.TableName, x, y))); }
/// <summary> /// The "integrity-check" command causes SQLite to read and verify /// the accuracy of all inverted indices in an FTS3/4 table by /// comparing those inverted indices against the original content. /// </summary> /// <param name="database">The database to use.</param> /// <param name="type">The table to check.</param> public static int IntegrityCheck(this SqliteSession database, Type type) { var map = database.GetMapping(type); return(database.Execute(String.Format(IntegrityCheckCommand, map.TableName))); }
private TableQuery(SqliteSession conn, TableMapping table) { Session = conn; Table = table; }