How to use the gun/gun.graph function in gun

To help you get started, we’ve selected a few gun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github d3x0r / gun-db / index.js View on Github external
this.to.next(at);
		if( skip_put && skip_put == at[ACK_] ) {
			if( _debug ) {
				var now = Date.now();
				if( now - _debug_tick > 1000 ) {
					console.log( "N in M", _debug_counter - __debug_counter, now-_debug_tick, (_debug_counter - __debug_counter)/( now-_debug_tick) );
					_debug_tick = now;
					__debug_counter = _debug_counter;
				}
				_debug_counter++;
				console.log( new Date(), "skipping put in-get:", _debug_counter, " get putting:", skip_put, at[ACK_], JSON.stringify( at.put ) ); 
			}
			return;
		}
		_debug && console.log( new Date(), "PUT", at[SEQ_], at[ACK_], JSON.stringify( at.put ) );
		Gun.graph.is(at.put, null, function(value, field, node, soul){ var id;
			// kinda hate to always do a select just to see that the new update is newer than what was there.
			//console.log( "do select soul field", field, `select state from Record where soul='${client.escape(soul)}' and field='${client.escape(field)}'` );
			var record = client.do( `select state from record where soul='${client.escape(soul)}' and field='${client.escape(field)}'` );
			{
				var dataRelation, dataValue, tmp;
				var state = Gun.state.is(node, field);
				// Check to see if what we have on disk is more recent.
				//console.log( "result?", record )
				if(record && record.length && state <= record[0].state){ 
					_debug && console.log( new Date(), "already newer in database.." ); 
					ctx.on('in', {[ACK_]: at[rel_], ok: 1});
					return 
				}
				if(value && (tmp = value[rel_])){ // TODO: Don't hardcode.
					dataRelation = "'" + client.escape(JSON.stringify(tmp)) + "'";
					dataValue = "NULL"
github lmangani / gun-cassandra / index.js View on Github external
this.to.next(at);
            if (skip_put && skip_put == at[ACK_]) {
                if (_debug) {
                    var now = Date.now();
                    if (now - _debug_tick > 1000) {
                        _debug && console.log("N in M", _debug_counter - __debug_counter, now - _debug_tick, (_debug_counter - __debug_counter) / (now - _debug_tick));
                        _debug_tick = now;
                        __debug_counter = _debug_counter;
                    }
                    _debug_counter++;
                    _debug && console.log(new Date(), "skipping put in-get:", _debug_counter, " get putting:", skip_put, at[ACK_], JSON.stringify(at.put));
                }
                return;
            }
            _debug && console.log( new Date(), "PUT", at[SEQ_], at[ACK_], JSON.stringify( at.put ) );
            Gun.graph.is(at.put, null, function(value, field, node, soul) {
                var id;
                // kinda hate to always do a select just to see that the new update is newer than what was there.
                qb(opt.keyspace)
                    .select('state')
		    .from(opt.table)
                    .where('soul', '=', soul)
                    .andWhere('field', '=', field)
                    .exec(function(err, record) {
			_debug && console.log('STATE SELECT!',soul,field,record.rows[0]);
                        var dataRelation, dataValue, tmp;
                        var state = Gun.state.is(node, field);
                        // Check to see if what we have on disk is more recent.
                        if (record && record.rowLength > 0 && state <= record.rows[0].state) {
                            _debug && console.log( new Date(), "already newer in database.." ); 
                            ctx.on('in', {
                                [ACK_]: at[rel_],
github gundb / sqlite / strict.js View on Github external
function get(at, gun, opt, store, table, id, u){ var tmp;
	if('_' === id){
		if(!store[table]){
			return gun.on('in', {'@': at['#']});
		}
		var empty = Gun.state.ify(u, u, u, u, table);
		gun.on('in', {'@': at['#'], put: Gun.graph.node(empty)});
		return;
	}
	if(!id){
		tmp = table.split(':');
		if(tmp[1]){
			return get(at, gun, opt, store, tmp[0], tmp[1]);
		}
		if(!(tmp = store[table])){
			return gun.on('in', {'@': at['#']});
		}
		// TODO: Handle async reads? :/
		tmp.find(null, {limit: 999999999}).then(function(records){
			var graph = {}, all = graph[table] = {};
			records.forEach(function(record){
				var soul = Gun.node.soul(record);
				if(soul && record.id && record.updatedAt){
github gundb / sqlite / index.js View on Github external
return store.Record.get(soul+field).then(function(record){
			record = record || block[soul+field];
			gun.on('in', {'@': at['#'], put: Gun.graph.node(nodeify(record))});
		});
	}
github sjones6 / gun-flint / src / Adapter / index.js View on Github external
const done = (err, data) => gun._.root.on('in', {
      '@': context['#'],
      put: Gun.graph.node(data),
      err,
    });

gun

A realtime, decentralized, offline-first, graph data synchronization engine.

(Zlib OR MIT OR Apache-2.0)
Latest version published 20 days ago

Package Health Score

83 / 100
Full package analysis