$queryRaw for Insert asking for id which is set to autoincrement
I've created this:
Now when I do
it says that
let prisma = new PrismaClient().$extends({
model: {
restaurants: {
async create(data: {
name: string;
address: string;
city: string;
state: string;
country: string;
district: string;
latitude: number;
longitude: number;
phoneNumber: string;
openingTime: string;
closingTime: string;
status: boolean;
verificationStatus: boolean;
}) {
const restaurant: RestaurantPrismaType = {
name: data.name,
address: data.address,
city: data.city,
state: data.state,
district: data.district,
country: data.country,
location: {
latitude: data.latitude,
longitude: data.longitude,
},
phoneNumber: data.phoneNumber,
openingTime: data.openingTime,
closingTime: data.closingTime,
status: data.status,
longitude: data.longitude,
latitude: data.latitude,
};
const point = `POINT(${restaurant.location.longitude} ${restaurant.location.latitude})`;
await prisma.$queryRaw`INSERT INTO "restaurants" (name, address, city, state, country, location, latitude, longitude, phone_number, opening_time, closing_time, status, verification_status)
VALUES (${restaurant.name}, ${restaurant.address}, ${restaurant.city}, ${restaurant.state}, ${restaurant.country}, ST_GeomFromText(${point}, 4326),
${restaurant.latitude}, ${restaurant.longitude}, ${restaurant.phoneNumber}, ${restaurant.openingTime}, ${restaurant.closingTime},
${restaurant.status}, ${data.verificationStatus})`;
return restaurant;
},
},
},
});
let prisma = new PrismaClient().$extends({
model: {
restaurants: {
async create(data: {
name: string;
address: string;
city: string;
state: string;
country: string;
district: string;
latitude: number;
longitude: number;
phoneNumber: string;
openingTime: string;
closingTime: string;
status: boolean;
verificationStatus: boolean;
}) {
const restaurant: RestaurantPrismaType = {
name: data.name,
address: data.address,
city: data.city,
state: data.state,
district: data.district,
country: data.country,
location: {
latitude: data.latitude,
longitude: data.longitude,
},
phoneNumber: data.phoneNumber,
openingTime: data.openingTime,
closingTime: data.closingTime,
status: data.status,
longitude: data.longitude,
latitude: data.latitude,
};
const point = `POINT(${restaurant.location.longitude} ${restaurant.location.latitude})`;
await prisma.$queryRaw`INSERT INTO "restaurants" (name, address, city, state, country, location, latitude, longitude, phone_number, opening_time, closing_time, status, verification_status)
VALUES (${restaurant.name}, ${restaurant.address}, ${restaurant.city}, ${restaurant.state}, ${restaurant.country}, ST_GeomFromText(${point}, 4326),
${restaurant.latitude}, ${restaurant.longitude}, ${restaurant.phoneNumber}, ${restaurant.openingTime}, ${restaurant.closingTime},
${restaurant.status}, ${data.verificationStatus})`;
return restaurant;
},
},
},
});
await prisma.restaurants.create
await prisma.restaurants.create
id
is missing. But this shouldn't be the case because id isn't set manually.0 Replies