Beetle is a data manager for Javascript. The goal is to be able to work with data as easy as Entity Framework and LINQ.
All dependencies have base types so custom implementations can be made easily.
public class BeetleTestController : BeetleApiController<EFContextHandler<TestEntities>> {
[HttpGet]
public IQueryable<Entity> Entities() {
return ContextHandler.Context.Entities;
}
}
public static class BeetleWebApiConfig {
public static void RegisterBeetlePreStart() {
GlobalConfiguration.Configuration.Routes.MapHttpRoute("BeetleApi", "api/{controller}/{action}");
}
}
var manager = new EntityManager('api/BeetleTest');
var query = manager.createQuery('Entities').where('e => e.Name != null');
manager.executeQuery(query)
.then(function (data) {
self.entities = data;
data[0].UserNameCreate = 'Test Name';
})
var hasCanceled = self.entities.asQueryable().any('e => e.IsCanceled == true').execute();
// q is shortcut for asQueryable, x is shortcut for execute
var hasDeleted = self.entities.q().any('e => e.IsDeleted').x();
// alias is optional
var hasDeleted = self.entities.q().any('IsDeleted').x();
// with beetle.queryExtensions.js we can write queries like these;
// this query will be executed immediately and returns true or false
var hasExpired = self.entities.any('IsExpired == true');
// below query will be executed after it's length property is accessed (like LINQ GetEnumerator)
var news = self.entities.where('IsNew');
var net = manager.createEntity('EntityType', {Id: beetle.helper.createGuid()});
net.Name = 'Test EntityType';
manager.deleteEntity(net);
manager.saveChanges()
.then(function () {
alert('Save succesfull');
})
string, guid, date, dateTimeOffset, time, boolean, int, number (for float, decimal, etc..), byte, enum, binary, geometry, geography (spatial types are supported partially, can be fully supported once we decide how to represent them at client side)
required, stringLength, maximumLength, minimumLength, range, emailAddress, creditCard, url, phone, postalCode, time, regularExpression, compare
ofType, where, orderBy, expand (include), select, skip, top (take), groupBy, distinct, reverse, selectMany, skipWhile, takeWhile, all, any, avg, max, min, sum, count, first, firstOrDefault, single, singleOrDefault, last, lastOrDefault
toupper, tolower, substring, substringof, length, trim, concat, replace, startswith, endswith, indexof, round, ceiling, floor, second, minute, hour, day, month, year, max, min, sum, count, avg, any, all, contains (can be used in expression strings, some are not supported by OData but can be used with beetle query string format)
See License
Thanks to JetBrains for providing me with free licenses to their great tools.