Update types
This commit is contained in:
@@ -22,7 +22,7 @@ const updateApiSchemaFromLocalDb = require("../query/update-api-schema-from-loca
|
||||
* ==============================================================================
|
||||
*
|
||||
* @param {object} params - Single object passed
|
||||
* @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} params.dbSchema - Database Schema Object
|
||||
* @param {DSQL_DatabaseSchemaType | undefined} params.dbSchema - Database Schema Object
|
||||
*
|
||||
* @returns {Promise<*>} new user auth object payload
|
||||
*/
|
||||
@@ -33,7 +33,7 @@ module.exports = async function addUsersTableToDb({ dbSchema }) {
|
||||
* @description Initialize
|
||||
*/
|
||||
const database = process.env.DSQL_DB_NAME || "";
|
||||
/** @type {import("@/package-shared/types/database-schema.td").DSQL_TableSchemaType} */
|
||||
/** @type {DSQL_TableSchemaType} */
|
||||
const userPreset = require("./data/presets/users.json");
|
||||
|
||||
try {
|
||||
|
||||
@@ -27,7 +27,7 @@ const updateTable = require("./utils/updateTable");
|
||||
* runs the "dsql create" command. `NOTE`: there must be a "dsql.schema.json" file
|
||||
* in the root of the project for this function to work
|
||||
*
|
||||
* @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} dbSchema - An array of database schema objects
|
||||
* @param {DSQL_DatabaseSchemaType | undefined} dbSchema - An array of database schema objects
|
||||
*/
|
||||
async function createDbFromSchema(dbSchema) {
|
||||
try {
|
||||
@@ -42,7 +42,7 @@ async function createDbFromSchema(dbSchema) {
|
||||
}
|
||||
|
||||
for (let i = 0; i < dbSchema.length; i++) {
|
||||
/** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */
|
||||
/** @type {DSQL_DatabaseSchemaType | undefined} */
|
||||
const database = dbSchema[i];
|
||||
|
||||
if (!database) {
|
||||
@@ -262,11 +262,11 @@ async function createDbFromSchema(dbSchema) {
|
||||
*/
|
||||
await varDatabaseDbHandler({
|
||||
queryString: `CREATE${
|
||||
indexType.match(/fullText/i)
|
||||
indexType?.match(/fullText/i)
|
||||
? " FULLTEXT"
|
||||
: ""
|
||||
} INDEX \`${alias}\` ON ${tableName}(${indexTableFields
|
||||
.map((nm) => nm.value)
|
||||
?.map((nm) => nm.value)
|
||||
.map((nm) => `\`${nm}\``)
|
||||
.join(
|
||||
","
|
||||
|
||||
@@ -17,7 +17,7 @@ const supplementTable = require("./supplementTable");
|
||||
* @param {string} param0.tableName
|
||||
* @param {any[]} param0.tableInfoArray
|
||||
* @param {(params: import("./varDatabaseDbHandler").VarDbHandlerParam)=>any} param0.varDatabaseDbHandler
|
||||
* @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType} [param0.dbSchema]
|
||||
* @param {DSQL_DatabaseSchemaType} [param0.dbSchema]
|
||||
* @returns
|
||||
*/
|
||||
module.exports = async function createTable({
|
||||
|
||||
@@ -65,7 +65,7 @@ const connection = mysql.createConnection({
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {string} params.query - Query String
|
||||
* @param {(string | number)[]} [params.values] - Values
|
||||
* @param {import("../../../package-shared/types/database-schema.td").DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema
|
||||
* @param {DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema
|
||||
* @param {string} [params.database] - Target Database
|
||||
* @param {string} [params.tableName] - Target Table Name
|
||||
*
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Generate SQL text for Field
|
||||
* ==============================================================================
|
||||
* @param {object} params - Single object params
|
||||
* @param {import("@/package-shared/types/database-schema.td").DSQL_FieldSchemaType} params.columnData - Field object
|
||||
* @param {DSQL_FieldSchemaType} params.columnData - Field object
|
||||
* @param {boolean} [params.primaryKeySet] - Table Name(slug)
|
||||
*
|
||||
* @returns {{fieldEntryText: string, newPrimaryKeySet: boolean}}
|
||||
|
||||
@@ -14,7 +14,7 @@ const defaultFieldsRegexp = require("./defaultFieldsRegexp");
|
||||
* @param {object} params - Single object params
|
||||
* @param {*[]} params.unparsedResults - Array of data objects containing Fields(keys)
|
||||
* and corresponding values of the fields(values)
|
||||
* @param {import("../../../package-shared/types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @param {DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||
* @returns {Promise<object[]|null>}
|
||||
*/
|
||||
module.exports = async function parseDbResults({
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {import("@/package-shared/types/database-schema.td").DSQL_FieldSchemaType[]} param0.tableInfoArray
|
||||
* @param {DSQL_FieldSchemaType[]} param0.tableInfoArray
|
||||
* @returns
|
||||
*/
|
||||
module.exports = function supplementTable({ tableInfoArray }) {
|
||||
|
||||
@@ -31,9 +31,9 @@ const schemaPath = path.resolve(process.cwd(), "dsql.schema.json");
|
||||
* @param {object} params - Single object params
|
||||
* @param {string} params.dbFullName - Database full name => "datasquirel_user_4394_db_name"
|
||||
* @param {string} params.tableName - Table Name(slug)
|
||||
* @param {import("@/package-shared/types/database-schema.td").DSQL_FieldSchemaType[]} params.tableInfoArray - Table Info Array
|
||||
* @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType[]} params.dbSchema - Single post
|
||||
* @param {import("@/package-shared/types/database-schema.td").DSQL_IndexSchemaType[]} [params.tableIndexes] - Table Indexes
|
||||
* @param {DSQL_FieldSchemaType[]} params.tableInfoArray - Table Info Array
|
||||
* @param {DSQL_DatabaseSchemaType[]} params.dbSchema - Single post
|
||||
* @param {DSQL_IndexSchemaType[]} [params.tableIndexes] - Table Indexes
|
||||
* @param {boolean} [params.clone] - Is this a newly cloned table?
|
||||
* @param {number} [params.tableIndex] - The number index of the table in the dbSchema array
|
||||
*
|
||||
@@ -141,7 +141,9 @@ module.exports = async function updateTable({
|
||||
* @description Check if Field name has been updated
|
||||
*/
|
||||
if (existingEntry[0].updatedField) {
|
||||
updatedColumnsArray.push(existingEntry[0].fieldName);
|
||||
updatedColumnsArray.push(
|
||||
String(existingEntry[0].fieldName)
|
||||
);
|
||||
|
||||
const renameColumn = await varDatabaseDbHandler({
|
||||
queryString: `ALTER TABLE ${tableName} RENAME COLUMN \`${existingEntry[0].originName}\` TO \`${existingEntry[0].fieldName}\``,
|
||||
@@ -293,9 +295,9 @@ module.exports = async function updateTable({
|
||||
*/
|
||||
await varDatabaseDbHandler({
|
||||
queryString: `CREATE${
|
||||
indexType.match(/fullText/i) ? " FULLTEXT" : ""
|
||||
indexType?.match(/fullText/i) ? " FULLTEXT" : ""
|
||||
} INDEX \`${alias}\` ON ${tableName}(${indexTableFields
|
||||
.map((nm) => nm.value)
|
||||
?.map((nm) => nm.value)
|
||||
.map((nm) => `\`${nm}\``)
|
||||
.join(",")}) COMMENT 'schema_index'`,
|
||||
database: dbFullName,
|
||||
@@ -375,7 +377,7 @@ module.exports = async function updateTable({
|
||||
/**
|
||||
* @description Skip default fields
|
||||
*/
|
||||
if (fieldName.match(/^id$|^date_/)) continue;
|
||||
if (fieldName?.match(/^id$|^date_/)) continue;
|
||||
/**
|
||||
* @description Skip columns that have been updated recently
|
||||
*/
|
||||
@@ -424,7 +426,7 @@ module.exports = async function updateTable({
|
||||
if (
|
||||
Field === fieldName &&
|
||||
!isColumnReordered &&
|
||||
dataType.toUpperCase() === Type.toUpperCase()
|
||||
dataType?.toUpperCase() === Type.toUpperCase()
|
||||
) {
|
||||
updateText += `MODIFY COLUMN ${fieldEntryText}`;
|
||||
// continue;
|
||||
|
||||
@@ -24,7 +24,7 @@ const dbHandler = require("./dbHandler");
|
||||
* @property {string} queryString - SQL string
|
||||
* @property {string[]} [queryValuesArray] - Values Array
|
||||
* @property {string} database - Database name
|
||||
* @property {import("@/package-shared/types/database-schema.td").DSQL_TableSchemaType} [tableSchema] - Table schema
|
||||
* @property {DSQL_TableSchemaType} [tableSchema] - Table schema
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user