Skip to content

Commit

Permalink
refactor(deno-kv): Use client2 for DB queries instead of transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
csulit committed Oct 30, 2024
1 parent 822cbfe commit c63210a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions config/deno-kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function listenQueue(kv: Deno.Kv) {

await transaction.begin();

const rawPropertiesCount = await transaction.queryObject<
const rawPropertiesCount = await client2.queryObject<
{ count: number }
>({
text: `
Expand All @@ -145,7 +145,7 @@ export async function listenQueue(kv: Deno.Kv) {
`Processing ${rawPropertiesCount.rows[0].count} raw properties`,
);

const rawProperties = await transaction.queryObject<RawLamudiData>(
const rawProperties = await client2.queryObject<RawLamudiData>(
`
SELECT
id,
Expand Down Expand Up @@ -365,7 +365,7 @@ export async function listenQueue(kv: Deno.Kv) {
if (listingByUrl.rowCount && listingByUrl.rowCount > 0) {
console.info("Listing query by url already exists");

const updateListingResult = await transaction.queryObject({
const updateListingResult = await client2.queryObject({
args: [
rawProperty.price,
rawProperty.price_formatted,
Expand All @@ -384,7 +384,7 @@ export async function listenQueue(kv: Deno.Kv) {
);
}

const updatePropertyResult = await transaction.queryObject({
const updatePropertyResult = await client2.queryObject({
args: [
JSON.stringify(images),
rawProperty.agent_name,
Expand All @@ -409,7 +409,7 @@ export async function listenQueue(kv: Deno.Kv) {
);
}

const updateResult = await transaction.queryObject({
const updateResult = await client2.queryObject({
args: [rawProperty.id],
text: `
UPDATE lamudi_raw_data
Expand Down Expand Up @@ -439,9 +439,7 @@ export async function listenQueue(kv: Deno.Kv) {
});

if (listingByTitle.rowCount && listingByTitle.rowCount > 0) {
await transaction.commit()
console.info("Listing query by title already exists")
console.info("Transaction successfully committed");
return;
}

Expand All @@ -468,7 +466,7 @@ export async function listenQueue(kv: Deno.Kv) {
throw error;
}

property = await client2.queryObject<Property>({
property = await transaction.queryObject<Property>({
args: [
lastCreatedPropertyId,
rawProperty.floor_size,
Expand Down

0 comments on commit c63210a

Please sign in to comment.