public void Default_OnlyDirtyPropsWritten() { _bean["a"] = "bean change"; _api.Exec("update foo set b='external change'"); _api.Store(_bean); Assert.Equal("external change", _api.Cell <string>("select b from foo")); }
void InternalQueryCache(BeanApi api) { /// ## Internal Query Cache /// Results of all recent read-only SQL queries initiated by /// [finder](#finding-beans-with-sql) and [generic query](#generic-sql-queries) functions are cached internally /// on the *least recently used* (LRU) basis. This saves database round trips during repeated reads. /// /// The number of cached results can be adjusted by setting the `CacheCapacity` property: #if CODE // increase api.CacheCapacity = 500; // turn off completely api.CacheCapacity = 0; #endif /// Cache is fully invalidated (cleared) on: /// /// * any non-readonly query (UPDATE, etc) /// * failed [transaction](#transactions) /// /// In rare special cases you may need to **bypass** the cache. /// For this purpose, all query functions provide overloads with the `useCache` argument: #if CODE var uid = api.Cell <string>(false, "select hex(randomblob(16))"); #endif }
private static Pagination PrepareFetchedPagination(BeanApi api, string query, int pageNo, int perPage) { var count = api.Cell <long>(Regex.Replace(query, "SELECT((.|\\n|\\r)*?)FROM", "SELECT COUNT(*) FROM")); return(new Pagination(count, pageNo, perPage)); }
public static T FetchScalar <T>(this SqlBuilder sqlBuilder, BeanApi api, bool useCache = true, params object[] parameters) { var query = sqlBuilder.ToSql(); return(query.StartsWith("SELECT") ? api.Cell <T>(useCache, query, parameters) : throw NotAnSqlQueryException.Create()); }
void GenericSqlQueries(BeanApi api) { /// ## Generic SQL Queries /// Often it's needed to execute queries which don't map to beans: /// aggregates, grouping, joins, selecting single column, etc. /// /// `BeanApi` provides methods for such tasks: /// { #if CODE // Load multiple rows var rows = api.Rows(@"SELECT author, COUNT(*) FROM book WHERE rating > {0} GROUP BY author", 7); // Load a single row var row = api.Row(@"SELECT author, COUNT(*) FROM book WHERE rating > {0} GROUP BY author ORDER BY COUNT(*) DESC LIMIT 1", 7); // Load a column var col = api.Col <string>("SELECT DISTINCT author FROM book ORDER BY author"); // Load a single value var count = api.Cell <int>("SELECT COUNT(*) FROM book"); #endif } /// For `Rows` and `Col`, there are unbuffered (memory-optimized) counterparts: { #if CODE foreach (var row in api.RowsIterator("SELECT...")) { // do something } foreach (var item in api.ColIterator("SELECT...")) { // do something } #endif } /// To execute a non-query SQL command, use the `Exec` method: #if CODE api.Exec("SET autocommit = 0"); #endif /// **NOTE:** all described functions accept parameters in the same form as [finder methods](#finding-beans-with-sql) do. }
void InternalQueryCache(BeanApi api) { /// ## Internal Query Cache /// Results of all recent read-only SQL queries initiated by /// [finder](#finding-beans-with-sql) and [generic query](#generic-sql-queries) functions are cached internally /// on the *least recently used* (LRU) basis. This saves database round trips during repeated reads. /// /// The number of cached results can be adjusted by setting the `CacheCapacity` property: #if CODE // increase api.CacheCapacity = 500; // turn off completely api.CacheCapacity = 0; #endif /// Cache is fully invalidated (cleared) on: /// /// * any non-readonly query (UPDATE, etc) /// * failed [transaction](#transactions) /// /// In rare special cases you may need to **bypass** the cache. /// For this purpose, all query functions provide overloads with the `useCache` argument: #if CODE var uid = api.Cell<string>(false, "select hex(randomblob(16))"); #endif }
void GenericSqlQueries(BeanApi api) { /// ## Generic SQL Queries /// Often it's needed to execute queries which don't map to beans: /// aggregates, grouping, joins, selecting single column, etc. /// /// `BeanApi` provides methods for such tasks: /// { #if CODE // Load multiple rows var rows = api.Rows(@"SELECT author, COUNT(*) FROM book WHERE rating > {0} GROUP BY author", 7); // Load a single row var row = api.Row(@"SELECT author, COUNT(*) FROM book WHERE rating > {0} GROUP BY author ORDER BY COUNT(*) DESC LIMIT 1", 7); // Load a column var col = api.Col<string>("SELECT DISTINCT author FROM book ORDER BY author"); // Load a single value var count = api.Cell<int>("SELECT COUNT(*) FROM book"); #endif } /// For `Rows` and `Col`, there are unbuffered (memory-optimized) counterparts: { #if CODE foreach(var row in api.RowsIterator("...")) { // do something } foreach(var item in api.ColIterator("...")) { // do something } #endif } /// To execute a non-query SQL command, use the `Exec` method: #if CODE api.Exec("SET autocommit = 0"); #endif /// **NOTE:** all described functions accept parameters in the same form as [finder methods](#finding-beans-with-sql) do. }