IocLookupException: E_IOC_LOOKUP_FAILED: Cannot resolve "Adonis/Lucid/Database" namespace from the IoC Container

279 views Asked by At

Getting this error while saving data into postgres using insert query via ADONISJS commands feature. Followed up the official documentation but not able to solve this.

    import Database from '@ioc:Adonis/Lucid/Database';
 public async run() {  
    {
      try {
        console.log('Starting fetching data from Coingecko')
        const response = await axios.get('https://api.coingecko.com/api/v3/coins/list', {
          params: {
            include_platform: true,
          },
        })

        if (true) {
          const coinsData = response.data
          await this.saveToDatabase(coinsData)
          console.info('Data Saved Successfully!')
        } else {
          console.error('Error while saving the data!')
        }
      } catch (error) {
        console.error(`Error: ${error.message}`)
      }
    }
  }
 private async saveToDatabase(coinsData: any[]) {
    for (const coin of coinsData) {
      await Database.table('coinsInfo').returning('id').insert({
        id: coin.id,
        name: coin.id,
        symbol: coin.symbol,
        platforms: coin.platforms,
      })
    }
  }
1

There are 1 answers

1
srliath On

install the dependency:

npm install @adonisjs/lucid

and call

node ace invoke @adonisjs/lucid

sometimes this error is just forget to invoke, this worked for me when i start to learn about adonis if dont work, tell me and i can help you