mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
Change endpoint from persons to people
This commit is contained in:
14
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-columncompiler.js
generated
vendored
Normal file
14
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-columncompiler.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
const ColumnCompiler_PG = require('../postgres/schema/pg-columncompiler.js');
|
||||
|
||||
class ColumnCompiler_CRDB extends ColumnCompiler_PG {
|
||||
uuid(options = { primaryKey: false }) {
|
||||
return (
|
||||
'uuid' +
|
||||
(this.tableCompiler._canBeAddPrimaryKey(options)
|
||||
? ' primary key default gen_random_uuid()'
|
||||
: '')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ColumnCompiler_CRDB;
|
11
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-querybuilder.js
generated
vendored
Normal file
11
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-querybuilder.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
const QueryBuilder = require('../../query/querybuilder');
|
||||
const isEmpty = require('lodash/isEmpty');
|
||||
|
||||
module.exports = class QueryBuilder_CockroachDB extends QueryBuilder {
|
||||
upsert(values, returning, options) {
|
||||
this._method = 'upsert';
|
||||
if (!isEmpty(returning)) this.returning(returning, options);
|
||||
this._single.upsert = values;
|
||||
return this;
|
||||
}
|
||||
};
|
122
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-querycompiler.js
generated
vendored
Normal file
122
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-querycompiler.js
generated
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
const QueryCompiler_PG = require('../postgres/query/pg-querycompiler');
|
||||
const {
|
||||
columnize: columnize_,
|
||||
wrap: wrap_,
|
||||
operator: operator_,
|
||||
} = require('../../formatter/wrappingFormatter');
|
||||
|
||||
class QueryCompiler_CRDB extends QueryCompiler_PG {
|
||||
truncate() {
|
||||
return `truncate ${this.tableName}`;
|
||||
}
|
||||
|
||||
upsert() {
|
||||
let sql = this._upsert();
|
||||
if (sql === '') return sql;
|
||||
const { returning } = this.single;
|
||||
if (returning) sql += this._returning(returning);
|
||||
return {
|
||||
sql: sql,
|
||||
returning,
|
||||
};
|
||||
}
|
||||
|
||||
_upsert() {
|
||||
const upsertValues = this.single.upsert || [];
|
||||
const sql = this.with() + `upsert into ${this.tableName} `;
|
||||
const body = this._insertBody(upsertValues);
|
||||
return body === '' ? '' : sql + body;
|
||||
}
|
||||
|
||||
_groupOrder(item, type) {
|
||||
// CockroachDB don't support PostgreSQL order nulls first/last syntax, we take the generic one.
|
||||
return this._basicGroupOrder(item, type);
|
||||
}
|
||||
|
||||
whereJsonPath(statement) {
|
||||
let castValue = '';
|
||||
if (!isNaN(statement.value) && parseInt(statement.value)) {
|
||||
castValue = '::int';
|
||||
} else if (!isNaN(statement.value) && parseFloat(statement.value)) {
|
||||
castValue = '::float';
|
||||
} else {
|
||||
castValue = " #>> '{}'";
|
||||
}
|
||||
return `json_extract_path(${this._columnClause(
|
||||
statement
|
||||
)}, ${this.client.toArrayPathFromJsonPath(
|
||||
statement.jsonPath,
|
||||
this.builder,
|
||||
this.bindingsHolder
|
||||
)})${castValue} ${operator_(
|
||||
statement.operator,
|
||||
this.builder,
|
||||
this.client,
|
||||
this.bindingsHolder
|
||||
)} ${this._jsonValueClause(statement)}`;
|
||||
}
|
||||
|
||||
// Json common functions
|
||||
_jsonExtract(nameFunction, params) {
|
||||
let extractions;
|
||||
if (Array.isArray(params.column)) {
|
||||
extractions = params.column;
|
||||
} else {
|
||||
extractions = [params];
|
||||
}
|
||||
return extractions
|
||||
.map((extraction) => {
|
||||
const jsonCol = `json_extract_path(${columnize_(
|
||||
extraction.column || extraction[0],
|
||||
this.builder,
|
||||
this.client,
|
||||
this.bindingsHolder
|
||||
)}, ${this.client.toArrayPathFromJsonPath(
|
||||
extraction.path || extraction[1],
|
||||
this.builder,
|
||||
this.bindingsHolder
|
||||
)})`;
|
||||
const alias = extraction.alias || extraction[2];
|
||||
return alias
|
||||
? this.client.alias(jsonCol, this.formatter.wrap(alias))
|
||||
: jsonCol;
|
||||
})
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
_onJsonPathEquals(nameJoinFunction, clause) {
|
||||
return (
|
||||
'json_extract_path(' +
|
||||
wrap_(
|
||||
clause.columnFirst,
|
||||
undefined,
|
||||
this.builder,
|
||||
this.client,
|
||||
this.bindingsHolder
|
||||
) +
|
||||
', ' +
|
||||
this.client.toArrayPathFromJsonPath(
|
||||
clause.jsonPathFirst,
|
||||
this.builder,
|
||||
this.bindingsHolder
|
||||
) +
|
||||
') = json_extract_path(' +
|
||||
wrap_(
|
||||
clause.columnSecond,
|
||||
undefined,
|
||||
this.builder,
|
||||
this.client,
|
||||
this.bindingsHolder
|
||||
) +
|
||||
', ' +
|
||||
this.client.toArrayPathFromJsonPath(
|
||||
clause.jsonPathSecond,
|
||||
this.builder,
|
||||
this.bindingsHolder
|
||||
) +
|
||||
')'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = QueryCompiler_CRDB;
|
37
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-tablecompiler.js
generated
vendored
Normal file
37
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-tablecompiler.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
const TableCompiler = require('../postgres/schema/pg-tablecompiler');
|
||||
|
||||
class TableCompiler_CRDB extends TableCompiler {
|
||||
constructor(client, tableBuilder) {
|
||||
super(client, tableBuilder);
|
||||
}
|
||||
|
||||
addColumns(columns, prefix, colCompilers) {
|
||||
if (prefix === this.alterColumnsPrefix) {
|
||||
// alter columns
|
||||
for (const col of colCompilers) {
|
||||
this.client.logger.warn(
|
||||
'Experimental alter column in use, see issue: https://github.com/cockroachdb/cockroach/issues/49329'
|
||||
);
|
||||
this.pushQuery({
|
||||
sql: 'SET enable_experimental_alter_column_type_general = true',
|
||||
bindings: [],
|
||||
});
|
||||
super._addColumn(col);
|
||||
}
|
||||
} else {
|
||||
// base class implementation for normal add
|
||||
super.addColumns(columns, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
dropUnique(columns, indexName) {
|
||||
indexName = indexName
|
||||
? this.formatter.wrap(indexName)
|
||||
: this._indexCommand('unique', this.tableNameRaw, columns);
|
||||
this.pushQuery(`drop index ${this.tableName()}@${indexName} cascade `);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TableCompiler_CRDB;
|
15
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-viewcompiler.js
generated
vendored
Normal file
15
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/crdb-viewcompiler.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
const ViewCompiler_PG = require('../postgres/schema/pg-viewcompiler.js');
|
||||
|
||||
class ViewCompiler_CRDB extends ViewCompiler_PG {
|
||||
renameColumn(from, to) {
|
||||
throw new Error('rename column of views is not supported by this dialect.');
|
||||
}
|
||||
|
||||
defaultTo(column, defaultValue) {
|
||||
throw new Error(
|
||||
'change default values of views is not supported by this dialect.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ViewCompiler_CRDB;
|
86
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/index.js
generated
vendored
Normal file
86
backend/apis/nodejs/node_modules/knex/lib/dialects/cockroachdb/index.js
generated
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
// CockroachDB Client
|
||||
// -------
|
||||
const Client_PostgreSQL = require('../postgres');
|
||||
const Transaction = require('../postgres/execution/pg-transaction');
|
||||
const QueryCompiler = require('./crdb-querycompiler');
|
||||
const ColumnCompiler = require('./crdb-columncompiler');
|
||||
const TableCompiler = require('./crdb-tablecompiler');
|
||||
const ViewCompiler = require('./crdb-viewcompiler');
|
||||
const QueryBuilder = require('./crdb-querybuilder');
|
||||
|
||||
// Always initialize with the "QueryBuilder" and "QueryCompiler"
|
||||
// objects, which extend the base 'lib/query/builder' and
|
||||
// 'lib/query/compiler', respectively.
|
||||
class Client_CockroachDB extends Client_PostgreSQL {
|
||||
transaction() {
|
||||
return new Transaction(this, ...arguments);
|
||||
}
|
||||
|
||||
queryCompiler(builder, formatter) {
|
||||
return new QueryCompiler(this, builder, formatter);
|
||||
}
|
||||
|
||||
columnCompiler() {
|
||||
return new ColumnCompiler(this, ...arguments);
|
||||
}
|
||||
|
||||
tableCompiler() {
|
||||
return new TableCompiler(this, ...arguments);
|
||||
}
|
||||
|
||||
viewCompiler() {
|
||||
return new ViewCompiler(this, ...arguments);
|
||||
}
|
||||
|
||||
queryBuilder() {
|
||||
return new QueryBuilder(this);
|
||||
}
|
||||
|
||||
_parseVersion(versionString) {
|
||||
return versionString.split(' ')[2];
|
||||
}
|
||||
|
||||
async cancelQuery(connectionToKill) {
|
||||
try {
|
||||
return await this._wrappedCancelQueryCall(null, connectionToKill);
|
||||
} catch (err) {
|
||||
this.logger.warn(`Connection Error: ${err}`);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
_wrappedCancelQueryCall(emptyConnection, connectionToKill) {
|
||||
// FixMe https://github.com/cockroachdb/cockroach/issues/41335
|
||||
if (
|
||||
connectionToKill.activeQuery.processID === 0 &&
|
||||
connectionToKill.activeQuery.secretKey === 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
return connectionToKill.cancel(
|
||||
connectionToKill,
|
||||
connectionToKill.activeQuery
|
||||
);
|
||||
}
|
||||
|
||||
toArrayPathFromJsonPath(jsonPath, builder, bindingsHolder) {
|
||||
return jsonPath
|
||||
.replace(/^(\$\.)/, '') // remove the first dollar
|
||||
.replace(/\[([0-9]+)]/, '.$1')
|
||||
.split('.')
|
||||
.map(
|
||||
function (v) {
|
||||
return this.parameter(v, builder, bindingsHolder);
|
||||
}.bind(this)
|
||||
)
|
||||
.join(', ');
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(Client_CockroachDB.prototype, {
|
||||
// The "dialect", for reference elsewhere.
|
||||
driverName: 'cockroachdb',
|
||||
});
|
||||
|
||||
module.exports = Client_CockroachDB;
|
Reference in New Issue
Block a user