Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<script src="https://cdn.jsdelivr.net/npm/sfdatabase-js@1.3.2/dist/SFDatabase.min.js"></script>
 
var options = {
  websql:true, // Set to true if to use WebSQL instead
  idbVersion:1,
  structure:{
    Settings:{
      // You need to remove $ when using WebSQL
      $name:['text', 'unique'],
      value:'text',
    },
  },
  // Debug WebSQL query if needed
  debug:function(query, data){
    console.log("Query: "+query, data);
  }
};
var MyDB = new SFDatabase('MyDBName', options, whenInitialized);
var myFeature = {
  getSettings(name, callback){
    this.get('Settings', 'value', {name}, callback);
  },
  setSettings(name, value, callback){
    let that = this;
    this.has('Settings', {name}, function(exist){
      if(exist === false)
        that.insert('Settings', {name, value}, callback);
      else
        that.update('Settings', {value}, {name}, callback);
    });
  }
};
function whenInitialized(){
  Object.assign(MyDB, myFeature);
  MyDB.setSettings("It's", "ready!", function(){
    MyDB.getSettings("It's", console.log)
  });
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers