Saving records to MySQL using AdonisJS JSONB field

I'm attempting to insert a new record with a JSONB field type included.

Below is the structure I am trying to create, along with the error message I am receiving.

The specific field causing the issue is "veiculo"

The ORM is struggling to access the nested values within the JSON for identification.

It should be inserting the entire object as it is.

Thank you for your attention and assistance.

Post

{
  veiculo: {
    placa: 'PLACA',
    motorista: 'NOME',
    contato: 'CONTATO',
    casa: true,
    horaEntrada: '2022-01-20T05:02:22.000Z'
  },
  fornecedor: 'ALIMENTOS',
  lab: 'sim',
}

Model

import { DateTime } from 'luxon'
import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm'

export default class Produto extends BaseModel {
  @column({ isPrimary: true })
  public id: number

  @column()
  public fornecedor: string

  @column()
  public lab: string

  @column()
  public veiculo: Object

  @column.dateTime({ autoCreate: true })
  public createdAt: DateTime

  @column.dateTime({ autoCreate: true, autoUpdate: true })
  public updatedAt: DateTime

Migration

public async up () {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')
      table.string('fornecedor')
      table.string('lab')
      table.jsonb('veiculo')

      /**
       * Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL
       */
      table.timestamp('created_at', { useTz: true })
      table.timestamp('updated_at', { useTz: true })
    })
  }

Error

Error: ER_BAD_FIELD_ERROR: Unknown column 'placa' in 'field list'

Answer №1

The issue was successfully resolved by using the await function to create multiple items related to dataNfe

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Extract data from dynamically loaded tables using PhantomJS and Selenium Webdriver

I've been informed by everyone that I should be able to retrieve the table content using PhantomJS when working with JavaScript. However, despite my attempts, I have not been successful. My expectation was to obtain the table from the website Page 1 ...

Unusual encoding in the ajax response

I am trying to use the Ajax function from Jquery to send a string to my JavaScript file, but I am encountering an issue where weird question marks or diamond blocks are appearing before the string that I expect to receive. (function( $ ) { $.f ...

Transform a String into an Array and display IDs accurately?

My goal is to capture the id of a checkbox when clicked and add it to an array. This array will then be used to populate the data-id attribute of a div with the class "block". Here is the link to the jsfiddle example: https://jsfiddle.net/chille1987/5g28uo ...

Is there a way to execute one function before another in JavaScript?

Is there a way to execute the checkifPresentInActiveProjLib function before running the checkifPresentInClosedProjLib function? checkifPresentInActiveProjLib(function(flgAc) { if (flgAc === "active_found") // do something $.ajax(...); / ...

Mastering socket emission and disconnection in reactjs

When using the onchange function, I am able to open a socket and emit/fetch data successfully. However, a new socket is opened on any event. I need to find a way to emit data from the same socket ID without opening a new socket each time. Could you pleas ...

Applying an active class in VueJs to a specific li element within a v-for loop when clicked

Struggling to select (set active class) in a v-for loop when one class is already selected. Here's the code and an explanation: These are my available subscriptions, with one already selected based on user data <ul> <li v-for="(s, key, ...

Retrieve the property of a Typescript object using a template argument

I am looking to develop a Typescript Collection class that can locate items by field. Here is an example of what I have in mind: class Collection<T, K keyof T> { private _items: T[]; public isItemInCollection(item: T) { return _item ...

Tips for avoiding the use of import statements in Typescript

log.ts contains the code below import {LOG} from './log' LOG.e("tag","error"); LOG.f("tag","error"); LOG.d("tag","error"); I am looking for IntelliSense support in my TS file without affecting the output javascript. I only want this in my Java ...

When a ListView item is clicked, a label will display text with text wrapping specific to the selected item in the list

Within the listview items, there is a label that should expand when clicked. For example, initially it only shows one line of text. Upon clicking on the label, it should expand to show 10 lines of text. Current Issue: At present, when I click on the firs ...

Attempting to modify/align JSON data structure

I seem to be struggling with a task that should be straightforward. I am attempting to adjust the structure and variables of a JSON object to fit specific parameters. Here is the current JSON structure I am dealing with: { "name":"BHPhotovideo", ...

Updating the parent navigation bar after a successful login in a child component in Angular4

In my Angular4 project, I have set up a login page. Within the parent app.component file, I have included a navigation bar with login and signup buttons. Upon successful login, the login and signup buttons should be hidden, and the username should appear i ...

Having trouble with CSS transitions in a Next.js or Tailwind application?

"use client"; import React, { useState } from "react"; import Image from "next/image"; import Link from "next/link"; const NavigationBar = () => ( <div id="navbar"> <Link href="/">Home</Link> <Link href="/about">About& ...

Using Typescript in the package.json as a dependency

After initiating a React project with typescript using the command below: npx create-react-app frontend --template typescript https://i.sstatic.net/8n4O5.png I noticed that the tyepscript, @testing, and @types libraries were added to dependencies rather ...

What is the process for obtaining a pristine window object?

My bookmarklet utilizes the window.open method, but sometimes websites modify this method which causes unpredictable behavior when running the bookmarklet. I'm looking for a way to obtain an "untouched" window object. I attempted to inject a new ifra ...

Implementing a onClick event to change the color of individual icons in a group using Angular

I have integrated 6 icons into my Angular application. When a user clicks on an icon, I want the color of that specific icon to change from gray to red. Additionally, when another icon is clicked, the previously selected icon should revert back to gray whi ...

Identify the quantity of dynamically added <li> elements within the <ul> using jQuery

I'm facing an issue where I need to dynamically add a list of LI items to a UL using jQuery. However, when I try to alert the number of LI elements in this list, it only shows 0. I suspect that it's because the code is trying to count the origina ...

Preserving input data based on click and change events

Upon form submission, I encounter an issue with displaying only the divs that contain fields with saved values. The form saves user-entered values using PHP, where some of the fields are initially hidden within div elements until an onclick or onchange eve ...

Switch up the background hue with jQuery

Each td in my HTML represents a square. I want the squares to change to yellow if they are white (default) and to white if they are already yellow when right-clicked. This is the code snippet I am using: $('tbody').on('contextmenu', &a ...

Retrieve the PDF document from the AJAX call and save it as a

My goal is to have the browser automatically download a PDF file that is received from an AJAX response. After reading about how to download a PDF file using jQuery AJAX, I attempted to simulate a click/download event in this way: var req = new XMLHt ...

Generating random positions on a mesh using Three.js

Just starting out with three.js and looking for some help, I want to place a simple mesh at a random position relative to the coordinates of another mesh, like this: I want the small yellow box to be positioned randomly above the letter M.emphasized text ...