Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example code is being added to the distribution file #4

Open
cyberglot opened this issue Apr 9, 2024 · 0 comments
Open

Example code is being added to the distribution file #4

cyberglot opened this issue Apr 9, 2024 · 0 comments

Comments

@cyberglot
Copy link

If you check the dist file, you can see all those lines:

kv-store-db/dist/index.js

Lines 40 to 108 in 8132099

// db and db0 reference the same instance
console.log('* DB singleton:', db === db0);
// set a new collection with one entry
console.log('==============================================================');
console.log('* Adding a new collection with one entry');
console.log('--------------------------------------------------------------');
yield db.set('users', {
id: '1',
name: 'John',
age: 32
});
console.log('users -->', yield db.get('users')); // users --> { '1': { id: '1', name: 'John', age: 32 } }
console.log('users/1 -->', yield db.get('users/1')); // users/1 --> { id: '1', name: 'John', age: 32 }
console.log('users/1/name -->', yield db.get('users/1/name')); // users/1/name --> John
// set a new entry in an existing collection
console.log('==============================================================');
console.log('* Adding a new entry in an existing collection');
console.log('--------------------------------------------------------------');
yield db.set('users', {
id: '2',
name: 'Jane',
age: 31
});
console.log('users -->', yield db.get('users')); // users --> { '1': { id: '1', name: 'John', age: 32 }, '2': { id: '2', name: 'Jane', age: 31 } }
console.log('users/2 -->', yield db.get('users/2')); // users/2 --> { id: '2', name: 'Jane', age: 31 }
console.log('users/2/name -->', yield db.get('users/2/name')); // users/2/name --> Jane
// update an entry in a collection
console.log('==============================================================');
console.log('* Updating an entry in a collection, (without merge)');
console.log('--------------------------------------------------------------');
yield db.set('users/1', {
age: 35
});
console.log('users -->', yield db.get('users')); // users --> { '1': { age: 35 }, '2': { id: '2', name: 'Jane', age: 31 } }
console.log('users/1 -->', yield db.get('users/1')); // users/1 --> { age: 35 }
console.log('users/1/name -->', yield db.get('users/1/name')); // users/1/name --> undefined
// update an entry in a collection with merge
console.log('==============================================================');
console.log('* Updating an entry in a collection (with merge)');
console.log('--------------------------------------------------------------');
yield db.set('users/1', {
id: '1',
name: 'John',
}, true);
console.log('users -->', yield db.get('users')); // users --> { '1': { age: 35, id: '1', name: 'John' }, '2': { id: '2', name: 'Jane', age: 31 } }
console.log('users/1 -->', yield db.get('users/1')); // users/1 --> { age: 35, id: '1', name: 'John' }
console.log('users/1/name -->', yield db.get('users/1/name')); // users/1/name --> John
// update a field of an entry in a collection
console.log('==============================================================');
console.log('* Updating a field of an entry in a collection');
console.log('--------------------------------------------------------------');
yield db.set('users/2/age', 33);
console.log('users -->', yield db.get('users')); // users --> { '1': { age: 35, id: '1', name: 'John' }, '2': { id: '2', name: 'Jane', age: 33 } }
console.log('users/2/age -->', yield db.get('users/2/age')); // users/2/age --> 33
// add a new field to an entry in a collection
console.log('==============================================================');
console.log('* Adding a new field to an entry in a collection');
console.log('--------------------------------------------------------------');
yield db.set('users/2/peers', ['1']);
console.log('users -->', yield db.get('users')); // users --> { '1': { age: 35, id: '1', name: 'John' }, '2': { id: '2', name: 'Jane', age: 33, peers: [ '1' ] } }
console.log('users/2/peers -->', yield db.get('users/2/peers')); // users/2/peers --> [ '1' ]
// delete a field of an entry in a collection
console.log('==============================================================');
console.log('* Deleting a field of an entry in a collection');
console.log('--------------------------------------------------------------');
yield db.delete('users/2/peers');
console.log('users -->', yield db.get('users')); // users --> { '1': { age: 35, id: '1', name: 'John' }, '2': { id: '2', name: 'Jane', age: 33 } }
console.log('users/2/peers -->', yield db.get('users/2/peers')); // users/2/peers --> undefined
console.log('==============================================================');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant