Skip to content

Commit a71ea30

Browse files
committed
chore: rename sql imports
1 parent 1e4c13b commit a71ea30

File tree

12 files changed

+92
-71
lines changed

12 files changed

+92
-71
lines changed

src/api/columns.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ interface QueryParams {
1515
}
1616

1717
const router = Router()
18-
const { columns, tables } = sql
18+
const { columnsSql, tablesSql } = sql
1919

2020
router.get('/', async (req, res) => {
2121
try {
22-
const { data } = await RunQuery(req.headers.pg, columns)
22+
const { data } = await RunQuery(req.headers.pg, columnsSql)
2323
const query: QueryParams = req.query
2424
const include_system_schemas = query?.include_system_schemas === 'true'
2525
let payload: Tables.Column[] = data
@@ -99,7 +99,7 @@ router.delete('/:id', async (req, res) => {
9999
})
100100

101101
const getTableSqlize = (id: number) => {
102-
return SQL``.append(tables).append(SQL` AND c.oid = ${id}`)
102+
return SQL``.append(tablesSql).append(SQL` AND c.oid = ${id}`)
103103
}
104104
const addColumnSqlize = ({
105105
schema,
@@ -159,10 +159,10 @@ ${commentSql}`,
159159
)
160160
}
161161
const getColumnSqlize = (tableId: number, name: string) => {
162-
return SQL``.append(columns).append(SQL` AND c.oid = ${tableId} AND a.attname = ${name}`)
162+
return SQL``.append(columnsSql).append(SQL` AND c.oid = ${tableId} AND a.attname = ${name}`)
163163
}
164164
const getColumnByPosSqlize = (tableId: number, ordinalPos: number) => {
165-
return SQL``.append(columns).append(SQL` AND c.oid = ${tableId} AND a.attnum = ${ordinalPos}`)
165+
return SQL``.append(columnsSql).append(SQL` AND c.oid = ${tableId} AND a.attnum = ${ordinalPos}`)
166166
}
167167
const alterColumnSqlize = (
168168
old: any,

src/api/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { Router } from 'express'
33
import { RunQuery } from '../lib/connectionPool'
44
import sql = require('../lib/sql')
55
import { logger } from '../lib/logger'
6-
const { config, version } = sql
6+
const { configSql, versionSql } = sql
77

88
const router = Router()
99
router.get('/', async (req, res) => {
1010
try {
11-
const { data } = await RunQuery(req.headers.pg, config)
11+
const { data } = await RunQuery(req.headers.pg, configSql)
1212
return res.status(200).json(data)
1313
} catch (error) {
1414
logger.error({ error, req: req.body })
@@ -17,7 +17,7 @@ router.get('/', async (req, res) => {
1717
})
1818
router.get('/version', async (req, res) => {
1919
try {
20-
const { data } = await RunQuery(req.headers.pg, version)
20+
const { data } = await RunQuery(req.headers.pg, versionSql)
2121
return res.status(200).json(data[0]) // only one row
2222
} catch (error) {
2323
logger.error({ error, req: req.body })

src/api/extensions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { Router } from 'express'
22
import format from 'pg-format'
33
import SQL from 'sql-template-strings'
44
import sqlTemplates = require('../lib/sql')
5-
const { extensions } = sqlTemplates
5+
const { extensionsSql } = sqlTemplates
66
import { RunQuery } from '../lib/connectionPool'
77
import { logger } from '../lib/logger'
88

99
const router = Router()
1010

1111
router.get('/', async (req, res) => {
1212
try {
13-
const getExtensionsQuery = getExtensionsSqlize(extensions)
13+
const getExtensionsQuery = getExtensionsSqlize(extensionsSql)
1414
const { data } = await RunQuery(req.headers.pg, getExtensionsQuery)
1515
return res.status(200).json(data)
1616
} catch (error) {
@@ -24,7 +24,7 @@ router.post('/', async (req, res) => {
2424
const query = createExtensionSqlize(req.body)
2525
await RunQuery(req.headers.pg, query)
2626

27-
const getExtensionQuery = singleExtensionSqlize(extensions, req.body.name)
27+
const getExtensionQuery = singleExtensionSqlize(extensionsSql, req.body.name)
2828
const extension = (await RunQuery(req.headers.pg, getExtensionQuery)).data[0]
2929

3030
return res.status(200).json(extension)
@@ -42,7 +42,7 @@ router.patch('/:name', async (req, res) => {
4242
const alterExtensionQuery = alterExtensionSqlize(req.body)
4343
await RunQuery(req.headers.pg, alterExtensionQuery)
4444

45-
const getExtensionQuery = singleExtensionSqlize(extensions, name)
45+
const getExtensionQuery = singleExtensionSqlize(extensionsSql, name)
4646
const updated = (await RunQuery(req.headers.pg, getExtensionQuery)).data[0]
4747

4848
return res.status(200).json(updated)
@@ -57,7 +57,7 @@ router.delete('/:name', async (req, res) => {
5757
const name = req.params.name
5858
const cascade = req.query.cascade === 'true'
5959

60-
const getExtensionQuery = singleExtensionSqlize(extensions, name)
60+
const getExtensionQuery = singleExtensionSqlize(extensionsSql, name)
6161
const deleted = (await RunQuery(req.headers.pg, getExtensionQuery)).data[0]
6262

6363
const query = dropExtensionSqlize(name, cascade)

src/api/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Router } from 'express'
22

33
import sql = require('../lib/sql')
4-
const { functions } = sql
4+
const { functionsSql } = sql
55
import { RunQuery } from '../lib/connectionPool'
66
import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
77
import { Functions } from '../lib/interfaces'
@@ -17,7 +17,7 @@ interface QueryParams {
1717
const router = Router()
1818
router.get('/', async (req, res) => {
1919
try {
20-
const { data } = await RunQuery(req.headers.pg, functions)
20+
const { data } = await RunQuery(req.headers.pg, functionsSql)
2121
const query: QueryParams = req.query
2222
const include_system_schemas = query?.include_system_schemas === 'true'
2323
let payload: Functions.Function[] = data

src/api/policies.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ router.get('/', async (req, res) => {
3131
}
3232
})
3333

34-
router.post('/', async (req, res) => {
34+
router.post('/', async (req: any, res) => {
3535
try {
3636
const pcConnection: string = req.headers.pg.toString()
3737
const payload: Tables.Policy = { ...req.body }
@@ -52,7 +52,7 @@ router.post('/', async (req, res) => {
5252
}
5353
})
5454

55-
router.patch('/:id', async (req, res) => {
55+
router.patch('/:id', async (req: any, res) => {
5656
try {
5757
const pcConnection: string = req.headers.pg.toString()
5858
const id: number = parseInt(req.params.id)
@@ -88,7 +88,7 @@ router.patch('/:id', async (req, res) => {
8888
}
8989
})
9090

91-
router.delete('/:id', async (req, res) => {
91+
router.delete('/:id', async (req: any, res) => {
9292
try {
9393
const pcConnection: string = req.headers.pg.toString()
9494
const id: number = parseInt(req.params.id)
@@ -109,14 +109,14 @@ router.delete('/:id', async (req, res) => {
109109
}
110110
})
111111

112-
const getAllSql = (sqlTemplates) => {
113-
const { policies } = sqlTemplates
114-
return `${policies}`.trim()
112+
const getAllSql = (sqlTemplates: any) => {
113+
const { policiesSql } = sqlTemplates
114+
return `${policiesSql}`.trim()
115115
}
116116
const getPolicyById = async (connection: string, id: number) => {
117-
const { policies } = sqlTemplates
117+
const { policiesSql } = sqlTemplates
118118
const sql = `
119-
with policies as (${policies})
119+
with policies as (${policiesSql})
120120
select * from policies
121121
where policies.id = ${id}
122122
limit 1
@@ -125,10 +125,10 @@ const getPolicyById = async (connection: string, id: number) => {
125125
return data[0]
126126
}
127127
const getPolicyByName = async (connection: string, name: string, schema: string, table: string) => {
128-
const { policies } = sqlTemplates
128+
const { policiesSql } = sqlTemplates
129129
let sql = format(
130130
`
131-
with policies as (${policies})
131+
with policies as (${policiesSql})
132132
select * from policies
133133
where policies.name = %L and policies.schema = %L and policies.table = %L
134134
limit 1

src/api/publications.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import sql = require('../lib/sql')
44
import { RunQuery } from '../lib/connectionPool'
55
import { logger } from '../lib/logger'
66

7-
const { publications } = sql
7+
const { publicationsSql } = sql
88
const router = Router()
99

1010
router.get('/', async (req, res) => {
1111
try {
12-
const { data } = await RunQuery(req.headers.pg, publications)
12+
const { data } = await RunQuery(req.headers.pg, publicationsSql)
1313
return res.status(200).json(data)
1414
} catch (error) {
1515
logger.error({ error, req: req.body })
@@ -89,7 +89,7 @@ const createPublicationSqlize = ({
8989
publish_truncate?: boolean
9090
tables?: string[]
9191
}) => {
92-
let tableClause: string = `FOR TABLE ${tables.map(ident).join(',')}`
92+
let tableClause: string = `FOR TABLE ${tables!.map(ident).join(',')}`
9393
if (tables === undefined) {
9494
tableClause = 'FOR ALL TABLES'
9595
} else if (tables.length === 0) {
@@ -109,11 +109,11 @@ CREATE PUBLICATION ${ident(name)} ${tableClause}
109109
}
110110

111111
const getPublicationByNameSqlize = (name: string) => {
112-
return `${publications} WHERE p.pubname = ${literal(name)}`
112+
return `${publicationsSql} WHERE p.pubname = ${literal(name)}`
113113
}
114114

115115
const getPublicationByIdSqlize = (id: string) => {
116-
return `${publications} WHERE p.oid = ${literal(id)}`
116+
return `${publicationsSql} WHERE p.oid = ${literal(id)}`
117117
}
118118

119119
const alterPublicationSqlize = ({

src/api/roles.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Router } from 'express'
33
import format from 'pg-format'
44
import SQL from 'sql-template-strings'
55
import sqlTemplates = require('../lib/sql')
6-
const { grants, roles } = sqlTemplates
6+
const { grantsSql, rolesSql } = sqlTemplates
77
import { coalesceRowsToArray } from '../lib/helpers'
88
import { RunQuery } from '../lib/connectionPool'
99
import { DEFAULT_ROLES, DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
@@ -22,7 +22,7 @@ const router = Router()
2222

2323
router.get('/', async (req, res) => {
2424
try {
25-
const sql = getRolesSqlize(roles, grants)
25+
const sql = getRolesSqlize(rolesSql, grantsSql)
2626
const { data } = await RunQuery(req.headers.pg, sql)
2727
const query: QueryParams = req.query
2828
const include_system_schemas = query?.include_system_schemas === 'true'
@@ -43,7 +43,7 @@ router.post('/', async (req, res) => {
4343
const query = createRoleSqlize(req.body)
4444
await RunQuery(req.headers.pg, query)
4545

46-
const getRoleQuery = singleRoleByNameSqlize(roles, req.body.name)
46+
const getRoleQuery = singleRoleByNameSqlize(rolesSql, req.body.name)
4747
const role = (await RunQuery(req.headers.pg, getRoleQuery)).data[0]
4848

4949
return res.status(200).json(role)
@@ -56,7 +56,7 @@ router.post('/', async (req, res) => {
5656
router.patch('/:id', async (req, res) => {
5757
try {
5858
const id = req.params.id
59-
const getRoleQuery = singleRoleSqlize(roles, id)
59+
const getRoleQuery = singleRoleSqlize(rolesSql, id)
6060
const role = (await RunQuery(req.headers.pg, getRoleQuery)).data[0]
6161
const { name: oldName } = role
6262

@@ -76,7 +76,7 @@ router.patch('/:id', async (req, res) => {
7676
router.delete('/:id', async (req, res) => {
7777
try {
7878
const id = req.params.id
79-
const getRoleQuery = singleRoleSqlize(roles, id)
79+
const getRoleQuery = singleRoleSqlize(rolesSql, id)
8080
const role = (await RunQuery(req.headers.pg, getRoleQuery)).data[0]
8181
const { name } = role
8282

src/api/schemas.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
55
import { Schemas as Interfaces } from '../lib/interfaces'
66
import { logger } from '../lib/logger'
77

8-
const { schemas: allSchemasSql } = sqlTemplates
8+
const { schemasSql: allSchemasSql } = sqlTemplates
99
const defaultSchemasList = DEFAULT_SYSTEM_SCHEMAS.map((x) => `'${x}'`).join(', ')
1010

1111
/**
@@ -21,7 +21,7 @@ export async function list(
2121
include_system_schemas?: boolean
2222
}
2323
): /** Returns a list of schemas */
24-
Promise<{ data: Interfaces.Schema[]; error: null | Error }> {
24+
Promise<{ data: any; error: null | Error }> {
2525
try {
2626
let query = SQL``.append(allSchemasSql)
2727
if (!include_system_schemas) {
@@ -45,7 +45,7 @@ export async function byId(
4545
/** The schema `oid` */
4646
id: number
4747
): /** Returns a single schemas */
48-
Promise<{ data: Interfaces.Schema; error: null | Error }> {
48+
Promise<{ data: any; error: null | Error }> {
4949
try {
5050
const query = SQL``.append(allSchemasSql).append(SQL` and n.oid = ${id}`)
5151
const { data } = await RunQuery<Interfaces.Schema>(connection, query)
@@ -65,7 +65,7 @@ export async function byName(
6565
/** The schema name */
6666
name: string
6767
): /** Returns a single schemas */
68-
Promise<{ data: Interfaces.Schema; error: null | Error }> {
68+
Promise<{ data: any; error: null | Error }> {
6969
try {
7070
const query = SQL``.append(allSchemasSql).append(SQL` and n.nspname = ${name}`)
7171
const { data } = await RunQuery<Interfaces.Schema>(connection, query)

0 commit comments

Comments
 (0)