mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
feat(new tool): JSON to SQL CREATE TABLE/DDL
This commit is contained in:
1 parent
f01d56cd6b
commit
06e4f84749
2 files changed
+55
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import { Database } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Json to SQL DDL',
|
||||
path: '/json-to-sql-ddl',
|
||||
description: 'JSON to SQL CREATE TABLE',
|
||||
keywords: ['json', 'sql', 'ddl', 'create', 'table'],
|
||||
component: () => import('./json-to-sql-ddl.vue'),
|
||||
icon: Database,
|
||||
createdAt: new Date('2025-03-09'),
|
||||
category: 'JSON',
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import GenerateSchema from 'generate-schema';
|
||||
import { withDefaultOnError } from '../../utils/defaults';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
|
||||
const tableName = ref('TableName');
|
||||
|
||||
function convertJsonToDDL(value: string) {
|
||||
const object = JSON5.parse(value);
|
||||
return GenerateSchema.mysql(tableName.value, object);
|
||||
}
|
||||
const transformer = (value: string) => value.trim() === '' ? '' : withDefaultOnError(() => convertJsonToDDL(value), '');
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (v: string) => v === '' || JSON5.parse(v),
|
||||
message: 'Provided JSON is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="tableName"
|
||||
label="Table Name"
|
||||
placeholder="Table Name"
|
||||
mb-2
|
||||
/>
|
||||
<n-divider />
|
||||
|
||||
<format-transformer
|
||||
input-label="Your JSON"
|
||||
input-placeholder="Paste your JSON here..."
|
||||
output-label="Your SQL DDL"
|
||||
output-language="sql"
|
||||
:input-validation-rules="rules"
|
||||
:transformer="transformer"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user