Error: Your SQL query failed due to incorrect syntax. Please refer to the manual that matches your MySQL server version for guidance on the correct syntax

While working on a TypeOrm entity, I encountered an issue and now I'm struggling to figure out what went wrong.

The error message I received is:

[Nest] 31328 - 21/12/2021, 15:15:05 [TypeOrmModule] Unable to connect to the database. Retrying (1)... +269ms

QueryFailedError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'array NOT NULL, sessionId varchar(36) NULL, PRIMARY KEY (id)) ENGINE=InnoDB' at line 1

at QueryFailedError.TypeORMError [as constructor]
at new QueryFailedError
at Query.onResult
at Query.execute
at PoolConnection.handlePacket
at PacketParser.onPacket
at PacketParser.executeStart
at Socket.
at Socket.emit
at addChunk

I need help in understanding what operations TypeOrm is attempting here. Any suggestions?

EDIT: Upon closer inspection of the error message, it seems like the sessionId field might be causing the issue for some reason.

Let's take a look at the entities involved:

@Entity()
export class Session extends BaseEntity {
  @ManyToOne(() => Workout, workout => workout.sessions)
  workout: Workout

  @OneToMany(() => Performance, performance => performance.session, {
    eager: true,
  })
  performances: Performance[]

  constructor(partial: Partial<Session> = {}) {
    super()
    Object.assign(this, partial)
  }
}
@Entity()
export class Performance extends BaseEntity {
  @ManyToOne(() => Session, session => session.performances)
  session: Session

  @Column('int', { array: true })
  sets: number[]

  constructor(partial: Partial<Performance> = {}) {
    super()
    Object.assign(this, partial)
  }
}
@Entity()
export class Workout extends BaseEntity {
  @Column()
  title: string

  @ManyToOne(() => Program, program => program.workouts)
  program?: Program

  @OneToMany(() => Exercise, exercise => exercise.workout, { eager: true })
  exercises?: Exercise[]

  @OneToMany(() => Session, session => session.workout)
  sessions?: Session[]

  @Column({
    type: 'set',
    enum: WeekDays,
    default: [],
  })
  scheduledDays?: WeekDays[]

  constructor(partial: Partial<Workout> = {}) {
    super()
    Object.assign(this, partial)
  }
}

Answer №1

My approach to addressing this issue involved making adjustments to the Performance entity as outlined below:

@Entity()
export class Performance extends BaseEntity {
  @ManyToOne(() => Session, (session) => session.performances)
  session: Session

  @Column('simple-array')
  sets: number[]

  constructor(partial: Partial<Performance> = {}) {
    super()
    Object.assign(this, partial)
  }
}

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

What is the best way to apply ngClass to style a JSON object based on its length?

Currently, I am working with a mat-table that displays data from a JSON object. My goal is to filter out all records with an ID of length 5 and then style them using ngClass in my HTML template. How can I achieve this? Below is the code I am working with: ...

Verify whether the message received contains a specific text within the property

Currently, I am facing a challenge with displaying a specific div in my component template only if any incoming messages contain the TYPE_OTHER property. With numerous variations of the TYPE_OTHER identifier, I am pondering on creating a condition that can ...

Combining strings in MySQL using CONCAT and GROUP_CONCAT

Seeking assistance with crafting an SQL query that displays client details alongside their orders. This is the desired output: { "success": true, "client": { "name": "General Kenobit", " ...

Is it possible to utilize Typescript generics for key filtering in an object?

I have a filter function that has functioning logic, but I am struggling to define its types: export function filter<T>(object: T, ...keys: Array<keyof T>): ??? { let index = -1; const length = keys.length; const result = { ...object }; ...

The functionality of `import { Dialogs } from "@nativescript/core"; seems to be malfunctioning

For my project, I am in need of using Dialogs. Unfortunately, the import from @nativescript/core as mentioned in their documentation is not working. I keep encountering this error: Module '"@nativescript/core"' has no exported member &a ...

Change the data returned by Ajax

After making an ajax request, my table gets populated with data from my array. The return is as expected, but now I want to modify this data before displaying it to the user. Whether this modification happens before or after the data is placed in the table ...

Angular 2 interprets my JSON object as a function

My webapp retrieves data via Json and places it in objects for display. I have successfully implemented this process twice using services and classes. However, when I recently copied and pasted the old code with some modifications to redirect to the correc ...

What are some alternatives for integrating React production build files apart from utilizing Express?

Is there a way to integrate React into my library using the HTTP module? I'm trying to figure out how to recursively send static files. Specifically, I want to include the build folder from the React production build, but I'm not sure how to go a ...

Avoiding a colon (:) in a PDO query with placeholders

$sql3 = 'SELECT sched_id, date_format(sched_date_time,\'%H:%i\') AS \'Time\' FROM schedule WHERE (date_format(sched_date_time,\'%Y-%m-%d\') = \':date\') ...

What is the best way to find fields containing values separated by commas in MYSQL?

tags (id_tag,name) news (id,title,data,tags) The database field news>tags holds values in a varchar(255) format. For example, it may contain data like "1,7,34" to indicate that a specific row in the news table is associated with tags 1, 7, and 34 from ...

Obtaining the latest inserted IDs across multiple rows

When adding data to a table with an auto-incremented primary key, I require the key to be used in another statement. Many questions on SO suggest that this can be done in PHP using mysql_insert_id(). However, I have been grouping my inserts together to ad ...

Error message: `Socket.io-client - Invalid TypeError: Expected a function for socket_io_client_1.default`

I have successfully installed socket.io-client in my Angular 5.2 application, but after trying to connect (which has worked flawlessly in the past), I am encountering a strange error. TypeError: socket_io_client_1.default is not a function at new Auth ...

AmCharts stacked bar chart - dynamically adjust value visibility (adjust transparency) based on user interaction

I recently utilized amcharts to construct a bar chart. The creation of my stacked bar chart was inspired by this specific example. Currently, I am attempting to modify the alpha (or color) of a box when hovering over another element on my webpage, such as ...

JavaScript and Angular are used to define class level variables

Hello, I'm currently diving into Angular and have encountered an issue with a class level variable called moratoriumID in my component. I have a method that makes a POST request and assigns the returned number to moratoriumID. Everything seems to work ...

What is the process for creating a method within a class?

Here is the current structure of my class: export class Patient { constructor(public id: number, public name: string, public location: string, public bedId: number, public severity: string, public trajectory: number, public vitalSigns: ...

When verifying for null in an instance method, an error of "Potential null object" is encountered

If I create an instance function that checks for a non-null property in TypeScript, I encounter an error stating 'Object possibly null' when using the function in a conditional statement. However, if I directly check for null, the error does not ...

The userData property cannot be set on an instance of the threejs MeshBasicMaterial

Encountering a TypeScript error while trying to assign the userData property of a MeshBasicMaterial instance when creating it. Here is an example: import * as THREE from 'three'; ... const customUserData = { ... }; const myMaterial = new THREE ...

Encoding identification data from JSON using ColdFusion

Hello everyone, I've been puzzling over how to intercept and encrypt database record ID from a JSON request in ColdFusion. Below is the code I have so far, along with my unsuccessful attempt. Any assistance would be greatly appreciated. <cfquery ...

Tips for organizing a multi-layered object based on an internal value

I am currently facing a challenge in sorting a complex object. Here is the structure of the object: [{ "searchResultProperties": [{ "key": "message_time", "value": 1542088800000 }, { "key": "size_byte AVG", "value": ...

Exporting requires a declaration or statement to be provided

My approach to export all reducers from my index.js file looks like this: export checking from 'reducers/Checking'; export saving from 'reducers/Saving'; export overdraft from 'reducers/Overdraft'; .......... However, upon tr ...