All Projects → socialpoint-labs → Sheetfu Apps Script

socialpoint-labs / Sheetfu Apps Script

Licence: mit
A Google apps scripts ORM to manipulate spreadsheets as database tables.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Sheetfu Apps Script

Kev
K.E.V. (Keys, Extras, and Values) is a Python ORM for key-value stores based on Valley. Currently supported backends are Redis, S3, and a S3/Redis hybrid backend. Based on Valley.
Stars: ✭ 95 (-11.21%)
Mutual labels:  orm
Alkali
a simple python database
Stars: ✭ 101 (-5.61%)
Mutual labels:  orm
Go Sdk
A composable toolbox of libraries to build everything from CLIs to enterprise applications.
Stars: ✭ 103 (-3.74%)
Mutual labels:  orm
Elasticsearch
Use SQL statements to query elasticsearch
Stars: ✭ 98 (-8.41%)
Mutual labels:  orm
Phero
这个是一个独立的orm组件可以使用在任何系统中,提供灵活的orm操作,注解形式的数据库和类的映射。This is a database query tool library. swoole mysql pool.
Stars: ✭ 100 (-6.54%)
Mutual labels:  orm
Borm
【🔥今日热门】🏎️ 更好的ORM库 (Better ORM library that is simple, fast and self-mockable for Go)
Stars: ✭ 102 (-4.67%)
Mutual labels:  orm
Core
Reactive ORM for Lovefield
Stars: ✭ 95 (-11.21%)
Mutual labels:  orm
Ymate Platform V2
YMP是一个非常简单、易用的轻量级Java应用开发框架,涵盖AOP、IoC、WebMVC、ORM、Validation、Plugin、Serv、Cache等特性,让开发工作像搭积木一样轻松!
Stars: ✭ 106 (-0.93%)
Mutual labels:  orm
Sarala
Javascript library to communicate with RESTful API built following JSON API specification. inspired by Laravel’s Eloquent
Stars: ✭ 101 (-5.61%)
Mutual labels:  orm
Orango
ArangoDB Object Modeling for Node.js, Foxx and Modern Web Browsers
Stars: ✭ 103 (-3.74%)
Mutual labels:  orm
Weed3
noear::微型ORM框架(支持:java sql,xml sql,annotation sql,template sql;事务;缓存;监控;等...)
Stars: ✭ 100 (-6.54%)
Mutual labels:  orm
Fastsql
Database rapid development framework for Java(数据库快速开发框架).
Stars: ✭ 100 (-6.54%)
Mutual labels:  orm
Django Cacheops
A slick ORM cache with automatic granular event-driven invalidation.
Stars: ✭ 1,379 (+1188.79%)
Mutual labels:  orm
Nymph
Data objects for JavaScript and PHP.
Stars: ✭ 97 (-9.35%)
Mutual labels:  orm
Xorm
xorm是一个简单而强大的Go语言ORM库,通过它可以使数据库操作非常简便。本库是基于原版xorm的定制增强版本,为xorm提供类似ibatis的配置文件及动态SQL支持,支持AcitveRecord操作
Stars: ✭ 1,394 (+1202.8%)
Mutual labels:  orm
Activegraph
An active model wrapper for the Neo4j Graph Database for Ruby.
Stars: ✭ 1,329 (+1142.06%)
Mutual labels:  orm
F3 Cortex
A multi-engine ORM / ODM for the PHP Fat-Free Framework
Stars: ✭ 101 (-5.61%)
Mutual labels:  orm
Sqlobject
SQLObject, an object-relational mapper for Python
Stars: ✭ 106 (-0.93%)
Mutual labels:  orm
Freesql.adminlte
这是一个 .NETCore MVC 中间件,基于 AdminLTE 前端框架动态产生 FreeSql 实体的增删查改界面。
Stars: ✭ 105 (-1.87%)
Mutual labels:  orm
Reactiveandroid
🚀 Simple and powerful ORM for Android
Stars: ✭ 102 (-4.67%)
Mutual labels:  orm

Sheetfu Table Class

A Table object gives us the capability to treat a spreadsheet in a more ORM-like syntax in the Google Apps script environment. Let's see an example in an app script context, using a "people" sheet as below:

first_name last_name age
Philippe Oger 36
Guillem Orpinell 25
John Doe 32
Jane Doe 32
function tableClassQuickstart() {
    // Let's create a table and search for Philippe.
    var sheetName = 'people';
    var headerRow = 1;
    var table = Sheetfu.getTable(sheetName, headerRow);       
    var item = table.select({"first_name": "Philippe"}).first();
    
    // get values, notes, etc..
    var age = item.getFieldValue("age");  // 36
    var ageNote = item.getFieldNote("age");
    var ageBackground = item.getFieldBackground("age");
    
    // More importantly, we can set values, colors, notes.
    item.setFieldNote("age", "His birthday is coming soon")  
        .setFieldValue("age", 37) 
        .setFieldBackground("age", "red")  
    .commit()    
}

We can also add new entries:

function addNewPerson() {
    var table = Sheetfu.getTable('people', 1);

    var newEmployee = {
        "first_name": "Albert", 
        "last_name": "Einstein", 
        "age": 138
    };
    table.add(newEmployee);
    table.commit()
}

More importantly, you can loop through every rows/items in the table the following way and add the execution worflow that you need.

function loopThroughItems() {
    var table = Sheetfu.getTable('people', 1);
    for (var i = 0; i < table.items.length; i ++) {
        var item = table.items[i];
        
        if (item.getFieldValue('age') > 24 ) {
            item.setFieldValue('age', 25)
                .setFieldBackground('age', 'green')
                .setFieldNote('age', 'Happy 25 th birthday')
              .commit()
        }    
    }
}


If the Item object have a method that is not in our API yet, you can always get the Range object for any given line or field and access every methods available to the GAS Range object documented here: https://developers.google.com/apps-script/reference/spreadsheet/range

function getItemRanges() {
    var table = Sheetfu.getTable('people', 1);
    
    for (var i = 0; i < table.items.length; i++) {
        var item = table.items[i];
        var lineRange = item.getLineRange();
        var ageRange = item.getFieldRange('age');
    }
}


Every examples above assume that the target sheet only contains the table data. In many cases, we have more complex sheets that contains multiple mini grid/tables. Sheetfu can easily handle this situation by creating a table from a Range object instead of a sheet name. The submitted Range object must contain the header on its first line.

function getItemRanges() {
    var peopleRange = SpreadsheetApp().getSheetByName('people').getRange(1, 1, 20, 3);
    var animalRange = SpreadsheetApp().getSheetByName('people').getRange(60, 60, 10, 5);
    
    var peopleTable = new Sheetfu.Table(peopleRange);
    var animalTable = new Sheetfu.Table(animalRange);
    
    
    // Alternatively you can create a table by using a named Range.
    var table = Sheetfu.getTableByName('people_named_range');
}


If you have a field that you know is a unique value for every item (like an ID, email, etc...), you can create a table index to have very fast lookup if you want to search by ID.

Let's take the following table as an example. We consider the email column to have unique values.

email first_name last_name age
[email protected] Philippe Oger 36
[email protected] Guillem Orpinell 25
[email protected] John Doe 32
[email protected] Jane Doe 32
function lookingForPhilippe() {
  
    // THE OLD WAY (very slow)
    var table = Sheetfu.getTable('people', 1);
    var philippe = table.select({'email': '[email protected]'}).first();
    
    // THE NEW WAY
    // we tell Sheetfu to create an index with the 'email' field
    var table = Sheetfu.getTable('people', 1, 'email');
    var philippe = table.getItemById('[email protected]');
    
    // Also work when you create a table with the Table Object
    var range = SpreadsheetApp().getSheetByName('people').getRange(1, 1, 20, 4);
    var indexField = 'email';
    var table = new Sheetfu.Table(range, indexField);
    var philippe = table.getItemById('[email protected]');
}

If you have a table of 20,000 lines, and you have to do make multiple lookups within the same process, performance will improve by orders of magnitude.

Some comments/caveats:

  • You must not have duplicate fields in your header (columns with same field name).
  • The range used for creating a Table object must contain the header in the first row.
  • The Table object takes all the sheet data in memory, you can then manipulate, query it as you wish, but this will not change the data on the sheet until you commit the data.
  • You can commit Item or Table objects. No need to commit items if you plan on committing your table. You usually do one or the other.

Installation

You can use this code in 2 ways:

  • GIT clone this repo and create your own app script file using this code. Be aware that you will not need to precede function and object with 'Sheetfu' as shown in examples above.'
  • Access it as an app script library from the app script editor (recommended).
    • Go to Resources > Libraries ...
    • In the 'Add a library' placeholder, add the following key: 1N8BGDNX4N64WP4HRjsnZJNwBx2UrAbc_DPZKYwFnVxqzeJdqEJQuCBSv
    • 'Sheetfu' should be prompted. Select the last version.
    • You can then access the library functions and objects by starting to type Sheetfu and the auto-completion should be triggered..
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].