Heisnberg
Heisnberg
DTDrizzle Team
Created by Heisnberg on 3/23/2024 in #help
Issues with the generated sql files
I tried that in phpmyadmin sql playground it’s throwing the same error
10 replies
DTDrizzle Team
Created by Heisnberg on 3/23/2024 in #help
Issues with the generated sql files
I already tried commenting some part of the code and found that the with section in the section.model.ts causing it but the weird thing is I am getting sql error which is generated by drizzle-orm
10 replies
DTDrizzle Team
Created by Heisnberg on 3/23/2024 in #help
Issues with the generated sql files
This the full error log
You have an error in your
SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select coalesce
(json_arrayagg(json_array(`sections_courses`.`ind`, `sections...' at line 1\n at PromisePool.query (/home/bes/WebDev/Backend/
MSSLanguage_learning/node_modules/mysql2/promise.js:356:22)\n at MySql2PreparedQuery.execute (/home/bes/WebDev/Backend/MSSLan
guage_learning/node_modules/src/mysql2/session.ts:88:31)\n at QueryPromise.execute (/home/bes/WebDev/Backend/MSSLanguage_lear
ning/node_modules/src/mysql-core/query-builders/query.ts:149:25)\n at QueryPromise.then (/home/bes/WebDev/Backend/MSSLanguage
_learning/node_modules/src/query-promise.ts:31:15)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)","
code":"ER_PARSE_ERROR","errno":1064,"sql":"select `sections`.`id`, `sections`.`language_level_id`, `sections`.`name`, `sections`
.`description`, `sections`.`created_at`, `sections`.`updated_at`, `sections_courses`.`data` as `courses` from `sections` left jo
in lateral (select coalesce(json_arrayagg(json_array(`sections_courses`.`ind`, `sections_courses`.`section_id`, `sections_course
s`.`name`, `sections_courses`.`description`, `sections_courses`.`created_at`, `sections_courses`.`updated_at`)), json_array()) a
s `data` from `courses` `sections_courses` where `sections_courses`.`section_id` = `sections`.`id`)
You have an error in your
SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select coalesce
(json_arrayagg(json_array(`sections_courses`.`ind`, `sections...' at line 1\n at PromisePool.query (/home/bes/WebDev/Backend/
MSSLanguage_learning/node_modules/mysql2/promise.js:356:22)\n at MySql2PreparedQuery.execute (/home/bes/WebDev/Backend/MSSLan
guage_learning/node_modules/src/mysql2/session.ts:88:31)\n at QueryPromise.execute (/home/bes/WebDev/Backend/MSSLanguage_lear
ning/node_modules/src/mysql-core/query-builders/query.ts:149:25)\n at QueryPromise.then (/home/bes/WebDev/Backend/MSSLanguage
_learning/node_modules/src/query-promise.ts:31:15)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)","
code":"ER_PARSE_ERROR","errno":1064,"sql":"select `sections`.`id`, `sections`.`language_level_id`, `sections`.`name`, `sections`
.`description`, `sections`.`created_at`, `sections`.`updated_at`, `sections_courses`.`data` as `courses` from `sections` left jo
in lateral (select coalesce(json_arrayagg(json_array(`sections_courses`.`ind`, `sections_courses`.`section_id`, `sections_course
s`.`name`, `sections_courses`.`description`, `sections_courses`.`created_at`, `sections_courses`.`updated_at`)), json_array()) a
s `data` from `courses` `sections_courses` where `sections_courses`.`section_id` = `sections`.`id`)
10 replies
DTDrizzle Team
Created by yousuf4you on 3/24/2024 in #help
Why returning not support in MySQL2??
I guess it’s not even supported in MySQL
4 replies
DTDrizzle Team
Created by Heisnberg on 3/23/2024 in #help
Issues with the generated sql files
schema.ts
export const sections = mysqlTable("sections", {
id: int("id").autoincrement().primaryKey(),
language_level_id: int("language_level_id")
.notNull()
.references(() => languageLevels.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
name: text("name").notNull(),
description: text("description").notNull(),
created_at: timestamp("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updated_at: timestamp("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});

export const courses = mysqlTable("courses", {
id: int("ind").autoincrement().primaryKey(),
section_id: int("section_id")
.notNull()
.references(() => sections.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
name: text("name").notNull(),
description: text("description").notNull(),
created_at: timestamp("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updated_at: timestamp("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});

export const sectionsRelations = relations(sections, ({ many, one }) => ({
languageLevels: one(languageLevels),
courses: many(courses),
sectionExam: one(sectionExam)
}));

export const coursesRelations = relations(courses, ({ many, one }) => ({
sections: one(sections, { fields: [courses.section_id], references: [sections.id] }),
courseContent: many(courseContent),
courseExam: many(courseExam),
}));
export const sections = mysqlTable("sections", {
id: int("id").autoincrement().primaryKey(),
language_level_id: int("language_level_id")
.notNull()
.references(() => languageLevels.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
name: text("name").notNull(),
description: text("description").notNull(),
created_at: timestamp("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updated_at: timestamp("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});

export const courses = mysqlTable("courses", {
id: int("ind").autoincrement().primaryKey(),
section_id: int("section_id")
.notNull()
.references(() => sections.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
name: text("name").notNull(),
description: text("description").notNull(),
created_at: timestamp("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updated_at: timestamp("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});

export const sectionsRelations = relations(sections, ({ many, one }) => ({
languageLevels: one(languageLevels),
courses: many(courses),
sectionExam: one(sectionExam)
}));

export const coursesRelations = relations(courses, ({ many, one }) => ({
sections: one(sections, { fields: [courses.section_id], references: [sections.id] }),
courseContent: many(courseContent),
courseExam: many(courseExam),
}));
section.model.ts
export const getSectionByLanguageLevelId = async (languageLevelId: number) => {
return await db.query.sections.findMany({
where: (section, { eq }) => eq(section.language_level_id, languageLevelId),
with: {
courses: true
}
});
}
export const getSectionByLanguageLevelId = async (languageLevelId: number) => {
return await db.query.sections.findMany({
where: (section, { eq }) => eq(section.language_level_id, languageLevelId),
with: {
courses: true
}
});
}
10 replies