Skip to content

Commit dad5dec

Browse files
committed
style: camelCase to snake_case on API props
1 parent a61f0f3 commit dad5dec

File tree

8 files changed

+159
-159
lines changed

8 files changed

+159
-159
lines changed

src/api/columns.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
66
import { Tables } from '../lib/interfaces'
77

88
/**
9-
* @param {boolean} [includeSystemSchemas=false] - Return system schemas as well as user schemas
9+
* @param {boolean} [include_system_schemas=false] - Return system schemas as well as user schemas
1010
*/
1111
interface QueryParams {
12-
includeSystemSchemas?: string
12+
include_system_schemas?: string
1313
}
1414

1515
const router = Router()
@@ -19,9 +19,9 @@ router.get('/', async (req, res) => {
1919
try {
2020
const { data } = await RunQuery(req.headers.pg, columns)
2121
const query: QueryParams = req.query
22-
const includeSystemSchemas = query?.includeSystemSchemas === 'true'
22+
const include_system_schemas = query?.include_system_schemas === 'true'
2323
let payload: Tables.Column[] = data
24-
if (!includeSystemSchemas) payload = removeSystemSchemas(data)
24+
if (!include_system_schemas) payload = removeSystemSchemas(data)
2525
return res.status(200).json(payload)
2626
} catch (error) {
2727
console.log('throwing error')
@@ -31,13 +31,13 @@ router.get('/', async (req, res) => {
3131

3232
router.post('/', async (req, res) => {
3333
try {
34-
const tableId: number = req.body.tableId
34+
const tableId: number = req.body.table_id
3535
const name: string = req.body.name
3636
const getTableQuery = getTableSqlize(tableId)
3737
const { name: table, schema } = (await RunQuery(req.headers.pg, getTableQuery)).data[0]
3838

3939
const addColumnArgs = req.body
40-
delete addColumnArgs.tableId
40+
delete addColumnArgs.table_id
4141
addColumnArgs.table = table
4242
addColumnArgs.schema = schema
4343
const query = addColumnSqlize(addColumnArgs)
@@ -100,27 +100,27 @@ const addColumnSqlize = ({
100100
table,
101101
name,
102102
type,
103-
defaultValue,
104-
isIdentity = false,
105-
isNullable = true,
106-
isPrimaryKey = false,
107-
isUnique = false,
103+
default_value,
104+
is_identity = false,
105+
is_nullable = true,
106+
is_primary_key = false,
107+
is_unique = false,
108108
}: {
109109
schema: string
110110
table: string
111111
name: string
112112
type: string
113-
defaultValue?: any
114-
isIdentity?: boolean
115-
isNullable?: boolean
116-
isPrimaryKey?: boolean
117-
isUnique?: boolean
113+
default_value?: any
114+
is_identity?: boolean
115+
is_nullable?: boolean
116+
is_primary_key?: boolean
117+
is_unique?: boolean
118118
}) => {
119-
const defaultValueSql = defaultValue === undefined ? '' : `DEFAULT ${defaultValue}`
120-
const isIdentitySql = isIdentity ? 'GENERATED BY DEFAULT AS IDENTITY' : ''
121-
const isNullableSql = isNullable ? 'NULL' : 'NOT NULL'
122-
const isPrimaryKeySql = isPrimaryKey ? 'PRIMARY KEY' : ''
123-
const isUniqueSql = isUnique ? 'UNIQUE' : ''
119+
const defaultValueSql = default_value === undefined ? '' : `DEFAULT ${default_value}`
120+
const isIdentitySql = is_identity ? 'GENERATED BY DEFAULT AS IDENTITY' : ''
121+
const isNullableSql = is_nullable ? 'NULL' : 'NOT NULL'
122+
const isPrimaryKeySql = is_primary_key ? 'PRIMARY KEY' : ''
123+
const isUniqueSql = is_unique ? 'UNIQUE' : ''
124124

125125
return `
126126
ALTER TABLE "${schema}"."${table}" ADD COLUMN "${name}" "${type}"
@@ -144,18 +144,18 @@ const alterColumnSqlize = ({
144144
oldName,
145145
name,
146146
type,
147-
dropDefault = false,
148-
defaultValue,
149-
isNullable,
147+
drop_default = false,
148+
default_value,
149+
is_nullable,
150150
}: {
151151
schema: string
152152
table: string
153153
oldName: string
154154
name?: string
155155
type?: string
156-
dropDefault?: boolean
157-
defaultValue?: any
158-
isNullable?: boolean
156+
drop_default?: boolean
157+
default_value?: any
158+
is_nullable?: boolean
159159
}) => {
160160
const nameSql =
161161
name === undefined
@@ -166,14 +166,14 @@ const alterColumnSqlize = ({
166166
? ''
167167
: `ALTER TABLE "${schema}"."${table}" ALTER COLUMN "${oldName}" SET DATA TYPE "${type}";`
168168
let defaultValueSql = ''
169-
if (dropDefault) {
169+
if (drop_default) {
170170
defaultValueSql = `ALTER TABLE "${schema}"."${table}" ALTER COLUMN "${oldName}" DROP DEFAULT;`
171-
} else if (defaultValue !== undefined) {
172-
defaultValueSql = `ALTER TABLE "${schema}"."${table}" ALTER COLUMN "${oldName}" SET DEFAULT ${defaultValue};`
171+
} else if (default_value !== undefined) {
172+
defaultValueSql = `ALTER TABLE "${schema}"."${table}" ALTER COLUMN "${oldName}" SET DEFAULT ${default_value};`
173173
}
174174
let isNullableSql = ''
175-
if (isNullable !== undefined) {
176-
isNullableSql = isNullable
175+
if (is_nullable !== undefined) {
176+
isNullableSql = is_nullable
177177
? `ALTER TABLE "${schema}"."${table}" ALTER COLUMN "${oldName}" DROP NOT NULL;`
178178
: `ALTER TABLE "${schema}"."${table}" ALTER COLUMN "${oldName}" SET NOT NULL;`
179179
}

src/api/functions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
77
import { Functions } from '../lib/interfaces'
88

99
/**
10-
* @param {boolean} [includeSystemSchemas=false] - Return system schemas as well as user schemas
10+
* @param {boolean} [include_system_schemas=false] - Return system schemas as well as user schemas
1111
*/
1212
interface QueryParams {
13-
includeSystemSchemas?: string
13+
include_system_schemas?: string
1414
}
1515

1616
const router = Router()
1717
router.get('/', async (req, res) => {
1818
try {
1919
const { data } = await RunQuery(req.headers.pg, functions)
2020
const query: QueryParams = req.query
21-
const includeSystemSchemas = query?.includeSystemSchemas === 'true'
21+
const include_system_schemas = query?.include_system_schemas === 'true'
2222
let payload: Functions.Function[] = data
23-
if (!includeSystemSchemas) payload = removeSystemSchemas(data)
23+
if (!include_system_schemas) payload = removeSystemSchemas(data)
2424
return res.status(200).json(payload)
2525
} catch (error) {
2626
console.log('throwing error')

src/api/policies.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { Tables } from '../lib/interfaces'
66
import sqlTemplates = require('../lib/sql')
77

88
/**
9-
* @param {string} [includeSystemSchemas=false] - Return system schemas as well as user schemas
9+
* @param {string} [include_system_schemas=false] - Return system schemas as well as user schemas
1010
*/
1111
interface QueryParams {
12-
includeSystemSchemas?: string
12+
include_system_schemas?: string
1313
}
1414

1515
const router = Router()
@@ -19,9 +19,9 @@ router.get('/', async (req, res) => {
1919
const sql = getAllSql(sqlTemplates)
2020
const { data } = await RunQuery(req.headers.pg, sql)
2121
const query: QueryParams = req.query
22-
const includeSystemSchemas = query?.includeSystemSchemas === 'true'
22+
const include_system_schemas = query?.include_system_schemas === 'true'
2323
let payload: Tables.Policy[] = data
24-
if (!includeSystemSchemas) payload = removeSystemSchemas(data)
24+
if (!include_system_schemas) payload = removeSystemSchemas(data)
2525
return res.status(200).json(payload)
2626
} catch (error) {
2727
console.log('throwing error', error)

src/api/roles.ts

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { DEFAULT_ROLES, DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
99
import { Roles } from '../lib/interfaces'
1010

1111
/**
12-
* @param {boolean} [includeSystemSchemas=false] - Return system schemas as well as user schemas
12+
* @param {boolean} [include_system_schemas=false] - Return system schemas as well as user schemas
1313
*/
1414
interface QueryParams {
15-
includeDefaultRoles?: string
16-
includeSystemSchemas?: string
15+
include_default_roles?: string
16+
include_system_schemas?: string
1717
}
1818

1919
const router = Router()
@@ -23,11 +23,11 @@ router.get('/', async (req, res) => {
2323
const sql = getRolesSqlize(roles, grants)
2424
const { data } = await RunQuery(req.headers.pg, sql)
2525
const query: QueryParams = req.query
26-
const includeSystemSchemas = query?.includeSystemSchemas === 'true'
27-
const includeDefaultRoles = query?.includeDefaultRoles === 'true'
26+
const include_system_schemas = query?.include_system_schemas === 'true'
27+
const include_default_roles = query?.include_default_roles === 'true'
2828
let payload: Roles.Role[] = data
29-
if (!includeSystemSchemas) payload = removeSystemSchemas(data)
30-
if (!includeDefaultRoles) payload = removeDefaultRoles(payload)
29+
if (!include_system_schemas) payload = removeSystemSchemas(data)
30+
if (!include_default_roles) payload = removeDefaultRoles(payload)
3131

3232
return res.status(200).json(payload)
3333
} catch (error) {
@@ -100,46 +100,46 @@ FROM
100100
}
101101
const createRoleSqlize = ({
102102
name,
103-
isSuperuser = false,
104-
canCreateDb = false,
105-
canCreateRole = false,
106-
inheritRole = true,
107-
canLogin = false,
108-
isReplicationRole = false,
109-
canBypassRls = false,
110-
connectionLimit = -1,
103+
is_superuser = false,
104+
can_create_db = false,
105+
can_create_role = false,
106+
inherit_role = true,
107+
can_login = false,
108+
is_replication_role = false,
109+
can_bypass_rls = false,
110+
connection_limit = -1,
111111
password,
112-
validUntil,
113-
memberOf,
112+
valid_until,
113+
member_of,
114114
members,
115115
admins,
116116
}: {
117117
name: string
118-
isSuperuser?: boolean
119-
canCreateDb?: boolean
120-
canCreateRole?: boolean
121-
inheritRole?: boolean
122-
canLogin?: boolean
123-
isReplicationRole?: boolean
124-
canBypassRls?: boolean
125-
connectionLimit?: number
118+
is_superuser?: boolean
119+
can_create_db?: boolean
120+
can_create_role?: boolean
121+
inherit_role?: boolean
122+
can_login?: boolean
123+
is_replication_role?: boolean
124+
can_bypass_rls?: boolean
125+
connection_limit?: number
126126
password?: string
127-
validUntil?: string
128-
memberOf?: string[]
127+
valid_until?: string
128+
member_of?: string[]
129129
members?: string[]
130130
admins?: string[]
131131
}) => {
132-
const isSuperuserSql = isSuperuser ? 'SUPERUSER' : 'NOSUPERUSER'
133-
const canCreateDbSql = canCreateDb ? 'CREATEDB' : 'NOCREATEDB'
134-
const canCreateRoleSql = canCreateRole ? 'CREATEROLE' : 'NOCREATEROLE'
135-
const inheritRoleSql = inheritRole ? 'INHERIT' : 'NOINHERIT'
136-
const canLoginSql = canLogin ? 'LOGIN' : 'NOLOGIN'
137-
const isReplicationRoleSql = isReplicationRole ? 'REPLICATION' : 'NOREPLICATION'
138-
const canBypassRlsSql = canBypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'
139-
const connectionLimitSql = `CONNECTION LIMIT ${connectionLimit}`
132+
const isSuperuserSql = is_superuser ? 'SUPERUSER' : 'NOSUPERUSER'
133+
const canCreateDbSql = can_create_db ? 'CREATEDB' : 'NOCREATEDB'
134+
const canCreateRoleSql = can_create_role ? 'CREATEROLE' : 'NOCREATEROLE'
135+
const inheritRoleSql = inherit_role ? 'INHERIT' : 'NOINHERIT'
136+
const canLoginSql = can_login ? 'LOGIN' : 'NOLOGIN'
137+
const isReplicationRoleSql = is_replication_role ? 'REPLICATION' : 'NOREPLICATION'
138+
const canBypassRlsSql = can_bypass_rls ? 'BYPASSRLS' : 'NOBYPASSRLS'
139+
const connectionLimitSql = `CONNECTION LIMIT ${connection_limit}`
140140
const passwordSql = password === undefined ? '' : `PASSWORD '${password}'`
141-
const validUntilSql = validUntil === undefined ? '' : `VALID UNTIL '${validUntil}'`
142-
const memberOfSql = memberOf === undefined ? '' : `IN ROLE ${memberOf.join(',')}`
141+
const validUntilSql = valid_until === undefined ? '' : `VALID UNTIL '${valid_until}'`
142+
const memberOfSql = member_of === undefined ? '' : `IN ROLE ${member_of.join(',')}`
143143
const membersSql = members === undefined ? '' : `ROLE ${members.join(',')}`
144144
const adminsSql = admins === undefined ? '' : `ADMIN ${admins.join(',')}`
145145

@@ -169,63 +169,63 @@ const singleRoleByNameSqlize = (roles: string, name: string) => {
169169
const alterRoleSqlize = ({
170170
oldName,
171171
name,
172-
isSuperuser,
173-
canCreateDb,
174-
canCreateRole,
175-
inheritRole,
176-
canLogin,
177-
isReplicationRole,
178-
canBypassRls,
179-
connectionLimit,
172+
is_superuser,
173+
can_create_db,
174+
can_create_role,
175+
inherit_role,
176+
can_login,
177+
is_replication_role,
178+
can_bypass_rls,
179+
connection_limit,
180180
password,
181-
validUntil,
181+
valid_until,
182182
}: {
183183
oldName: string
184184
name?: string
185-
isSuperuser?: boolean
186-
canCreateDb?: boolean
187-
canCreateRole?: boolean
188-
inheritRole?: boolean
189-
canLogin?: boolean
190-
isReplicationRole?: boolean
191-
canBypassRls?: boolean
192-
connectionLimit?: number
185+
is_superuser?: boolean
186+
can_create_db?: boolean
187+
can_create_role?: boolean
188+
inherit_role?: boolean
189+
can_login?: boolean
190+
is_replication_role?: boolean
191+
can_bypass_rls?: boolean
192+
connection_limit?: number
193193
password?: string
194-
validUntil?: string
194+
valid_until?: string
195195
}) => {
196196
const nameSql = name === undefined ? '' : `ALTER ROLE "${oldName}" RENAME TO "${name}";`
197197
let isSuperuserSql = ''
198-
if (isSuperuser !== undefined) {
199-
isSuperuserSql = isSuperuser ? 'SUPERUSER' : 'NOSUPERUSER'
198+
if (is_superuser !== undefined) {
199+
isSuperuserSql = is_superuser ? 'SUPERUSER' : 'NOSUPERUSER'
200200
}
201201
let canCreateDbSql = ''
202-
if (canCreateDb !== undefined) {
203-
canCreateDbSql = canCreateDb ? 'CREATEDB' : 'NOCREATEDB'
202+
if (can_create_db !== undefined) {
203+
canCreateDbSql = can_create_db ? 'CREATEDB' : 'NOCREATEDB'
204204
}
205205
let canCreateRoleSql = ''
206-
if (canCreateRole !== undefined) {
207-
canCreateRoleSql = canCreateRole ? 'CREATEROLE' : 'NOCREATEROLE'
206+
if (can_create_role !== undefined) {
207+
canCreateRoleSql = can_create_role ? 'CREATEROLE' : 'NOCREATEROLE'
208208
}
209209
let inheritRoleSql = ''
210-
if (inheritRole !== undefined) {
211-
inheritRoleSql = inheritRole ? 'INHERIT' : 'NOINHERIT'
210+
if (inherit_role !== undefined) {
211+
inheritRoleSql = inherit_role ? 'INHERIT' : 'NOINHERIT'
212212
}
213213
let canLoginSql = ''
214-
if (canLogin !== undefined) {
215-
canLoginSql = canLogin ? 'LOGIN' : 'NOLOGIN'
214+
if (can_login !== undefined) {
215+
canLoginSql = can_login ? 'LOGIN' : 'NOLOGIN'
216216
}
217217
let isReplicationRoleSql = ''
218-
if (isReplicationRole !== undefined) {
219-
isReplicationRoleSql = isReplicationRole ? 'REPLICATION' : 'NOREPLICATION'
218+
if (is_replication_role !== undefined) {
219+
isReplicationRoleSql = is_replication_role ? 'REPLICATION' : 'NOREPLICATION'
220220
}
221221
let canBypassRlsSql = ''
222-
if (canBypassRls !== undefined) {
223-
canBypassRlsSql = canBypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'
222+
if (can_bypass_rls !== undefined) {
223+
canBypassRlsSql = can_bypass_rls ? 'BYPASSRLS' : 'NOBYPASSRLS'
224224
}
225225
const connectionLimitSql =
226-
connectionLimit === undefined ? '' : `CONNECTION LIMIT ${connectionLimit}`
226+
connection_limit === undefined ? '' : `CONNECTION LIMIT ${connection_limit}`
227227
let passwordSql = password === undefined ? '' : `PASSWORD '${password}'`
228-
let validUntilSql = validUntil === undefined ? '' : `VALID UNTIL '${validUntil}'`
228+
let validUntilSql = valid_until === undefined ? '' : `VALID UNTIL '${valid_until}'`
229229

230230
return `
231231
BEGIN;

0 commit comments

Comments
 (0)