function insert( db, link ) {
	var keywords;
	var keys;
	var desc;
	var out;
	var key;
	var uri;
	var err;
	var i;
	var j;

	keys = objectKeys( db );
	uri = link.uri; // TODO: percent-encode URI

	desc = link.description;
	desc = trim( desc );

	// Add period to end of description if forgotten:
	if ( !REGEXP_END.test( desc ) ) {
		desc += '.';
	}

	// Check for an existing URI entry or identifier...
	for ( i = 0; i < keys.length; i++ ) {
		key = keys[ i ];
		if ( uri === key ) {
			err = new Error( format( 'invalid argument. Database already contains an entry for the provided URI. Value: `%s`.', link.uri ) );
			debug( 'Found a duplicate entry: %s', JSON.stringify( db[ key] ) );
			return err;
		}
		if ( link.id === db[ key ].id ) {
			err = new Error( format( 'invalid argument. Database already contains an entry for the provided id. Value: `%s`.', link.id ) );
			debug( 'Found a duplicate identifier: %s', JSON.stringify( db[ key] ) );
			return err;
		}
	}
	// New entry...
	keys.push( uri );

	// Sort the keys to enforce lexicographic order (valid on most engines, but not guaranteed as insertion order is not specified at specification level):
	keys.sort();

	// Clone the database, adding the new entry...
	out = {};
	for ( i = 0; i < keys.length; i++ ) {
		key = keys[ i ];
		keywords = ( link.keywords ) ? link.keywords : [];
		for ( j = 0; j < keywords.length; j++ ) {
			keywords[ j ] = trim( keywords[ j ] );
		}
		if ( key === uri ) {
			out[ key ] = {
				'id': link.id,
				'description': desc,
				'short_url': '',
				'keywords': keywords
			};
		} else {
			out[ key ] = db[ key ];
		}
	}
	return out;
}
Attempts to insert a link into a database.

@private
@param {Object} db - link database
@param {Object} link - link details
@returns {(Error|Object)} error or updated database