/// <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);
        }
 /// <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));
 }