Types schema
```
import type { ColumnType } from "kysely";
export type Generated = T extends ColumnType
? ColumnType
: ColumnType;
export type Timestamp = ColumnType;
export type Category = {
id: number;
name: string;
};
export type CategoryToPost = {
A: number;
B: number;
};
export type Img = {
id: number;
url: string;
};
export type Post = {
id: number;
content: string;
excerpt: string;
featureImgId: number;
};
export type PostToTag = {
A: number;
B: number;
};
export type Tag = {
id: number;
name: string;
};
export type DB = {
_CategoryToPost: CategoryToPost;
_PostToTag: PostToTag;
Category: Category;
Img: Img;
Post: Post;
Tag: Tag;
};
```
Kysely define file
```ts
fimport { DB } from "./types"; // this is the Database interface we defined earlier
import { createPool, createConnection } from "mysql2"; // do not use 'mysql2/promises'!
import { Kysely, MysqlDialect, ParseJSONResultsPlugin } from "kysely";
const dialect = new MysqlDialect({
pool: createPool({ uri: process.env.DATABASE_URL }),
});
// Database interface is passed to Kysely's constructor, and from now on, Kysely
// knows your database structure.
// Dialect is passed to Kysely's constructor, and from now on, Kysely knows how
// to communicate with your database.
export const db = new Kysely({
dialect,
});
```
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 'returning `id`' at line 1",
sql: "insert into `Img` (`id`, `url`) values (3, 'urdl') returning `id`
I have a schema like this
Types schema
``` import type { ColumnType } from "kysely"; export type Generated: ColumnType;
export type Timestamp = ColumnType;
export type Category = {
id: number;
name: string;
};
export type CategoryToPost = {
A: number;
B: number;
};
export type Img = {
id: number;
url: string;
};
export type Post = {
id: number;
content: string;
excerpt: string;
featureImgId: number;
};
export type PostToTag = {
A: number;
B: number;
};
export type Tag = {
id: number;
name: string;
};
export type DB = {
_CategoryToPost: CategoryToPost;
_PostToTag: PostToTag;
Category: Category;
Img: Img;
Post: Post;
Tag: Tag;
};
```
Kysely define file
```ts fimport { DB } from "./types"; // this is the Database interface we defined earlier import { createPool, createConnection } from "mysql2"; // do not use 'mysql2/promises'! import { Kysely, MysqlDialect, ParseJSONResultsPlugin } from "kysely"; const dialect = new MysqlDialect({ pool: createPool({ uri: process.env.DATABASE_URL }), }); // Database interface is passed to Kysely's constructor, and from now on, Kysely // knows your database structure. // Dialect is passed to Kysely's constructor, and from now on, Kysely knows how // to communicate with your database. export const db = new KyselyI am trying to create
Img
like thisbut I get this error
What did I do wrong? I just start using Kysely.