-
I have a project with table configured like that
Which gives me table as I expected (DDL as example): CREATE TABLE public."IP" (
id serial4 NOT NULL,
description text NOT NULL DEFAULT ''::text,
"updatedAt" timestamp(3) NOT NULL,
address inet NOT NULL,
CONSTRAINT "IP_pkey" PRIMARY KEY (id)
);
CREATE UNIQUE INDEX "IP_address_key" ON public."IP" USING btree (address); In this table I have only one record (for test purposes): Also I have a route, which should just return every records stored in IP table const ips = await prisma.iP.findMany();
return ips; As a result it gives: [
{
"id": 2,
"description": "Localhost",
"updatedAt": "2023-02-13T14:05:04.121Z",
"address": "127.0.0.0"
}
] Everything is nearly correct, but there is no mask in address field. In this case I'm expecting "address": "127.0.0.0/16" as it stored in Data Base. How can i achieve the expected behavior? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hi @RrredHead 👋 This looks like the default behavior of the database. You can see a reference here If you want to include the mask, you might want to consider using the net functions, but then you would need to utilize raw queries within Prisma. |
Beta Was this translation helpful? Give feedback.
-
Hi @ludralph! Here are some quotes from this section of reference
and
But as you can see in my example, the netmask is Actually it looks like function |
Beta Was this translation helpful? Give feedback.
-
OK, I've found one workaround: async function findIPs() {
const result = await prisma.$queryRaw<
IP[]
>`SELECT id, description, "updatedAt", text(address) as address FROM public."IP"`;
return result;
}
// ... later in route handler
const ips = await findIPs();
return ips; This gives me output as I expected: [
{
"id": 2,
"description": "Localhost",
"updatedAt": "2023-02-13T14:05:04.121Z",
"address": "127.0.0.0/16"
}
] But I'm quite sure that function |
Beta Was this translation helpful? Give feedback.
-
I've created an issue from this discussions: #17929 |
Beta Was this translation helpful? Give feedback.
OK, I've found one workaround:
This gives me output as I expected:
But I'm quite sure that function
text
have to be applied when casting postgres INET datatype to JS String by default 🤔