public void InsertsRow() { var result = new SqlBuilder() .Insert("Product") .Into("Id", "Name") .Values("6", "'High Power Gamer Notebook'") .Execute(_api); Assert.True(result == 1 && _api.Count("Product") == 6); }
void FindingBeansWithSql(BeanApi api) { /// ## Finding Beans with SQL /// LimeBean doesn't introduce any custom query language, nor does it implement a LINQ provider. /// To find beans matching a criteria, use fragments of plain SQL: /// { #if CODE var list = api.Find("book", "WHERE rating > 7"); #endif } /// Instead of embedding values into SQL code, it is recommended to use **parameters**: { #if CODE var list = api.Find("book", "WHERE rating > {0}", 7); #endif } /// Usage of parameters looks similar to `String.Format`, but instead of direct interpolation, /// they are transformed into fair ADO.NET command parameters to protect your queries from SQL-injection attacks. /// { #if CODE var list = api.Find( "book", "WHERE release_date BETWEEN {0} and {1} AND author LIKE {2}", new DateTime(1930, 1, 1), new DateTime(1950, 1, 1), "%remarque%" ); #endif } /// /// You can use any SQL as long as the result maps to a set of beans. /// For other cases, see [Generic Queries](#generic-sql-queries). /// /// To find a single bean: #if CODE var best = api.FindOne("book", "ORDER BY rating DESC LIMIT 1"); #endif /// To find out the number of beans without loading them: #if CODE var count = api.Count("book", "WHERE rating > {0}", 7); #endif /// It is also possible to perform unbuffered (memory-optimized) load for processing in a `foreach` loop. /// /// Data is 'Lazy Loaded' on each iteration using [C-sharp's IEnumerable Yield](http://programmers.stackexchange.com/a/97350) #if CODE foreach (var bean in api.FindIterator("book", "ORDER BY rating")) { // do something with bean } #endif }
public void Assigned_FrozenMode() { _api.Exec("create table foo (pk, prop)"); _api.Key("foo", "pk", false); var bean = _api.Dispense("foo"); bean["pk"] = "pk1"; bean["prop"] = "value1"; var key = _api.Store(bean); Assert.Equal("pk1", key); bean["prop"] = "value2"; Assert.Equal(key, _api.Store(bean)); bean = _api.Load("foo", key); Assert.Equal(key, bean["pk"]); Assert.Equal("value2", bean["prop"]); _api.Trash(bean); Assert.Equal(0, _api.Count("foo")); }
public void AuditTableIsCreated() { _api.AddObserver(new Auditor(_api, string.Empty)); Assert.Equal(1, _api.Count(false, "AUDIT")); Assert.True(_storage.IsKnownKind("AUDIT")); }
void FindingBeansWithSql(BeanApi api) { /// ## Finding Beans with SQL /// LimeBean doesn't introduce any custom query language, nor does it implement a LINQ provider. /// To find beans matching a criteria, use snippets of plain SQL: /// { #if CODE var list = api.Find("book", "WHERE rating > 7"); #endif } /// Instead of embedding values into SQL code, it is recommended to use **parameters**: { #if CODE var list = api.Find("book", "WHERE rating > {0}", 7); #endif } /// Usage of parameters looks similar to `String.Format`, but instead of direct interpolation, /// they are transformed into fair ADO.NET command parameters to protect your queries from injection-attacks. /// { #if CODE var list = api.Find( "book", "WHERE release_date BETWEEN {0} and {1} AND author LIKE {2}", new DateTime(1930, 1, 1), new DateTime(1950, 1, 1), "%remarque%" ); #endif } /// /// You can use any SQL as long as the result maps to a set of beans. /// For other cases, see [Generic Queries](#generic-sql-queries). /// /// To find a single bean: #if CODE var best = api.FindOne("book", "ORDER BY rating DESC LIMIT 1"); #endif /// To find out the number of beans without loading them: #if CODE var count = api.Count("book", "WHERE rating > {0}", 7); #endif /// It is also possible to perform unbuffered (memory-optimized) load for processing in a foreach-loop: #if CODE foreach(var bean in api.FindIterator("book", "ORDER BY rating")) { // do something with bean } #endif }