aith
aith
PPrisma
Created by aith on 6/27/2024 in #help-and-questions
$queryRaw for Insert asking for id which is set to autoincrement
I've created this:
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;
},
},
},
});
Now when I do
await prisma.restaurants.create
await prisma.restaurants.create
it says that id is missing. But this shouldn't be the case because id isn't set manually.
2 replies
PPrisma
Created by aith on 6/11/2024 in #help-and-questions
Setting up SafeQL for Prisma
I need help in setting up SafeQL for Prisma. I can't correctly configure my eslint.config and tsconfig. This is my eslint.config.mjs right now:
import tseslint from 'typescript-eslint';
import safeql from '@ts-safeql/eslint-plugin/config';

/** @type {import('eslint').Linter.Config} */
export default tseslint.config({
plugins: {
'@ts-safeql/eslint-plugin': safeql,
},
rules: {
'@ts-safeql/eslint-plugin': [
'error',
{
connections: [
{
// The migrations path:
migrationsDir: './prisma/migrations',
targets: [
// This makes `prisma.$queryRaw` and `prisma.$executeRaw` commands linted
{ tag: 'prisma.+($queryRaw|$executeRaw)', transform: '{type}[]' },
],
},
],
},
],
},
});
import tseslint from 'typescript-eslint';
import safeql from '@ts-safeql/eslint-plugin/config';

/** @type {import('eslint').Linter.Config} */
export default tseslint.config({
plugins: {
'@ts-safeql/eslint-plugin': safeql,
},
rules: {
'@ts-safeql/eslint-plugin': [
'error',
{
connections: [
{
// The migrations path:
migrationsDir: './prisma/migrations',
targets: [
// This makes `prisma.$queryRaw` and `prisma.$executeRaw` commands linted
{ tag: 'prisma.+($queryRaw|$executeRaw)', transform: '{type}[]' },
],
},
],
},
],
},
});
When I run npx eslint . I get the following:
Oops! Something went wrong! :(

ESLint: 9.4.0

TypeError: Key "rules": Key "@ts-safeql/eslint": Could not find plugin "@ts-safeql".
Oops! Something went wrong! :(

ESLint: 9.4.0

TypeError: Key "rules": Key "@ts-safeql/eslint": Could not find plugin "@ts-safeql".
7 replies