Skip to content

Instantly share code, notes, and snippets.

Avatar
💭

vasa vasa-develop

💭
View GitHub Profile
View aviondb-browser-example.html
<!--Using AvionDB in Browser-->
<!--IPFS CDN Link-->
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
<!--AvionDB CDN Link-->
<script src="https://unpkg.com/aviondb/dist/aviondb.min.js"></script>
<script type="text/javascript">
const runExample = async () => {
const ipfs = await window.Ipfs.create();
// Creates a db named "DatabaseName"
@vasa-develop
vasa-develop / aviondb-example.js
Created May 3, 2020
Using AvionDB with Node.js
View aviondb-example.js
// Import modules
const AvionDB = require("aviondb");
const IPFS = require("ipfs");
const ipfs = new IPFS();
const runExample = async () => {
await ipfs.ready;
// Creates a db named "DatabaseName"
const aviondb = await AvionDB.init("DatabaseName", ipfs);
@vasa-develop
vasa-develop / go-ipld-p2-5.go
Created Jan 22, 2020
SimpleAsWater Tutorial: Hands On IPLD Tutorial: PART 2
View go-ipld-p2-5.go
// Fetch the details by reading the DAG for key "inputKey"
fmt.Printf("READ: Reading the document details of employee by ID: \"%s\"\n", inputID)
start = time.Now()
document, err := GetDocument(cid, inputID)
elapsed = time.Since(start)
if err != nil {
fmt.Println(err)
}
fmt.Printf("READ: Salary of employee ID %s is %s\n", string(inputID), string(document.Salary))
@vasa-develop
vasa-develop / go-ipld-p2-4.go
Created Jan 22, 2020
SimpleAsWater Tutorial: Hands On IPLD Tutorial: PART 2
View go-ipld-p2-4.go
// GetDocument handles READ operations of a DAG entry by CID, returning the corresponding document
func GetDocument(ref, key string) (out SampleStruct, err error) {
err = sh.DagGet(ref+"/"+key, &out)
return
}
@vasa-develop
vasa-develop / go-ipld-p2-3.go
Created Jan 22, 2020
SimpleAsWater Tutorial: Hands On IPLD Tutorial: PART 2
View go-ipld-p2-3.go
// Map the struct instance to the mapping
DocStoreMap[inputID] = employeeObject
// Converting the map into JSON object
entryJSON, err := json.Marshal(DocStoreMap)
if err != nil {
fmt.Println(err)
}
// Display the marshaled JSON object before sending it to IPFS
@vasa-develop
vasa-develop / go-ipld-p2-2.go
Created Jan 22, 2020
SimpleAsWater Tutorial: Hands On IPLD Tutorial: PART 2
View go-ipld-p2-2.go
scanner := bufio.NewScanner(os.Stdin)
fmt.Println("Enter the ID of the employee: ")
scanner.Scan()
inputID := scanner.Text()
fmt.Println("Enter the name of the employee: ")
scanner.Scan()
inputName := scanner.Text()
@vasa-develop
vasa-develop / go-ipld-p2-2.go
Created Jan 22, 2020
SimpleAsWater Tutorial: Hands On IPLD Tutorial: PART 2
View go-ipld-p2-2.go
// Map the struct instance its own ID
DocStoreMap := make(map[string]SampleStruct)
@vasa-develop
vasa-develop / go-ipld-p2-0.go
Created Jan 22, 2020
SimpleAsWater Tutorial: Hands On IPLD Tutorial: PART 2
View go-ipld-p2-0.go
// SampleStruct defines the benchmark payload
type SampleStruct struct {
ID string `json:"ID"`
Name string `json:"Name"`
Salary string `json:"Salary"`
}
@vasa-develop
vasa-develop / go-snippet-5.go
Created Jan 4, 2020
SimpleAsWater: Hands-on IPLD Tutorial in Golang
View go-snippet-5.go
// Fetch the details by reading the DAG for key "inputKey"
fmt.Printf("READ: Value for key \"%s\" is: ", inputKey)
res, err := GetDag(cid, inputKey)
if err != nil {
fmt.Println(err)
}
fmt.Println(res)
@vasa-develop
vasa-develop / go-snippet-4.go
Created Jan 4, 2020
SimpleAsWater: Hands-on IPLD Tutorial in Golang
View go-snippet-4.go
// Dag PUT operation which will return the CID for futher access or pinning etc.
cid, err := sh.DagPut(entryJSON, "json", "cbor")
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s", err)
os.Exit(1)
}
fmt.Println("------\nOUTPUT\n------")
fmt.Printf("WRITE: Successfully added %sHere's the IPLD Explorer link: https://explore.ipld.io/#/explore/%s \n", string(cid+"\n"), string(cid+"\n"))