If the app has its own database, use it for writes
979049
def db_for_write(self, model, **hints):
        
        if model._meta.app_label in self._apps:
            return getattr(model, '_db_alias', model._meta.app_label)
        return None
1199346
def _sync_writes(self):
        '''
        
        '''
        for key in self._wqueue:
            val = self._cache[key]
            self._database[key] = val
        del self._wqueue
        self._wqueue = set()
        self._database.sync()
1044031
public SQLiteDatabase openWritableDatabase() {
		lockDb.lock();
		try {
			if (sqliteHelper == null)
				createHelper(options);

			status.set(TypeStatus.READ_AND_WRITE_OPENED);

			if (openCounter.incrementAndGet() == 1) {
				// open new write database
				if (database == null) {
					sqliteHelper.setWriteAheadLoggingEnabled(true);
					database = sqliteHelper.getWritableDatabase();
				}
				if (logEnabled)
					Logger.info("database OPEN %s (connections: %s)", status.get(), (openCounter.intValue() - 1));
			} else {
				if (logEnabled)
					Logger.info("database REUSE %s (connections: %s)", status.get(), (openCounter.intValue() - 1));
			}
		} finally {
			lockDb.unlock();
			lockReadWriteAccess.lock();
		}

		return database;
	}
1269659
function Batch(db, options) {
  this.options = options || {};
  this.ops = [];
  this.db = db;
  this.written = false;
}
688319
def write(self):
        
        # write data
        self.project_manager.writeInput(session=self.db_session,
                                        directory=self.project_directory,
                                        name=self.project_manager.name)
697334
def WriteBlobs(self, blob_id_data_map):
    """"""

    urns = {self._BlobUrn(blob_id): blob_id for blob_id in blob_id_data_map}

    mutation_pool = data_store.DB.GetMutationPool()

    existing = aff4.FACTORY.MultiOpen(
        urns, aff4_type=aff4.AFF4MemoryStreamBase, mode="r")

    for blob_urn, blob_id in iteritems(urns):
      if blob_urn in existing:
        logging.debug("Blob %s already stored.", blob_id)
        continue

      with aff4.FACTORY.Create(
          blob_urn,
          aff4.AFF4UnversionedMemoryStream,
          mode="w",
          mutation_pool=mutation_pool) as fd:
        content = blob_id_data_map[blob_id]
        fd.Write(content)

      logging.debug("Got blob %s (length %s)", blob_id.AsHexString(),
                    len(content))

    mutation_pool.Flush()
903659
def write(key, data = nil, parameters = {}, conditions = {})
      @stores.capture_first {|s| s.write(key, data, parameters, conditions)}
    end
861953
private void writeMainPage(int userPage, int oidPage, int schemaPage, int indexPage, 
			int freeSpaceIndexPage, int pageCount, StorageChannelOutput out, long lastUsedOid,
			long txId) {
		rootPageID = (rootPageID + 1) % 2;
		
		out.seekPageForWrite(PAGE_TYPE.ROOT_PAGE, rootPages[rootPageID]);

		//**********
		// When updating this, also update checkRoot()!
		//**********
		
		//tx ID
		out.writeLong(txId);
		//User table
		out.writeInt(userPage);
		//OID table
		out.writeInt(oidPage);
		//schemata
		out.writeInt(schemaPage);
		//indices
		out.writeInt(indexPage);
		//free space index
		out.writeInt(freeSpaceIndexPage);
		//page count
		out.writeInt(pageCount);
		//last used oid
		out.writeLong(lastUsedOid);
		//tx ID. Writing the tx ID twice should ensure that the data between the two has been
		//written correctly.
		out.writeLong(txId);
	}
437322
def write(object_file, dependent_files)
      db.transaction(false) do |store|
        store[object_file] = dependent_files
      end
    end
618703
def write_to_db(key, value)
      db_setting = Configuration.find_or_create_by(name: namespaced_key(key))
      db_setting.update_attribute(:value, value)
    end
1369442
function _initStorage$1(options) {
    var self = this;
    var dbInfo = {
        db: null
    };

    if (options) {
        for (var i in options) {
            dbInfo[i] = typeof options[i] !== 'string' ? options[i].toString() : options[i];
        }
    }

    var dbInfoPromise = new Promise$1(function (resolve, reject) {
        // Open the database; the openDatabase API will automatically
        // create it for us if it doesn't exist.
        try {
            dbInfo.db = openDatabase(dbInfo.name, String(dbInfo.version), dbInfo.description, dbInfo.size);
        } catch (e) {
            return reject(e);
        }

        // Create our key/value table if it doesn't exist.
        dbInfo.db.transaction(function (t) {
            createDbTable(t, dbInfo, function () {
                self._dbInfo = dbInfo;
                resolve();
            }, function (t, error) {
                reject(error);
            });
        }, reject);
    });

    dbInfo.serializer = localforageSerializer;
    return dbInfoPromise;
}
683180
def save(self, obj):
        """"""
        if not obj.id:
            obj.id = uuid()

        index_names = obj.__class__.index_names() or []
        index_dict = obj.indexes() or {}
        index_name_values = [
            (key, index_dict.get(key, ''))
            for key in index_names
        ]

        write_rec(
            obj.__class__.get_table_name(),
            obj.id,
            obj.to_data(),
            index_name_values
        )
710592
public void doOpen() throws DBException
    {
        super.doOpen();
        try   {
            m_pTable.open(this);
        } catch (DBException ex)    {
            throw DatabaseException.toDatabaseException(ex);
        }
    }
152874
def load(self):
        
        #We load the database even when it is not configured to be
        #writable. After all, the user may decide part-way through a session to
        #begin writing again, and then we would want a history up to that point
        #to be valid.
        from os import path
        if path.isfile(self.dbpath):
            import json
            with open(self.dbpath) as f:
                jdb = json.load(f)
                self.entities = jdb["entities"]
                self.uuids = jdb["uuids"]
1371766
def skeleton(files, metadata, sqlite_extensions):
    ""
    if os.path.exists(metadata):
        click.secho(
            "File {} already exists, will not over-write".format(metadata),
            bg="red",
            fg="white",
            bold=True,
            err=True,
        )
        sys.exit(1)
    app = Datasette(files, sqlite_extensions=sqlite_extensions)
    databases = {}
    for database_name, info in app.inspect().items():
        databases[database_name] = {
            "title": None,
            "description": None,
            "description_html": None,
            "license": None,
            "license_url": None,
            "source": None,
            "source_url": None,
            "queries": {},
            "tables": {
                table_name: {
                    "title": None,
                    "description": None,
                    "description_html": None,
                    "license": None,
                    "license_url": None,
                    "source": None,
                    "source_url": None,
                    "units": {},
                }
                for table_name in (info.get("tables") or {})
            },
        }
    open(metadata, "w").write(
        json.dumps(
            {
                "title": None,
                "description": None,
                "description_html": None,
                "license": None,
                "license_url": None,
                "source": None,
                "source_url": None,
                "databases": databases,
            },
            indent=4,
        )
    )
    click.echo("Wrote skeleton to {}".format(metadata))
460473
function SQLite(config) {
  
  /*jshint bitwise: false */
  
  var self = this;
  
  config = config || {};
  config.mode = config.mode || (sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE);
  
  if (!config.filename) {
    
    // Exit if no filename provided
    throw new Error("No filename provided for SQLite Driver");
    
  } else if (config.filename != ":memory:" && !fs.existsSync(config.filename)) {
    
    // Create file if it doesn't exist
    fs.writeFileSync(config.filename, '', 'binary');

  }
  
  this.className = this.constructor.name;
  
  this.config = config;
  
  // Set client
  this.client = new sqlite3.Database(config.filename, config.mode);

  // Assign storage
  if (typeof config.storage == 'string') {
    this.storage = app.getResource('storages/' + config.storage);
  } else if (config.storage instanceof protos.lib.storage) {
    this.storage = config.storage;
  }
  
  // Set db
  this.db = config.filename;
      
  // Only set important properties enumerable
  protos.util.onlySetEnumerable(this, ['className', 'db']);

}
1196336
def write(self, read, unique_id=None, umi=None, unmapped=False):
        ''''''

        if unmapped or read.mate_is_unmapped:
            self.outfile.write(read)
            return

        if not self.chrom == read.reference_name:
            self.write_mates()
            self.chrom = read.reference_name

        key = read.query_name, read.next_reference_name, read.next_reference_start
        self.read1s.add(key)

        self.outfile.write(read)