getPostTempArray = (postId: number, userId: number) => {
return Effect.tryPromise({
try: () =>
lite
.select()
.from(edits)
.where(and(eq(edits.postId, postId), eq(edits.userId, userId))),
catch: () => new CheckPostExistError(),
}).pipe(
Effect.map((x) => x[0]),
Effect.flatMap((edit) =>
edit
? Effect.succeed(edit)
: Effect.tryPromise({
try: () =>
lite
.insert(edits)
.values({ postId, userId, json: JSON.stringify([]) })
.returning(),
catch: () => new InsertSqliteError(),
}).pipe(Effect.map((x) => x[0])),
),
Effect.runPromise,
);
};
getPostTempArray = (postId: number, userId: number) => {
return Effect.tryPromise({
try: () =>
lite
.select()
.from(edits)
.where(and(eq(edits.postId, postId), eq(edits.userId, userId))),
catch: () => new CheckPostExistError(),
}).pipe(
Effect.map((x) => x[0]),
Effect.flatMap((edit) =>
edit
? Effect.succeed(edit)
: Effect.tryPromise({
try: () =>
lite
.insert(edits)
.values({ postId, userId, json: JSON.stringify([]) })
.returning(),
catch: () => new InsertSqliteError(),
}).pipe(Effect.map((x) => x[0])),
),
Effect.runPromise,
);
};