我可以使用ScriptDB替代什么来存储大量数组?(不使用外部数据库) [英] What alternative to ScriptDB I could use to store a big array of arrays? (without using external DB)

查看:31
本文介绍了我可以使用ScriptDB替代什么来存储大量数组?(不使用外部数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是不推荐使用的ScriptDB的用户.我对ScriptDB的使用非常简单:以这种方式存储面板选项中包含的某些信息:

I was a user of the deprecated ScriptDB. The use I made of ScriptDB was fairly simple: to store a certain amount of information contained on a panel options, this way:

var db = ScriptDb.getMyDb();

function showList(folderID) {
  var folder = DocsList.getFolderById(folderID);
  var files = folder.getFiles();
  var arrayList = [];
  for (var file in files) {
    file = files[file];
    var thesesName = file.getName();
    var thesesId = file.getId();
    var thesesDoc = DocumentApp.openById(thesesId);
    for (var child = 0; child < thesesDoc.getNumChildren(); child++){
         var thesesFirstParagraph = thesesDoc.getChild(child);
         var thesesType = thesesFirstParagraph.getText();
         if (thesesType != ''){
             var newArray = [thesesName, thesesType, thesesId];
        arrayList.push(newArray);
        break;
         }
      }
   }
  arrayList.sort();
  var result = db.query({arrayName: 'savedArray'});
  if (result.hasNext()) {
    var savedArray = result.next();
    savedArray.arrayValue = arrayList;
    db.save(savedArray);
    }
  else {
    var record = db.save({arrayName: "savedArray", arrayValue:arrayList});
  }
    var mydoc = SpreadsheetApp.getActiveSpreadsheet();
    var app = UiApp.createApplication().setWidth(550).setHeight(450);
    var panel = app.createVerticalPanel()
                   .setId('panel');
    var label = app.createLabel("Choose the options").setStyleAttribute("fontSize", 18);
    app.add(label);
    panel.add(app.createHidden('checkbox_total', arrayList.length)); 
    for(var i = 0; i < arrayList.length; i++){
      var checkbox = app.createCheckBox().setName('checkbox_isChecked_'+i).setText(arrayList[i][0]);
      panel.add(checkbox);
   }
   var handler = app.createServerHandler('submit').addCallbackElement(panel);
   panel.add(app.createButton('Submit', handler));
   var scroll = app.createScrollPanel().setPixelSize(500, 400);
   scroll.add(panel);
   app.add(scroll);
   mydoc.show(app);
}

function include(arr, obj) {
    for(var i=0; i<arr.length; i++) {
        if (arr[i] == obj) // if we find a match, return true
            return true;    }
    return false; // if we got here, there was no match, so return false
 }

function submit(e){
  var scriptDbObject = db.query({arrayName: "savedArray"});
  var result = scriptDbObject.next();
  var arrayList = result.arrayValue;
  db.remove(result);
  // continues...
 }

我以为我可以简单地用userProperties替换ScriptDB(使用JSON将数组转换为字符串).但是,出现错误警告我,我的信息太大,无法存储在userProperties中.

I thought I could simply replace the ScriptDB by userProperties (using JSON to turn the array into string). However, an error warns me that my piece of information is too large to be stored in userProperties.

我不想使用外部数据库(解析或MongoDB),因为我认为这对于我的(简单)用途不是必需的.

I did not want to use external databases (parse or MongoDB), because I think it isn't necessary for my (simple) purpose.

那么,我可以用什么解决方案替代ScriptDB?

So, what solution I could use as a replacement to ScriptDB?

推荐答案

您可以使用HtmlOutput类存储字符串.

You could store a string using the HtmlOutput Class.

 var output = HtmlService.createHtmlOutput('<b>Hello, world!</b>');
 output.append('<p>Hello again, world.</p>');
 Logger.log(output.getContent());

Google文档-HtmlOutput

有一些方法可以从HtmlOutput对象附加,清除和获取内容.

There are methods to append, clear and get the content out of the HtmlOutput object.

OR

也许创建一个Blob:

Maybe create a Blob:

Google文档-实用工具类-newBlob方法

然后,您可以将数据作为字符串从Blob中获取.

Then you can get the data out of the blob as a string.

getDataAsString

然后,如果需要,可以将字符串转换为正确的JSON格式的对象.

Then if you need to you can convert the string to an object if it's in the right JSON format.

这篇关于我可以使用ScriptDB替代什么来存储大量数组?(不使用外部数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆