This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { SQL } from "drizzle-orm"; | |
import { sql } from "drizzle-orm"; | |
import type { AnyColumn } from "drizzle-orm/column"; | |
import type { TypedQueryBuilder } from "drizzle-orm/query-builders/query-builder"; | |
import type { SQLWrapper } from "drizzle-orm/sql"; | |
function toSql(value: number[] | string[]): string { | |
return JSON.stringify(value); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { AnyColumn, SQL, Table } from "drizzle-orm"; | |
import { sql } from "drizzle-orm"; | |
import type { PgColumn } from "drizzle-orm/pg-core"; | |
import { type SelectedFields } from "drizzle-orm/pg-core"; | |
import { type SelectResultFields } from "drizzle-orm/query-builders/select.types"; | |
import { jsonBuildObject } from "./external-utils"; | |
import type { | |
ExtractColumnData, | |
PathsToStringProperty, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { SQLWrapper } from "drizzle-orm"; | |
import { sql } from "drizzle-orm"; | |
import type { DbClient } from "@/db"; | |
export const explainAnalyze = async <T extends SQLWrapper>( | |
db: DbClient, | |
query: T, | |
) => { | |
const debugResult = await db.execute(sql`EXPLAIN ANALYZE ${query.getSQL()}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { SQL, Table } from "drizzle-orm"; | |
import { getTableColumns, sql } from "drizzle-orm"; | |
// from https://github.com/drizzle-team/drizzle-orm/issues/1728 | |
export function conflictUpdateAllExcept< | |
T extends Table, | |
E extends (keyof T["$inferInsert"])[], | |
>(table: T, except: E) { | |
const columns = getTableColumns(table); | |
const updateColumns = Object.entries(columns).filter( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
bird_pid=$(pgrep bird) | |
cloudd_pid=$(pgrep cloudd) | |
nsurlsessiond=$(pgrep nsurlsessiond) | |
# check all the values are not empty | |
# refactor to not use [[ ]] and use [ ] instead | |
if [[ -z "$bird_pid" || -z "$cloudd_pid" || -z "$nsurlsessiond" ]]; then | |
echo "bird, cloudd or nsurlsessiond is not running" | |
exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
pid=$(ps -fe | grep 'bird' | grep -v grep | awk '{print $2}') | |
if [[ -n $pid ]]; then | |
kill $pid | |
else | |
echo "bird is not running" | |
fi |