MCPcopy Index your code
hub / github.com/PostHog/posthog / insertRow

Function insertRow

plugin-server/tests/helpers/sql.ts:95–171  ·  view source on GitHub ↗
(db: Pool, table: string, objectProvided: Record<string, any>)

Source from the content-addressed store, hash-verified

93}
94
95export async function insertRow(db: Pool, table: string, objectProvided: Record<string, any>) {
96 // Handling of related fields
97 const { source__plugin_json, source__index_ts, source__frontend_tsx, source__site_ts, ...object } = objectProvided
98
99 const keys = Object.keys(object)
100 .map((key) => `"${key}"`)
101 .join(',')
102 const params = Object.keys(object)
103 .map((_, i) => `\$${i + 1}`)
104 .join(',')
105 const values = Object.values(object).map((value) => {
106 if (Array.isArray(value) && value.length > 0) {
107 return JSON.stringify(value)
108 }
109 return value
110 })
111
112 try {
113 const {
114 rows: [rowSaved],
115 } = await db.query(`INSERT INTO ${table} (${keys}) VALUES (${params}) RETURNING *`, values)
116 const dependentQueries: Promise<void>[] = []
117 if (source__plugin_json) {
118 dependentQueries.push(
119 insertRow(db, 'posthog_pluginsourcefile', {
120 id: new UUIDT().toString(),
121 filename: 'plugin.json',
122 source: source__plugin_json,
123 plugin_id: rowSaved.id,
124 error: null,
125 transpiled: null,
126 })
127 )
128 }
129 if (source__index_ts) {
130 dependentQueries.push(
131 insertRow(db, 'posthog_pluginsourcefile', {
132 id: new UUIDT().toString(),
133 filename: 'index.ts',
134 source: source__index_ts,
135 plugin_id: rowSaved.id,
136 error: null,
137 transpiled: null,
138 })
139 )
140 }
141 if (source__frontend_tsx) {
142 dependentQueries.push(
143 insertRow(db, 'posthog_pluginsourcefile', {
144 id: new UUIDT().toString(),
145 filename: 'frontend.tsx',
146 source: source__frontend_tsx,
147 plugin_id: rowSaved.id,
148 error: null,
149 transpiled: null,
150 })
151 )
152 }

Callers 15

createPluginFunction · 0.90
createPluginConfigFunction · 0.90
createOrganizationFunction · 0.90
createTeamFunction · 0.90
createActionFunction · 0.90
createUserFunction · 0.90
createTestActionFunction · 0.90
db.test.tsFile · 0.90
resetTestDatabaseFunction · 0.85

Calls 4

joinMethod · 0.80
toStringMethod · 0.80
valuesMethod · 0.45
queryMethod · 0.45

Tested by 1

createTestActionFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…