// needed for instantiation of ipfs
 const initIPFS = async (IPFS, ORBITDB) => {

  // Create IPFS instance
 // const ipfsOptions = { repo: '/orbitdb/examples/browser/new/ipfs/0.33.1', }
  //const ipfs = await Ipfs.create(ipfsOptions)

  // Create OrbitDB instance
  //const orbitdb = await OrbitDB.createInstance(ipfs)

}
initIPFS()

        
        async function createDb(db_name){
  // Create database instance

  const ipfsOptions = { repo: '/orbitdb/examples/browser/new/ipfs/0.33.1', }
  const ipfs = await Ipfs.create(ipfsOptions)
  const orbitdb = await OrbitDB.createInstance(ipfs)
  // Create IPFS instance
  const db = await orbitdb.keyvalue(db_name)
                 const address = db.address
                 console.log(address)
                 console.log(db.address.toString())
                 //await db.put('2022-07-01T10:49:07', '49.41185089/8.67646861')
                 //await db.put('2022-07-01T10:49:12', '49.41166303/8.67652893')
                 let csv = "./new.csv"
                 const value = db.all
               //console.log(value)
               console.log('datenbank erstellt danke')
               //console.log(value)
               await db.close()
               return db
                }

async function loadRoute(db_name){
  const ipfsOptions = { repo: '/orbitdb/los', }
  const ipfs = await Ipfs.create(ipfsOptions)
  const orbitdb = await OrbitDB.createInstance(ipfs) 

  const db = await orbitdb.keyvalue(db_name)
  await db.load()
  console.log("loadroute ausgeführt")
  const value = db.all 
  console.log(value)
  return value;
}
async function connectDB(dbname){
 const ipfsOptions = { repo: '/orbitdb/los', }
  const ipfs = await Ipfs.create(ipfsOptions)
  const orbitdb = await OrbitDB.createInstance(ipfs)
  const db_route2 = await orbitdb.open('/orbitdb/zdpuAoog9p95yvwyGcL3xJsGcdMkxVdEDRwYwba1JrKNEgQod/'+dbname);
    const route2 = db_route2.all
    console.log(route2);
}



