Shuvi ☁ 🪽
Shuvi ☁ 🪽
DTDrizzle Team
Created by MahmoodKhalil on 8/24/2024 in #help
Cannot push postgres
export const userProfiles = createTable(
"user_profile",
{
id: serial("id").primaryKey(),
userId: varchar("user_id", { length: 36 })
.references(() => users.id, { onDelete: "cascade" })
.unique(),
},
(table) => ({
userIdIdx: uniqueIndex("user_profile_userId_idx").on(table.userId),
}),
);
export const userProfiles = createTable(
"user_profile",
{
id: serial("id").primaryKey(),
userId: varchar("user_id", { length: 36 })
.references(() => users.id, { onDelete: "cascade" })
.unique(),
},
(table) => ({
userIdIdx: uniqueIndex("user_profile_userId_idx").on(table.userId),
}),
);
21 replies
DTDrizzle Team
Created by MahmoodKhalil on 8/24/2024 in #help
Cannot push postgres
same issue here, in my case it's throwing an error about cascading instead
PostgresError: cannot drop sequence "truncated" because other objects depend on it
at ErrorResponse ([email protected]/node_modules/postgres/src/connection.js:788:26)
at handle ([email protected]/node_modules/postgres/src/connection.js:474:6)
at Socket.data ([email protected]/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:545:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
at Readable.push (node:internal/streams/readable:375:5)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '2BP01',
detail: 'default value for column id of table "truncated" depends on sequence "truncated"',
hint: 'Use DROP ... CASCADE to drop the dependent objects too.',
file: 'dependency.c',
line: '1204',
routine: 'reportDependentObjects'
}
PostgresError: cannot drop sequence "truncated" because other objects depend on it
at ErrorResponse ([email protected]/node_modules/postgres/src/connection.js:788:26)
at handle ([email protected]/node_modules/postgres/src/connection.js:474:6)
at Socket.data ([email protected]/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:545:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
at Readable.push (node:internal/streams/readable:375:5)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '2BP01',
detail: 'default value for column id of table "truncated" depends on sequence "truncated"',
hint: 'Use DROP ... CASCADE to drop the dependent objects too.',
file: 'dependency.c',
line: '1204',
routine: 'reportDependentObjects'
}
21 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
Thank you for your time🙂
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
I guess for these kind of watch Ill just use a pinia store then, though I do think it is a bit of a pitfall that computed state is running so often.
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
Do you suggest using any other pattern or just stick with pinia?
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
Yes, but isnt setting state with this pattern not ideal? I dont think it is appropriate for the use case
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
Using watch in pinia with the same pattern seems to produce the appropriate behaviour
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
No description
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
Is there any explanation to why this is the behavior? It seems like computed is prone to rerunning too often. I know having side effects in computed is a bad practice, but this firing behavior would affect cases where computed function is expensive too
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
somehow computed is reacting to changes from count in useCounterStore
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
import { defineStore } from 'pinia';

export const useStore = () => {
const count = useState('count', () => 0);
const sideEffectCount = useState('sideEffect', () => 0);
const sideEffectComputedCount = useState('sideEffectComputed', () => 0);

watch(count, () => sideEffectCount.value++);
const computedState = computed(() => {
const something = count.value;
sideEffectComputedCount.value++;
return something;
});

return { count, sideEffectCount, sideEffectComputedCount, computedState };
};

export const useCounterStore = defineStore('counter', () => {
const count = ref(0);
const doubleCount = computed(() => count.value * 2);
function increment() {
count.value++;
}

return { count, doubleCount, increment };
});
import { defineStore } from 'pinia';

export const useStore = () => {
const count = useState('count', () => 0);
const sideEffectCount = useState('sideEffect', () => 0);
const sideEffectComputedCount = useState('sideEffectComputed', () => 0);

watch(count, () => sideEffectCount.value++);
const computedState = computed(() => {
const something = count.value;
sideEffectComputedCount.value++;
return something;
});

return { count, sideEffectCount, sideEffectComputedCount, computedState };
};

export const useCounterStore = defineStore('counter', () => {
const count = ref(0);
const doubleCount = computed(() => count.value * 2);
function increment() {
count.value++;
}

return { count, doubleCount, increment };
});
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
@manniL / TheAlexLichter sorry for bumping this, but I ran into another behaviour in having side effects in computed, this time interacting with pinia store https://stackblitz.com/edit/nuxt-starter-izzlz4?file=README.md
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
Some button has the hook mounted, so in stotal the watch effect is mounted 4 times
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
<script setup lang="ts">
import SomeButton from './SomeButton.vue';
import { useStore } from './useStore';

const { count, sideEffectCount, sideEffectComputedCount, computedState } =
useStore();
</script>

<template>
<div>
<div>Count = {{ count }}</div>
<div>computedState = {{ computedState }}</div>
<div>sideEffectCount = {{ sideEffectCount }}</div>
<div>sideEffectComputedCount = {{ sideEffectComputedCount }}</div>
<SomeButton />
<SomeButton />
<SomeButton />
</div>
</template>
<script setup lang="ts">
import SomeButton from './SomeButton.vue';
import { useStore } from './useStore';

const { count, sideEffectCount, sideEffectComputedCount, computedState } =
useStore();
</script>

<template>
<div>
<div>Count = {{ count }}</div>
<div>computedState = {{ computedState }}</div>
<div>sideEffectCount = {{ sideEffectCount }}</div>
<div>sideEffectComputedCount = {{ sideEffectComputedCount }}</div>
<SomeButton />
<SomeButton />
<SomeButton />
</div>
</template>
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
No description
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
No description
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
I couldnt get console.log to work so I just have the sideeffect as a state count instead
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
It seems like the code sandbox is broken with vue/nuxt right now, https://github.com/codesandbox/codesandbox-client/issues/8451
31 replies
NNuxt
Created by Shuvi ☁ 🪽 on 6/3/2024 in #❓・help
Computed properties from useState inside a composable is called multiple times
I can create a code sandbox to demonstrate what I meant
31 replies