🚧 Refactor backup service

This commit is contained in:
2025-12-14 23:48:52 +08:00
parent cc4c2189dc
commit 67d35626cb
47 changed files with 2184 additions and 489 deletions

View File

@@ -19,37 +19,45 @@ export class Document {
"id"?: number; "id"?: number;
/** /**
* 创建时间 * UUID for cross-device sync (UUIDv7)
*/
"uuid": string;
/**
* creation time
*/ */
"created_at": string; "created_at": string;
/** /**
* 最后更新时间 * update time
*/ */
"updated_at": string; "updated_at": string;
/** /**
* 删除时间NULL表示未删除 * deleted at
*/ */
"deleted_at"?: string | null; "deleted_at"?: string | null;
/** /**
* 文档标题 * document title
*/ */
"title": string; "title": string;
/** /**
* 文档内容 * document content
*/ */
"content": string; "content": string;
/** /**
* 是否锁定 * document locked status
*/ */
"locked": boolean; "locked": boolean;
/** Creates a new Document instance. */ /** Creates a new Document instance. */
constructor($$source: Partial<Document> = {}) { constructor($$source: Partial<Document> = {}) {
if (!("uuid" in $$source)) {
this["uuid"] = "";
}
if (!("created_at" in $$source)) { if (!("created_at" in $$source)) {
this["created_at"] = ""; this["created_at"] = "";
} }
@@ -88,37 +96,45 @@ export class Extension {
"id"?: number; "id"?: number;
/** /**
* 创建时间 * UUID for cross-device sync (UUIDv7)
*/
"uuid": string;
/**
* creation time
*/ */
"created_at": string; "created_at": string;
/** /**
* 最后更新时间 * update time
*/ */
"updated_at": string; "updated_at": string;
/** /**
* 删除时间NULL表示未删除 * deleted at
*/ */
"deleted_at"?: string | null; "deleted_at"?: string | null;
/** /**
* 扩展标识符 * extension key
*/ */
"key": string; "key": string;
/** /**
* 是否启用 * extension enabled or not
*/ */
"enabled": boolean; "enabled": boolean;
/** /**
* 扩展配置 * extension config
*/ */
"config": { [_: string]: any }; "config": { [_: string]: any };
/** Creates a new Extension instance. */ /** Creates a new Extension instance. */
constructor($$source: Partial<Extension> = {}) { constructor($$source: Partial<Extension> = {}) {
if (!("uuid" in $$source)) {
this["uuid"] = "";
}
if (!("created_at" in $$source)) { if (!("created_at" in $$source)) {
this["created_at"] = ""; this["created_at"] = "";
} }
@@ -142,10 +158,10 @@ export class Extension {
* Creates a new Extension instance from a string or object. * Creates a new Extension instance from a string or object.
*/ */
static createFrom($$source: any = {}): Extension { static createFrom($$source: any = {}): Extension {
const $$createField6_0 = $$createType0; const $$createField7_0 = $$createType0;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("config" in $$parsedSource) { if ("config" in $$parsedSource) {
$$parsedSource["config"] = $$createField6_0($$parsedSource["config"]); $$parsedSource["config"] = $$createField7_0($$parsedSource["config"]);
} }
return new Extension($$parsedSource as Partial<Extension>); return new Extension($$parsedSource as Partial<Extension>);
} }
@@ -161,42 +177,50 @@ export class KeyBinding {
"id"?: number; "id"?: number;
/** /**
* 创建时间 * UUID for cross-device sync (UUIDv7)
*/
"uuid": string;
/**
* creation time
*/ */
"created_at": string; "created_at": string;
/** /**
* 最后更新时间 * update time
*/ */
"updated_at": string; "updated_at": string;
/** /**
* 删除时间NULL表示未删除 * deleted at
*/ */
"deleted_at"?: string | null; "deleted_at"?: string | null;
/** /**
* 快捷键标识符 * key binding key
*/ */
"key": string; "key": string;
/** /**
* 快捷键命令 * key binding command
*/ */
"command": string; "command": string;
/** /**
* 所属扩展标识符 * key binding extension
*/ */
"extension"?: string; "extension"?: string;
/** /**
* 是否启用 * key binding enabled
*/ */
"enabled": boolean; "enabled": boolean;
/** Creates a new KeyBinding instance. */ /** Creates a new KeyBinding instance. */
constructor($$source: Partial<KeyBinding> = {}) { constructor($$source: Partial<KeyBinding> = {}) {
if (!("uuid" in $$source)) {
this["uuid"] = "";
}
if (!("created_at" in $$source)) { if (!("created_at" in $$source)) {
this["created_at"] = ""; this["created_at"] = "";
} }
@@ -235,37 +259,45 @@ export class Theme {
"id"?: number; "id"?: number;
/** /**
* 创建时间 * UUID for cross-device sync (UUIDv7)
*/
"uuid": string;
/**
* creation time
*/ */
"created_at": string; "created_at": string;
/** /**
* 最后更新时间 * update time
*/ */
"updated_at": string; "updated_at": string;
/** /**
* 删除时间NULL表示未删除 * deleted at
*/ */
"deleted_at"?: string | null; "deleted_at"?: string | null;
/** /**
* 主题标识符 * theme key
*/ */
"key": string; "key": string;
/** /**
* 主题类型 * theme type
*/ */
"type": theme$0.Type; "type": theme$0.Type;
/** /**
* 主题颜色配置 * theme colors
*/ */
"colors": { [_: string]: any }; "colors": { [_: string]: any };
/** Creates a new Theme instance. */ /** Creates a new Theme instance. */
constructor($$source: Partial<Theme> = {}) { constructor($$source: Partial<Theme> = {}) {
if (!("uuid" in $$source)) {
this["uuid"] = "";
}
if (!("created_at" in $$source)) { if (!("created_at" in $$source)) {
this["created_at"] = ""; this["created_at"] = "";
} }
@@ -289,10 +321,10 @@ export class Theme {
* Creates a new Theme instance from a string or object. * Creates a new Theme instance from a string or object.
*/ */
static createFrom($$source: any = {}): Theme { static createFrom($$source: any = {}): Theme {
const $$createField6_0 = $$createType0; const $$createField7_0 = $$createType0;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("colors" in $$parsedSource) { if ("colors" in $$parsedSource) {
$$parsedSource["colors"] = $$createField6_0($$parsedSource["colors"]); $$parsedSource["colors"] = $$createField7_0($$parsedSource["colors"]);
} }
return new Theme($$parsedSource as Partial<Theme>); return new Theme($$parsedSource as Partial<Theme>);
} }

View File

@@ -2,7 +2,7 @@
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
/** /**
* BackupService 提供基于Git的备份功能 * BackupService 提供基于Git的备份同步功能
* @module * @module
*/ */
@@ -18,7 +18,7 @@ import * as application$0 from "../../../github.com/wailsapp/wails/v3/pkg/applic
import * as models$0 from "../models/models.js"; import * as models$0 from "../models/models.js";
/** /**
* HandleConfigChange 处理备份配置变更 * HandleConfigChange 处理配置变更
*/ */
export function HandleConfigChange(config: models$0.GitBackupConfig | null): Promise<void> & { cancel(): void } { export function HandleConfigChange(config: models$0.GitBackupConfig | null): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(395287784, config) as any; let $resultPromise = $Call.ByID(395287784, config) as any;
@@ -34,15 +34,7 @@ export function Initialize(): Promise<void> & { cancel(): void } {
} }
/** /**
* PushToRemote 推送本地更改到远程仓库 * Reinitialize 重新初始化
*/
export function PushToRemote(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(262644139) as any;
return $resultPromise;
}
/**
* Reinitialize 重新初始化备份服务,用于响应配置变更
*/ */
export function Reinitialize(): Promise<void> & { cancel(): void } { export function Reinitialize(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(301562543) as any; let $resultPromise = $Call.ByID(301562543) as any;
@@ -50,7 +42,7 @@ export function Reinitialize(): Promise<void> & { cancel(): void } {
} }
/** /**
* ServiceShutdown 服务关闭时的清理工作 * ServiceShutdown 服务关闭
*/ */
export function ServiceShutdown(): Promise<void> & { cancel(): void } { export function ServiceShutdown(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(422131801) as any; let $resultPromise = $Call.ByID(422131801) as any;
@@ -63,7 +55,7 @@ export function ServiceStartup(options: application$0.ServiceOptions): Promise<v
} }
/** /**
* StartAutoBackup 启动自动备份定时器 * StartAutoBackup 启动自动备份
*/ */
export function StartAutoBackup(): Promise<void> & { cancel(): void } { export function StartAutoBackup(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3035755449) as any; let $resultPromise = $Call.ByID(3035755449) as any;
@@ -77,3 +69,11 @@ export function StopAutoBackup(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(2641894021) as any; let $resultPromise = $Call.ByID(2641894021) as any;
return $resultPromise; return $resultPromise;
} }
/**
* Sync 执行完整的同步流程:导出 -> commit -> pull -> 解决冲突 -> push -> 导入
*/
export function Sync(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3420383211) as any;
return $resultPromise;
}

View File

@@ -46,7 +46,7 @@ export default {
keybindings: { keybindings: {
headers: { headers: {
shortcut: 'Shortcut', shortcut: 'Shortcut',
category: 'Category', extension: 'Extension',
description: 'Description' description: 'Description'
}, },
commands: { commands: {
@@ -227,14 +227,10 @@ export default {
sshKeyPassphrase: 'SSH Key Passphrase', sshKeyPassphrase: 'SSH Key Passphrase',
sshKeyPassphrasePlaceholder: 'Enter SSH key passphrase', sshKeyPassphrasePlaceholder: 'Enter SSH key passphrase',
backupOperations: 'Backup Operations', backupOperations: 'Backup Operations',
pushToRemote: 'Push to Remote', syncToRemote: 'Sync to Remote',
pushing: 'Pushing...', syncing: 'Syncing...',
actions: { actions: {
push: 'Push', sync: 'Sync',
},
status: {
success: 'Success',
failed: 'Failed'
} }
}, },
}, },

View File

@@ -46,7 +46,7 @@ export default {
keybindings: { keybindings: {
headers: { headers: {
shortcut: '快捷键', shortcut: '快捷键',
category: '分类', extension: '扩展',
description: '描述' description: '描述'
}, },
commands: { commands: {
@@ -229,14 +229,10 @@ export default {
sshKeyPassphrase: 'SSH密钥密码', sshKeyPassphrase: 'SSH密钥密码',
sshKeyPassphrasePlaceholder: '请输入SSH密钥密码', sshKeyPassphrasePlaceholder: '请输入SSH密钥密码',
backupOperations: '备份操作', backupOperations: '备份操作',
pushToRemote: '推送到远程', syncToRemote: '同步到远程',
pushing: '推送中...', syncing: '同步中...',
actions: { actions: {
push: '推送', sync: '同步',
},
status: {
success: '成功',
failed: '失败'
} }
}, },
}, },

View File

@@ -1,49 +1,31 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { ref, onScopeDispose } from 'vue'; import { ref } from 'vue';
import { BackupService } from '@/../bindings/voidraft/internal/services'; import { BackupService } from '@/../bindings/voidraft/internal/services';
import { useConfigStore } from '@/stores/configStore';
import { createTimerManager } from '@/common/utils/timerUtils';
export const useBackupStore = defineStore('backup', () => { export const useBackupStore = defineStore('backup', () => {
const isPushing = ref(false); const isSyncing = ref(false);
const message = ref<string | null>(null); const error = ref<string | null>(null);
const isError = ref(false);
const timer = createTimerManager();
const configStore = useConfigStore();
onScopeDispose(() => timer.clear()); const sync = async (): Promise<void> => {
if (isSyncing.value) {
const pushToRemote = async () => {
const isConfigured = Boolean(configStore.config.backup.repo_url?.trim());
if (isPushing.value || !isConfigured) {
return; return;
} }
isSyncing.value = true;
error.value = null;
try { try {
isPushing.value = true; await BackupService.Sync();
message.value = null; } catch (e) {
timer.clear(); error.value = e instanceof Error ? e.message : String(e);
await BackupService.PushToRemote();
isError.value = false;
message.value = 'push successful';
timer.set(() => { message.value = null; }, 3000);
} catch (error) {
isError.value = true;
message.value = error instanceof Error ? error.message : 'backup operation failed';
timer.set(() => { message.value = null; }, 5000);
} finally { } finally {
isPushing.value = false; isSyncing.value = false;
} }
}; };
return { return {
isPushing, isSyncing,
message, error,
isError, sync
pushToRemote
}; };
}); });

View File

@@ -1,6 +1,5 @@
import { Extension } from '@codemirror/state'; import { Extension } from '@codemirror/state';
import { useKeybindingStore } from '@/stores/keybindingStore'; import { useKeybindingStore } from '@/stores/keybindingStore';
import { useExtensionStore } from '@/stores/extensionStore';
import { Manager } from './manager'; import { Manager } from './manager';
/** /**
@@ -8,24 +7,13 @@ import { Manager } from './manager';
*/ */
export const createDynamicKeymapExtension = async (): Promise<Extension> => { export const createDynamicKeymapExtension = async (): Promise<Extension> => {
const keybindingStore = useKeybindingStore(); const keybindingStore = useKeybindingStore();
const extensionStore = useExtensionStore();
// 确保快捷键配置已加载 // 确保快捷键配置已加载
if (keybindingStore.keyBindings.length === 0) { if (keybindingStore.keyBindings.length === 0) {
await keybindingStore.loadKeyBindings(); await keybindingStore.loadKeyBindings();
} }
// 确保扩展配置已加载 return Manager.createKeymapExtension(keybindingStore.keyBindings);
if (extensionStore.extensions.length === 0) {
await extensionStore.loadExtensions();
}
// 获取启用的扩展key列表
const enabledExtensionKeys = extensionStore.enabledExtensions
.map(ext => ext.key)
.filter((key): key is string => key !== undefined);
return Manager.createKeymapExtension(keybindingStore.keyBindings, enabledExtensionKeys);
}; };
/** /**
@@ -34,14 +22,7 @@ export const createDynamicKeymapExtension = async (): Promise<Extension> => {
*/ */
export const updateKeymapExtension = (view: any): void => { export const updateKeymapExtension = (view: any): void => {
const keybindingStore = useKeybindingStore(); const keybindingStore = useKeybindingStore();
const extensionStore = useExtensionStore(); Manager.updateKeymap(view, keybindingStore.keyBindings);
// 获取启用的扩展key列表
const enabledExtensionKeys = extensionStore.enabledExtensions
.map(ext => ext.key)
.filter((key): key is string => key !== undefined);
Manager.updateKeymap(view, keybindingStore.keyBindings, enabledExtensionKeys);
}; };
// 导出相关模块 // 导出相关模块

View File

@@ -14,10 +14,9 @@ export class Manager {
/** /**
* 将后端快捷键配置转换为CodeMirror快捷键绑定 * 将后端快捷键配置转换为CodeMirror快捷键绑定
* @param keyBindings 后端快捷键配置列表 * @param keyBindings 后端快捷键配置列表
* @param enabledExtensions 启用的扩展key列表如果不提供则使用所有启用的快捷键
* @returns 转换结果 * @returns 转换结果
*/ */
static convertToKeyBindings(keyBindings: KeyBindingConfig[], enabledExtensions?: string[]): KeymapResult { static convertToKeyBindings(keyBindings: KeyBindingConfig[]): KeymapResult {
const result: KeyBinding[] = []; const result: KeyBinding[] = [];
for (const binding of keyBindings) { for (const binding of keyBindings) {
@@ -26,11 +25,6 @@ export class Manager {
continue; continue;
} }
// 如果提供了扩展列表,则只处理启用扩展的快捷键
if (enabledExtensions && binding.extension && !enabledExtensions.includes(binding.extension)) {
continue;
}
// 检查命令是否已注册(使用 key 字段作为命令标识符) // 检查命令是否已注册(使用 key 字段作为命令标识符)
if (!binding.key || !isCommandRegistered(binding.key)) { if (!binding.key || !isCommandRegistered(binding.key)) {
continue; continue;
@@ -59,13 +53,10 @@ export class Manager {
/** /**
* 创建CodeMirror快捷键扩展 * 创建CodeMirror快捷键扩展
* @param keyBindings 后端快捷键配置列表 * @param keyBindings 后端快捷键配置列表
* @param enabledExtensions 启用的扩展key列表
* @returns CodeMirror扩展 * @returns CodeMirror扩展
*/ */
static createKeymapExtension(keyBindings: KeyBindingConfig[], enabledExtensions?: string[]): Extension { static createKeymapExtension(keyBindings: KeyBindingConfig[]): Extension {
const {keyBindings: cmKeyBindings} = const {keyBindings: cmKeyBindings} = this.convertToKeyBindings(keyBindings);
this.convertToKeyBindings(keyBindings, enabledExtensions);
return this.compartment.of(keymap.of(cmKeyBindings)); return this.compartment.of(keymap.of(cmKeyBindings));
} }
@@ -73,12 +64,9 @@ export class Manager {
* 动态更新快捷键扩展 * 动态更新快捷键扩展
* @param view 编辑器视图 * @param view 编辑器视图
* @param keyBindings 后端快捷键配置列表 * @param keyBindings 后端快捷键配置列表
* @param enabledExtensions 启用的扩展key列表
*/ */
static updateKeymap(view: any, keyBindings: KeyBindingConfig[], enabledExtensions: string[]): void { static updateKeymap(view: any, keyBindings: KeyBindingConfig[]): void {
const {keyBindings: cmKeyBindings} = const {keyBindings: cmKeyBindings} = this.convertToKeyBindings(keyBindings);
this.convertToKeyBindings(keyBindings, enabledExtensions);
view.dispatch({ view.dispatch({
effects: this.compartment.reconfigure(keymap.of(cmKeyBindings)) effects: this.compartment.reconfigure(keymap.of(cmKeyBindings))
}); });

View File

@@ -2,7 +2,7 @@
import {useConfigStore} from '@/stores/configStore'; import {useConfigStore} from '@/stores/configStore';
import {useBackupStore} from '@/stores/backupStore'; import {useBackupStore} from '@/stores/backupStore';
import {useI18n} from 'vue-i18n'; import {useI18n} from 'vue-i18n';
import {computed} from 'vue'; import {computed, ref, watch, onUnmounted} from 'vue';
import SettingSection from '../components/SettingSection.vue'; import SettingSection from '../components/SettingSection.vue';
import SettingItem from '../components/SettingItem.vue'; import SettingItem from '../components/SettingItem.vue';
import ToggleSwitch from '../components/ToggleSwitch.vue'; import ToggleSwitch from '../components/ToggleSwitch.vue';
@@ -13,6 +13,37 @@ const {t} = useI18n();
const configStore = useConfigStore(); const configStore = useConfigStore();
const backupStore = useBackupStore(); const backupStore = useBackupStore();
// 消息显示状态
const message = ref<string | null>(null);
const isError = ref(false);
let messageTimer: ReturnType<typeof setTimeout> | null = null;
const clearMessage = () => {
if (messageTimer) {
clearTimeout(messageTimer);
messageTimer = null;
}
message.value = null;
};
// 监听同步完成,显示消息并自动消失
watch(() => backupStore.isSyncing, (syncing, wasSyncing) => {
if (wasSyncing && !syncing) {
clearMessage();
if (backupStore.error) {
message.value = backupStore.error;
isError.value = true;
messageTimer = setTimeout(clearMessage, 5000);
} else {
message.value = 'Sync successful';
isError.value = false;
messageTimer = setTimeout(clearMessage, 3000);
}
}
});
onUnmounted(clearMessage);
const authMethodOptions = computed(() => [ const authMethodOptions = computed(() => [
{value: AuthMethod.Token, label: t('settings.backup.authMethods.token')}, {value: AuthMethod.Token, label: t('settings.backup.authMethods.token')},
{value: AuthMethod.SSHKey, label: t('settings.backup.authMethods.sshKey')}, {value: AuthMethod.SSHKey, label: t('settings.backup.authMethods.sshKey')},
@@ -172,18 +203,18 @@ const selectSshKeyFile = async () => {
<!-- 备份操作 --> <!-- 备份操作 -->
<SettingSection :title="t('settings.backup.backupOperations')"> <SettingSection :title="t('settings.backup.backupOperations')">
<SettingItem <SettingItem
:title="t('settings.backup.pushToRemote')" :title="t('settings.backup.syncToRemote')"
:description="backupStore.message || undefined" :description="message || undefined"
:descriptionType="backupStore.message ? (backupStore.isError ? 'error' : 'success') : 'default'" :descriptionType="message ? (isError ? 'error' : 'success') : 'default'"
> >
<button <button
class="push-button" class="sync-button"
@click="backupStore.pushToRemote" @click="backupStore.sync"
:disabled="!configStore.config.backup.enabled || !configStore.config.backup.repo_url || backupStore.isPushing" :disabled="!configStore.config.backup.enabled || !configStore.config.backup.repo_url || backupStore.isSyncing"
:class="{ 'backing-up': backupStore.isPushing }" :class="{ 'syncing': backupStore.isSyncing }"
> >
<span v-if="backupStore.isPushing" class="loading-spinner"></span> <span v-if="backupStore.isSyncing" class="loading-spinner"></span>
{{ backupStore.isPushing ? t('settings.backup.pushing') : t('settings.backup.actions.push') }} {{ backupStore.isSyncing ? t('settings.backup.syncing') : t('settings.backup.actions.sync') }}
</button> </button>
</SettingItem> </SettingItem>
</SettingSection> </SettingSection>
@@ -257,7 +288,7 @@ const selectSshKeyFile = async () => {
} }
// 按钮样式 // 按钮样式
.push-button { .sync-button {
padding: 8px 16px; padding: 8px 16px;
background-color: var(--settings-input-bg); background-color: var(--settings-input-bg);
border: 1px solid var(--settings-input-border); border: 1px solid var(--settings-input-border);
@@ -294,7 +325,7 @@ const selectSshKeyFile = async () => {
animation: spin 1s linear infinite; animation: spin 1s linear infinite;
} }
&.backing-up { &.syncing {
background-color: #2196f3; background-color: #2196f3;
border-color: #2196f3; border-color: #2196f3;
color: white; color: white;

View File

@@ -3,33 +3,27 @@ import { useI18n } from 'vue-i18n';
import { onMounted, computed } from 'vue'; import { onMounted, computed } from 'vue';
import SettingSection from '../components/SettingSection.vue'; import SettingSection from '../components/SettingSection.vue';
import { useKeybindingStore } from '@/stores/keybindingStore'; import { useKeybindingStore } from '@/stores/keybindingStore';
import { useExtensionStore } from '@/stores/extensionStore';
import { useSystemStore } from '@/stores/systemStore'; import { useSystemStore } from '@/stores/systemStore';
import { getCommandDescription } from '@/views/editor/keymap/commands'; import { getCommandDescription } from '@/views/editor/keymap/commands';
import { KeyBindingKey } from '@/../bindings/voidraft/internal/models/models'; import { KeyBindingKey } from '@/../bindings/voidraft/internal/models/models';
const { t } = useI18n(); const { t } = useI18n();
const keybindingStore = useKeybindingStore(); const keybindingStore = useKeybindingStore();
const extensionStore = useExtensionStore();
const systemStore = useSystemStore(); const systemStore = useSystemStore();
// 加载数据 // 加载数据
onMounted(async () => { onMounted(async () => {
await keybindingStore.loadKeyBindings(); await keybindingStore.loadKeyBindings();
await extensionStore.loadExtensions();
}); });
// 从store中获取快捷键数据并转换为显示格式 // 从store中获取快捷键数据并转换为显示格式
const keyBindings = computed(() => { const keyBindings = computed(() => {
// 只显示启用扩展的快捷键
const enabledExtensionIds = new Set(extensionStore.enabledExtensionIds);
return keybindingStore.keyBindings return keybindingStore.keyBindings
.filter(kb => kb.enabled && (!kb.extension || enabledExtensionIds.has(kb.extension))) .filter(kb => kb.enabled)
.map(kb => ({ .map(kb => ({
id: kb.key, key: kb.key,
keys: parseKeyBinding(kb.command || '', kb.key), command: parseKeyBinding(kb.command || '', kb.key),
category: kb.extension || '', extension: kb.extension || '',
description: kb.key ? (getCommandDescription(kb.key) || kb.key) : '' description: kb.key ? (getCommandDescription(kb.key) || kb.key) : ''
})); }));
}); });
@@ -204,25 +198,25 @@ const parseKeyBinding = (keyStr: string, keyBindingKey?: string): string[] => {
<div class="key-bindings-container"> <div class="key-bindings-container">
<div class="key-bindings-header"> <div class="key-bindings-header">
<div class="keybinding-col">{{ t('keybindings.headers.shortcut') }}</div> <div class="keybinding-col">{{ t('keybindings.headers.shortcut') }}</div>
<div class="category-col">{{ t('keybindings.headers.category') }}</div> <div class="extension-col">{{ t('keybindings.headers.extension') }}</div>
<div class="description-col">{{ t('keybindings.headers.description') }}</div> <div class="description-col">{{ t('keybindings.headers.description') }}</div>
</div> </div>
<div <div
v-for="binding in keyBindings" v-for="binding in keyBindings"
:key="binding.id" :key="binding.key"
class="key-binding-row" class="key-binding-row"
> >
<div class="keybinding-col"> <div class="keybinding-col">
<span <span
v-for="(key, index) in binding.keys" v-for="(key, index) in binding.command"
:key="index" :key="index"
class="key-badge" class="key-badge"
> >
{{ key }} {{ key }}
</span> </span>
</div> </div>
<div class="category-col">{{ binding.category }}</div> <div class="extension-col">{{ binding.extension }}</div>
<div class="description-col">{{ binding.description }}</div> <div class="description-col">{{ binding.description }}</div>
</div> </div>
</div> </div>
@@ -276,7 +270,7 @@ const parseKeyBinding = (keyStr: string, keyBindingKey?: string): string[] => {
} }
} }
.category-col { .extension-col {
width: 80px; width: 80px;
padding: 0 10px 0 0; padding: 0 10px 0 0;
font-size: 13px; font-size: 13px;

2
go.mod
View File

@@ -6,6 +6,7 @@ require (
entgo.io/ent v0.14.5 entgo.io/ent v0.14.5
github.com/creativeprojects/go-selfupdate v1.5.1 github.com/creativeprojects/go-selfupdate v1.5.1
github.com/go-git/go-git/v5 v5.16.3 github.com/go-git/go-git/v5 v5.16.3
github.com/google/uuid v1.6.0
github.com/knadh/koanf/parsers/json v1.0.0 github.com/knadh/koanf/parsers/json v1.0.0
github.com/knadh/koanf/providers/file v1.2.0 github.com/knadh/koanf/providers/file v1.2.0
github.com/knadh/koanf/providers/structs v1.0.0 github.com/knadh/koanf/providers/structs v1.0.0
@@ -52,7 +53,6 @@ require (
github.com/google/go-cmp v0.7.0 // indirect github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-github/v30 v30.1.0 // indirect github.com/google/go-github/v30 v30.1.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect github.com/hashicorp/go-version v1.7.0 // indirect

View File

@@ -208,7 +208,7 @@ func NewDefaultAppConfig() *AppConfig {
}, },
Appearance: AppearanceConfig{ Appearance: AppearanceConfig{
Language: LangEnUS, Language: LangEnUS,
SystemTheme: SystemThemeAuto, SystemTheme: SystemThemeDark,
CurrentTheme: "default-dark", // 默认使用 default-dark 主题 CurrentTheme: "default-dark", // 默认使用 default-dark 主题
}, },
Updates: UpdatesConfig{ Updates: UpdatesConfig{

View File

@@ -16,17 +16,19 @@ type Document struct {
config `json:"-"` config `json:"-"`
// ID of the ent. // ID of the ent.
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// 创建时间 // UUID for cross-device sync (UUIDv7)
UUID string `json:"uuid"`
// creation time
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
// 最后更新时间 // update time
UpdatedAt string `json:"updated_at"` UpdatedAt string `json:"updated_at"`
// 删除时间NULL表示未删除 // deleted at
DeletedAt *string `json:"deleted_at,omitempty"` DeletedAt *string `json:"deleted_at,omitempty"`
// 文档标题 // document title
Title string `json:"title"` Title string `json:"title"`
// 文档内容 // document content
Content string `json:"content"` Content string `json:"content"`
// 是否锁定 // document locked status
Locked bool `json:"locked"` Locked bool `json:"locked"`
selectValues sql.SelectValues selectValues sql.SelectValues
} }
@@ -40,7 +42,7 @@ func (*Document) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool) values[i] = new(sql.NullBool)
case document.FieldID: case document.FieldID:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case document.FieldCreatedAt, document.FieldUpdatedAt, document.FieldDeletedAt, document.FieldTitle, document.FieldContent: case document.FieldUUID, document.FieldCreatedAt, document.FieldUpdatedAt, document.FieldDeletedAt, document.FieldTitle, document.FieldContent:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
default: default:
values[i] = new(sql.UnknownType) values[i] = new(sql.UnknownType)
@@ -63,6 +65,12 @@ func (_m *Document) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field id", value) return fmt.Errorf("unexpected type %T for field id", value)
} }
_m.ID = int(value.Int64) _m.ID = int(value.Int64)
case document.FieldUUID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field uuid", values[i])
} else if value.Valid {
_m.UUID = value.String
}
case document.FieldCreatedAt: case document.FieldCreatedAt:
if value, ok := values[i].(*sql.NullString); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i]) return fmt.Errorf("unexpected type %T for field created_at", values[i])
@@ -136,6 +144,9 @@ func (_m *Document) String() string {
var builder strings.Builder var builder strings.Builder
builder.WriteString("Document(") builder.WriteString("Document(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("uuid=")
builder.WriteString(_m.UUID)
builder.WriteString(", ")
builder.WriteString("created_at=") builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt) builder.WriteString(_m.CreatedAt)
builder.WriteString(", ") builder.WriteString(", ")

View File

@@ -12,6 +12,8 @@ const (
Label = "document" Label = "document"
// FieldID holds the string denoting the id field in the database. // FieldID holds the string denoting the id field in the database.
FieldID = "id" FieldID = "id"
// FieldUUID holds the string denoting the uuid field in the database.
FieldUUID = "uuid"
// FieldCreatedAt holds the string denoting the created_at field in the database. // FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at" FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database. // FieldUpdatedAt holds the string denoting the updated_at field in the database.
@@ -31,6 +33,7 @@ const (
// Columns holds all SQL columns for document fields. // Columns holds all SQL columns for document fields.
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldUUID,
FieldCreatedAt, FieldCreatedAt,
FieldUpdatedAt, FieldUpdatedAt,
FieldDeletedAt, FieldDeletedAt,
@@ -57,6 +60,8 @@ func ValidColumn(column string) bool {
var ( var (
Hooks [2]ent.Hook Hooks [2]ent.Hook
Interceptors [1]ent.Interceptor Interceptors [1]ent.Interceptor
// DefaultUUID holds the default value on creation for the "uuid" field.
DefaultUUID func() string
// DefaultCreatedAt holds the default value on creation for the "created_at" field. // DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() string DefaultCreatedAt func() string
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field. // DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
@@ -77,6 +82,11 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc() return sql.OrderByField(FieldID, opts...).ToFunc()
} }
// ByUUID orders the results by the uuid field.
func ByUUID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUUID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field. // ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()

View File

@@ -53,6 +53,11 @@ func IDLTE(id int) predicate.Document {
return predicate.Document(sql.FieldLTE(FieldID, id)) return predicate.Document(sql.FieldLTE(FieldID, id))
} }
// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ.
func UUID(v string) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldUUID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v string) predicate.Document { func CreatedAt(v string) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldCreatedAt, v)) return predicate.Document(sql.FieldEQ(FieldCreatedAt, v))
@@ -83,6 +88,81 @@ func Locked(v bool) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldLocked, v)) return predicate.Document(sql.FieldEQ(FieldLocked, v))
} }
// UUIDEQ applies the EQ predicate on the "uuid" field.
func UUIDEQ(v string) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldUUID, v))
}
// UUIDNEQ applies the NEQ predicate on the "uuid" field.
func UUIDNEQ(v string) predicate.Document {
return predicate.Document(sql.FieldNEQ(FieldUUID, v))
}
// UUIDIn applies the In predicate on the "uuid" field.
func UUIDIn(vs ...string) predicate.Document {
return predicate.Document(sql.FieldIn(FieldUUID, vs...))
}
// UUIDNotIn applies the NotIn predicate on the "uuid" field.
func UUIDNotIn(vs ...string) predicate.Document {
return predicate.Document(sql.FieldNotIn(FieldUUID, vs...))
}
// UUIDGT applies the GT predicate on the "uuid" field.
func UUIDGT(v string) predicate.Document {
return predicate.Document(sql.FieldGT(FieldUUID, v))
}
// UUIDGTE applies the GTE predicate on the "uuid" field.
func UUIDGTE(v string) predicate.Document {
return predicate.Document(sql.FieldGTE(FieldUUID, v))
}
// UUIDLT applies the LT predicate on the "uuid" field.
func UUIDLT(v string) predicate.Document {
return predicate.Document(sql.FieldLT(FieldUUID, v))
}
// UUIDLTE applies the LTE predicate on the "uuid" field.
func UUIDLTE(v string) predicate.Document {
return predicate.Document(sql.FieldLTE(FieldUUID, v))
}
// UUIDContains applies the Contains predicate on the "uuid" field.
func UUIDContains(v string) predicate.Document {
return predicate.Document(sql.FieldContains(FieldUUID, v))
}
// UUIDHasPrefix applies the HasPrefix predicate on the "uuid" field.
func UUIDHasPrefix(v string) predicate.Document {
return predicate.Document(sql.FieldHasPrefix(FieldUUID, v))
}
// UUIDHasSuffix applies the HasSuffix predicate on the "uuid" field.
func UUIDHasSuffix(v string) predicate.Document {
return predicate.Document(sql.FieldHasSuffix(FieldUUID, v))
}
// UUIDIsNil applies the IsNil predicate on the "uuid" field.
func UUIDIsNil() predicate.Document {
return predicate.Document(sql.FieldIsNull(FieldUUID))
}
// UUIDNotNil applies the NotNil predicate on the "uuid" field.
func UUIDNotNil() predicate.Document {
return predicate.Document(sql.FieldNotNull(FieldUUID))
}
// UUIDEqualFold applies the EqualFold predicate on the "uuid" field.
func UUIDEqualFold(v string) predicate.Document {
return predicate.Document(sql.FieldEqualFold(FieldUUID, v))
}
// UUIDContainsFold applies the ContainsFold predicate on the "uuid" field.
func UUIDContainsFold(v string) predicate.Document {
return predicate.Document(sql.FieldContainsFold(FieldUUID, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field. // CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v string) predicate.Document { func CreatedAtEQ(v string) predicate.Document {
return predicate.Document(sql.FieldEQ(FieldCreatedAt, v)) return predicate.Document(sql.FieldEQ(FieldCreatedAt, v))

View File

@@ -19,6 +19,20 @@ type DocumentCreate struct {
hooks []Hook hooks []Hook
} }
// SetUUID sets the "uuid" field.
func (_c *DocumentCreate) SetUUID(v string) *DocumentCreate {
_c.mutation.SetUUID(v)
return _c
}
// SetNillableUUID sets the "uuid" field if the given value is not nil.
func (_c *DocumentCreate) SetNillableUUID(v *string) *DocumentCreate {
if v != nil {
_c.SetUUID(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (_c *DocumentCreate) SetCreatedAt(v string) *DocumentCreate { func (_c *DocumentCreate) SetCreatedAt(v string) *DocumentCreate {
_c.mutation.SetCreatedAt(v) _c.mutation.SetCreatedAt(v)
@@ -132,6 +146,13 @@ func (_c *DocumentCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save. // defaults sets the default values of the builder before save.
func (_c *DocumentCreate) defaults() error { func (_c *DocumentCreate) defaults() error {
if _, ok := _c.mutation.UUID(); !ok {
if document.DefaultUUID == nil {
return fmt.Errorf("ent: uninitialized document.DefaultUUID (forgotten import ent/runtime?)")
}
v := document.DefaultUUID()
_c.mutation.SetUUID(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok { if _, ok := _c.mutation.CreatedAt(); !ok {
if document.DefaultCreatedAt == nil { if document.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized document.DefaultCreatedAt (forgotten import ent/runtime?)") return fmt.Errorf("ent: uninitialized document.DefaultCreatedAt (forgotten import ent/runtime?)")
@@ -202,6 +223,10 @@ func (_c *DocumentCreate) createSpec() (*Document, *sqlgraph.CreateSpec) {
_node = &Document{config: _c.config} _node = &Document{config: _c.config}
_spec = sqlgraph.NewCreateSpec(document.Table, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt)) _spec = sqlgraph.NewCreateSpec(document.Table, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt))
) )
if value, ok := _c.mutation.UUID(); ok {
_spec.SetField(document.FieldUUID, field.TypeString, value)
_node.UUID = value
}
if value, ok := _c.mutation.CreatedAt(); ok { if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(document.FieldCreatedAt, field.TypeString, value) _spec.SetField(document.FieldCreatedAt, field.TypeString, value)
_node.CreatedAt = value _node.CreatedAt = value

View File

@@ -265,12 +265,12 @@ func (_q *DocumentQuery) Clone() *DocumentQuery {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// CreatedAt string `json:"created_at"` // UUID string `json:"uuid"`
// Count int `json:"count,omitempty"` // Count int `json:"count,omitempty"`
// } // }
// //
// client.Document.Query(). // client.Document.Query().
// GroupBy(document.FieldCreatedAt). // GroupBy(document.FieldUUID).
// Aggregate(ent.Count()). // Aggregate(ent.Count()).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupBy { func (_q *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupBy {
@@ -288,11 +288,11 @@ func (_q *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupB
// Example: // Example:
// //
// var v []struct { // var v []struct {
// CreatedAt string `json:"created_at"` // UUID string `json:"uuid"`
// } // }
// //
// client.Document.Query(). // client.Document.Query().
// Select(document.FieldCreatedAt). // Select(document.FieldUUID).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *DocumentQuery) Select(fields ...string) *DocumentSelect { func (_q *DocumentQuery) Select(fields ...string) *DocumentSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...) _q.ctx.Fields = append(_q.ctx.Fields, fields...)

View File

@@ -170,6 +170,9 @@ func (_u *DocumentUpdate) sqlSave(ctx context.Context) (_node int, err error) {
} }
} }
} }
if _u.mutation.UUIDCleared() {
_spec.ClearField(document.FieldUUID, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok { if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(document.FieldUpdatedAt, field.TypeString, value) _spec.SetField(document.FieldUpdatedAt, field.TypeString, value)
} }
@@ -385,6 +388,9 @@ func (_u *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err
} }
} }
} }
if _u.mutation.UUIDCleared() {
_spec.ClearField(document.FieldUUID, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok { if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(document.FieldUpdatedAt, field.TypeString, value) _spec.SetField(document.FieldUpdatedAt, field.TypeString, value)
} }

View File

@@ -28,6 +28,7 @@ var schemaGraph = func() *sqlgraph.Schema {
}, },
Type: "Document", Type: "Document",
Fields: map[string]*sqlgraph.FieldSpec{ Fields: map[string]*sqlgraph.FieldSpec{
document.FieldUUID: {Type: field.TypeString, Column: document.FieldUUID},
document.FieldCreatedAt: {Type: field.TypeString, Column: document.FieldCreatedAt}, document.FieldCreatedAt: {Type: field.TypeString, Column: document.FieldCreatedAt},
document.FieldUpdatedAt: {Type: field.TypeString, Column: document.FieldUpdatedAt}, document.FieldUpdatedAt: {Type: field.TypeString, Column: document.FieldUpdatedAt},
document.FieldDeletedAt: {Type: field.TypeString, Column: document.FieldDeletedAt}, document.FieldDeletedAt: {Type: field.TypeString, Column: document.FieldDeletedAt},
@@ -47,6 +48,7 @@ var schemaGraph = func() *sqlgraph.Schema {
}, },
Type: "Extension", Type: "Extension",
Fields: map[string]*sqlgraph.FieldSpec{ Fields: map[string]*sqlgraph.FieldSpec{
extension.FieldUUID: {Type: field.TypeString, Column: extension.FieldUUID},
extension.FieldCreatedAt: {Type: field.TypeString, Column: extension.FieldCreatedAt}, extension.FieldCreatedAt: {Type: field.TypeString, Column: extension.FieldCreatedAt},
extension.FieldUpdatedAt: {Type: field.TypeString, Column: extension.FieldUpdatedAt}, extension.FieldUpdatedAt: {Type: field.TypeString, Column: extension.FieldUpdatedAt},
extension.FieldDeletedAt: {Type: field.TypeString, Column: extension.FieldDeletedAt}, extension.FieldDeletedAt: {Type: field.TypeString, Column: extension.FieldDeletedAt},
@@ -66,6 +68,7 @@ var schemaGraph = func() *sqlgraph.Schema {
}, },
Type: "KeyBinding", Type: "KeyBinding",
Fields: map[string]*sqlgraph.FieldSpec{ Fields: map[string]*sqlgraph.FieldSpec{
keybinding.FieldUUID: {Type: field.TypeString, Column: keybinding.FieldUUID},
keybinding.FieldCreatedAt: {Type: field.TypeString, Column: keybinding.FieldCreatedAt}, keybinding.FieldCreatedAt: {Type: field.TypeString, Column: keybinding.FieldCreatedAt},
keybinding.FieldUpdatedAt: {Type: field.TypeString, Column: keybinding.FieldUpdatedAt}, keybinding.FieldUpdatedAt: {Type: field.TypeString, Column: keybinding.FieldUpdatedAt},
keybinding.FieldDeletedAt: {Type: field.TypeString, Column: keybinding.FieldDeletedAt}, keybinding.FieldDeletedAt: {Type: field.TypeString, Column: keybinding.FieldDeletedAt},
@@ -86,6 +89,7 @@ var schemaGraph = func() *sqlgraph.Schema {
}, },
Type: "Theme", Type: "Theme",
Fields: map[string]*sqlgraph.FieldSpec{ Fields: map[string]*sqlgraph.FieldSpec{
theme.FieldUUID: {Type: field.TypeString, Column: theme.FieldUUID},
theme.FieldCreatedAt: {Type: field.TypeString, Column: theme.FieldCreatedAt}, theme.FieldCreatedAt: {Type: field.TypeString, Column: theme.FieldCreatedAt},
theme.FieldUpdatedAt: {Type: field.TypeString, Column: theme.FieldUpdatedAt}, theme.FieldUpdatedAt: {Type: field.TypeString, Column: theme.FieldUpdatedAt},
theme.FieldDeletedAt: {Type: field.TypeString, Column: theme.FieldDeletedAt}, theme.FieldDeletedAt: {Type: field.TypeString, Column: theme.FieldDeletedAt},
@@ -143,6 +147,11 @@ func (f *DocumentFilter) WhereID(p entql.IntP) {
f.Where(p.Field(document.FieldID)) f.Where(p.Field(document.FieldID))
} }
// WhereUUID applies the entql string predicate on the uuid field.
func (f *DocumentFilter) WhereUUID(p entql.StringP) {
f.Where(p.Field(document.FieldUUID))
}
// WhereCreatedAt applies the entql string predicate on the created_at field. // WhereCreatedAt applies the entql string predicate on the created_at field.
func (f *DocumentFilter) WhereCreatedAt(p entql.StringP) { func (f *DocumentFilter) WhereCreatedAt(p entql.StringP) {
f.Where(p.Field(document.FieldCreatedAt)) f.Where(p.Field(document.FieldCreatedAt))
@@ -213,6 +222,11 @@ func (f *ExtensionFilter) WhereID(p entql.IntP) {
f.Where(p.Field(extension.FieldID)) f.Where(p.Field(extension.FieldID))
} }
// WhereUUID applies the entql string predicate on the uuid field.
func (f *ExtensionFilter) WhereUUID(p entql.StringP) {
f.Where(p.Field(extension.FieldUUID))
}
// WhereCreatedAt applies the entql string predicate on the created_at field. // WhereCreatedAt applies the entql string predicate on the created_at field.
func (f *ExtensionFilter) WhereCreatedAt(p entql.StringP) { func (f *ExtensionFilter) WhereCreatedAt(p entql.StringP) {
f.Where(p.Field(extension.FieldCreatedAt)) f.Where(p.Field(extension.FieldCreatedAt))
@@ -283,6 +297,11 @@ func (f *KeyBindingFilter) WhereID(p entql.IntP) {
f.Where(p.Field(keybinding.FieldID)) f.Where(p.Field(keybinding.FieldID))
} }
// WhereUUID applies the entql string predicate on the uuid field.
func (f *KeyBindingFilter) WhereUUID(p entql.StringP) {
f.Where(p.Field(keybinding.FieldUUID))
}
// WhereCreatedAt applies the entql string predicate on the created_at field. // WhereCreatedAt applies the entql string predicate on the created_at field.
func (f *KeyBindingFilter) WhereCreatedAt(p entql.StringP) { func (f *KeyBindingFilter) WhereCreatedAt(p entql.StringP) {
f.Where(p.Field(keybinding.FieldCreatedAt)) f.Where(p.Field(keybinding.FieldCreatedAt))
@@ -358,6 +377,11 @@ func (f *ThemeFilter) WhereID(p entql.IntP) {
f.Where(p.Field(theme.FieldID)) f.Where(p.Field(theme.FieldID))
} }
// WhereUUID applies the entql string predicate on the uuid field.
func (f *ThemeFilter) WhereUUID(p entql.StringP) {
f.Where(p.Field(theme.FieldUUID))
}
// WhereCreatedAt applies the entql string predicate on the created_at field. // WhereCreatedAt applies the entql string predicate on the created_at field.
func (f *ThemeFilter) WhereCreatedAt(p entql.StringP) { func (f *ThemeFilter) WhereCreatedAt(p entql.StringP) {
f.Where(p.Field(theme.FieldCreatedAt)) f.Where(p.Field(theme.FieldCreatedAt))

View File

@@ -17,17 +17,19 @@ type Extension struct {
config `json:"-"` config `json:"-"`
// ID of the ent. // ID of the ent.
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// 创建时间 // UUID for cross-device sync (UUIDv7)
UUID string `json:"uuid"`
// creation time
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
// 最后更新时间 // update time
UpdatedAt string `json:"updated_at"` UpdatedAt string `json:"updated_at"`
// 删除时间NULL表示未删除 // deleted at
DeletedAt *string `json:"deleted_at,omitempty"` DeletedAt *string `json:"deleted_at,omitempty"`
// 扩展标识符 // extension key
Key string `json:"key"` Key string `json:"key"`
// 是否启用 // extension enabled or not
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
// 扩展配置 // extension config
Config map[string]interface{} `json:"config"` Config map[string]interface{} `json:"config"`
selectValues sql.SelectValues selectValues sql.SelectValues
} }
@@ -43,7 +45,7 @@ func (*Extension) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool) values[i] = new(sql.NullBool)
case extension.FieldID: case extension.FieldID:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case extension.FieldCreatedAt, extension.FieldUpdatedAt, extension.FieldDeletedAt, extension.FieldKey: case extension.FieldUUID, extension.FieldCreatedAt, extension.FieldUpdatedAt, extension.FieldDeletedAt, extension.FieldKey:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
default: default:
values[i] = new(sql.UnknownType) values[i] = new(sql.UnknownType)
@@ -66,6 +68,12 @@ func (_m *Extension) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field id", value) return fmt.Errorf("unexpected type %T for field id", value)
} }
_m.ID = int(value.Int64) _m.ID = int(value.Int64)
case extension.FieldUUID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field uuid", values[i])
} else if value.Valid {
_m.UUID = value.String
}
case extension.FieldCreatedAt: case extension.FieldCreatedAt:
if value, ok := values[i].(*sql.NullString); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i]) return fmt.Errorf("unexpected type %T for field created_at", values[i])
@@ -141,6 +149,9 @@ func (_m *Extension) String() string {
var builder strings.Builder var builder strings.Builder
builder.WriteString("Extension(") builder.WriteString("Extension(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("uuid=")
builder.WriteString(_m.UUID)
builder.WriteString(", ")
builder.WriteString("created_at=") builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt) builder.WriteString(_m.CreatedAt)
builder.WriteString(", ") builder.WriteString(", ")

View File

@@ -12,6 +12,8 @@ const (
Label = "extension" Label = "extension"
// FieldID holds the string denoting the id field in the database. // FieldID holds the string denoting the id field in the database.
FieldID = "id" FieldID = "id"
// FieldUUID holds the string denoting the uuid field in the database.
FieldUUID = "uuid"
// FieldCreatedAt holds the string denoting the created_at field in the database. // FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at" FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database. // FieldUpdatedAt holds the string denoting the updated_at field in the database.
@@ -31,6 +33,7 @@ const (
// Columns holds all SQL columns for extension fields. // Columns holds all SQL columns for extension fields.
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldUUID,
FieldCreatedAt, FieldCreatedAt,
FieldUpdatedAt, FieldUpdatedAt,
FieldDeletedAt, FieldDeletedAt,
@@ -57,6 +60,8 @@ func ValidColumn(column string) bool {
var ( var (
Hooks [2]ent.Hook Hooks [2]ent.Hook
Interceptors [1]ent.Interceptor Interceptors [1]ent.Interceptor
// DefaultUUID holds the default value on creation for the "uuid" field.
DefaultUUID func() string
// DefaultCreatedAt holds the default value on creation for the "created_at" field. // DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() string DefaultCreatedAt func() string
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field. // DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
@@ -75,6 +80,11 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc() return sql.OrderByField(FieldID, opts...).ToFunc()
} }
// ByUUID orders the results by the uuid field.
func ByUUID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUUID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field. // ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()

View File

@@ -53,6 +53,11 @@ func IDLTE(id int) predicate.Extension {
return predicate.Extension(sql.FieldLTE(FieldID, id)) return predicate.Extension(sql.FieldLTE(FieldID, id))
} }
// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ.
func UUID(v string) predicate.Extension {
return predicate.Extension(sql.FieldEQ(FieldUUID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v string) predicate.Extension { func CreatedAt(v string) predicate.Extension {
return predicate.Extension(sql.FieldEQ(FieldCreatedAt, v)) return predicate.Extension(sql.FieldEQ(FieldCreatedAt, v))
@@ -78,6 +83,81 @@ func Enabled(v bool) predicate.Extension {
return predicate.Extension(sql.FieldEQ(FieldEnabled, v)) return predicate.Extension(sql.FieldEQ(FieldEnabled, v))
} }
// UUIDEQ applies the EQ predicate on the "uuid" field.
func UUIDEQ(v string) predicate.Extension {
return predicate.Extension(sql.FieldEQ(FieldUUID, v))
}
// UUIDNEQ applies the NEQ predicate on the "uuid" field.
func UUIDNEQ(v string) predicate.Extension {
return predicate.Extension(sql.FieldNEQ(FieldUUID, v))
}
// UUIDIn applies the In predicate on the "uuid" field.
func UUIDIn(vs ...string) predicate.Extension {
return predicate.Extension(sql.FieldIn(FieldUUID, vs...))
}
// UUIDNotIn applies the NotIn predicate on the "uuid" field.
func UUIDNotIn(vs ...string) predicate.Extension {
return predicate.Extension(sql.FieldNotIn(FieldUUID, vs...))
}
// UUIDGT applies the GT predicate on the "uuid" field.
func UUIDGT(v string) predicate.Extension {
return predicate.Extension(sql.FieldGT(FieldUUID, v))
}
// UUIDGTE applies the GTE predicate on the "uuid" field.
func UUIDGTE(v string) predicate.Extension {
return predicate.Extension(sql.FieldGTE(FieldUUID, v))
}
// UUIDLT applies the LT predicate on the "uuid" field.
func UUIDLT(v string) predicate.Extension {
return predicate.Extension(sql.FieldLT(FieldUUID, v))
}
// UUIDLTE applies the LTE predicate on the "uuid" field.
func UUIDLTE(v string) predicate.Extension {
return predicate.Extension(sql.FieldLTE(FieldUUID, v))
}
// UUIDContains applies the Contains predicate on the "uuid" field.
func UUIDContains(v string) predicate.Extension {
return predicate.Extension(sql.FieldContains(FieldUUID, v))
}
// UUIDHasPrefix applies the HasPrefix predicate on the "uuid" field.
func UUIDHasPrefix(v string) predicate.Extension {
return predicate.Extension(sql.FieldHasPrefix(FieldUUID, v))
}
// UUIDHasSuffix applies the HasSuffix predicate on the "uuid" field.
func UUIDHasSuffix(v string) predicate.Extension {
return predicate.Extension(sql.FieldHasSuffix(FieldUUID, v))
}
// UUIDIsNil applies the IsNil predicate on the "uuid" field.
func UUIDIsNil() predicate.Extension {
return predicate.Extension(sql.FieldIsNull(FieldUUID))
}
// UUIDNotNil applies the NotNil predicate on the "uuid" field.
func UUIDNotNil() predicate.Extension {
return predicate.Extension(sql.FieldNotNull(FieldUUID))
}
// UUIDEqualFold applies the EqualFold predicate on the "uuid" field.
func UUIDEqualFold(v string) predicate.Extension {
return predicate.Extension(sql.FieldEqualFold(FieldUUID, v))
}
// UUIDContainsFold applies the ContainsFold predicate on the "uuid" field.
func UUIDContainsFold(v string) predicate.Extension {
return predicate.Extension(sql.FieldContainsFold(FieldUUID, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field. // CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v string) predicate.Extension { func CreatedAtEQ(v string) predicate.Extension {
return predicate.Extension(sql.FieldEQ(FieldCreatedAt, v)) return predicate.Extension(sql.FieldEQ(FieldCreatedAt, v))

View File

@@ -19,6 +19,20 @@ type ExtensionCreate struct {
hooks []Hook hooks []Hook
} }
// SetUUID sets the "uuid" field.
func (_c *ExtensionCreate) SetUUID(v string) *ExtensionCreate {
_c.mutation.SetUUID(v)
return _c
}
// SetNillableUUID sets the "uuid" field if the given value is not nil.
func (_c *ExtensionCreate) SetNillableUUID(v *string) *ExtensionCreate {
if v != nil {
_c.SetUUID(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (_c *ExtensionCreate) SetCreatedAt(v string) *ExtensionCreate { func (_c *ExtensionCreate) SetCreatedAt(v string) *ExtensionCreate {
_c.mutation.SetCreatedAt(v) _c.mutation.SetCreatedAt(v)
@@ -124,6 +138,13 @@ func (_c *ExtensionCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save. // defaults sets the default values of the builder before save.
func (_c *ExtensionCreate) defaults() error { func (_c *ExtensionCreate) defaults() error {
if _, ok := _c.mutation.UUID(); !ok {
if extension.DefaultUUID == nil {
return fmt.Errorf("ent: uninitialized extension.DefaultUUID (forgotten import ent/runtime?)")
}
v := extension.DefaultUUID()
_c.mutation.SetUUID(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok { if _, ok := _c.mutation.CreatedAt(); !ok {
if extension.DefaultCreatedAt == nil { if extension.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized extension.DefaultCreatedAt (forgotten import ent/runtime?)") return fmt.Errorf("ent: uninitialized extension.DefaultCreatedAt (forgotten import ent/runtime?)")
@@ -190,6 +211,10 @@ func (_c *ExtensionCreate) createSpec() (*Extension, *sqlgraph.CreateSpec) {
_node = &Extension{config: _c.config} _node = &Extension{config: _c.config}
_spec = sqlgraph.NewCreateSpec(extension.Table, sqlgraph.NewFieldSpec(extension.FieldID, field.TypeInt)) _spec = sqlgraph.NewCreateSpec(extension.Table, sqlgraph.NewFieldSpec(extension.FieldID, field.TypeInt))
) )
if value, ok := _c.mutation.UUID(); ok {
_spec.SetField(extension.FieldUUID, field.TypeString, value)
_node.UUID = value
}
if value, ok := _c.mutation.CreatedAt(); ok { if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(extension.FieldCreatedAt, field.TypeString, value) _spec.SetField(extension.FieldCreatedAt, field.TypeString, value)
_node.CreatedAt = value _node.CreatedAt = value

View File

@@ -265,12 +265,12 @@ func (_q *ExtensionQuery) Clone() *ExtensionQuery {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// CreatedAt string `json:"created_at"` // UUID string `json:"uuid"`
// Count int `json:"count,omitempty"` // Count int `json:"count,omitempty"`
// } // }
// //
// client.Extension.Query(). // client.Extension.Query().
// GroupBy(extension.FieldCreatedAt). // GroupBy(extension.FieldUUID).
// Aggregate(ent.Count()). // Aggregate(ent.Count()).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *ExtensionQuery) GroupBy(field string, fields ...string) *ExtensionGroupBy { func (_q *ExtensionQuery) GroupBy(field string, fields ...string) *ExtensionGroupBy {
@@ -288,11 +288,11 @@ func (_q *ExtensionQuery) GroupBy(field string, fields ...string) *ExtensionGrou
// Example: // Example:
// //
// var v []struct { // var v []struct {
// CreatedAt string `json:"created_at"` // UUID string `json:"uuid"`
// } // }
// //
// client.Extension.Query(). // client.Extension.Query().
// Select(extension.FieldCreatedAt). // Select(extension.FieldUUID).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *ExtensionQuery) Select(fields ...string) *ExtensionSelect { func (_q *ExtensionQuery) Select(fields ...string) *ExtensionSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...) _q.ctx.Fields = append(_q.ctx.Fields, fields...)

View File

@@ -162,6 +162,9 @@ func (_u *ExtensionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
} }
} }
} }
if _u.mutation.UUIDCleared() {
_spec.ClearField(extension.FieldUUID, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok { if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(extension.FieldUpdatedAt, field.TypeString, value) _spec.SetField(extension.FieldUpdatedAt, field.TypeString, value)
} }
@@ -369,6 +372,9 @@ func (_u *ExtensionUpdateOne) sqlSave(ctx context.Context) (_node *Extension, er
} }
} }
} }
if _u.mutation.UUIDCleared() {
_spec.ClearField(extension.FieldUUID, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok { if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(extension.FieldUpdatedAt, field.TypeString, value) _spec.SetField(extension.FieldUpdatedAt, field.TypeString, value)
} }

View File

@@ -16,19 +16,21 @@ type KeyBinding struct {
config `json:"-"` config `json:"-"`
// ID of the ent. // ID of the ent.
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// 创建时间 // UUID for cross-device sync (UUIDv7)
UUID string `json:"uuid"`
// creation time
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
// 最后更新时间 // update time
UpdatedAt string `json:"updated_at"` UpdatedAt string `json:"updated_at"`
// 删除时间NULL表示未删除 // deleted at
DeletedAt *string `json:"deleted_at,omitempty"` DeletedAt *string `json:"deleted_at,omitempty"`
// 快捷键标识符 // key binding key
Key string `json:"key"` Key string `json:"key"`
// 快捷键命令 // key binding command
Command string `json:"command"` Command string `json:"command"`
// 所属扩展标识符 // key binding extension
Extension string `json:"extension,omitempty"` Extension string `json:"extension,omitempty"`
// 是否启用 // key binding enabled
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
selectValues sql.SelectValues selectValues sql.SelectValues
} }
@@ -42,7 +44,7 @@ func (*KeyBinding) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool) values[i] = new(sql.NullBool)
case keybinding.FieldID: case keybinding.FieldID:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case keybinding.FieldCreatedAt, keybinding.FieldUpdatedAt, keybinding.FieldDeletedAt, keybinding.FieldKey, keybinding.FieldCommand, keybinding.FieldExtension: case keybinding.FieldUUID, keybinding.FieldCreatedAt, keybinding.FieldUpdatedAt, keybinding.FieldDeletedAt, keybinding.FieldKey, keybinding.FieldCommand, keybinding.FieldExtension:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
default: default:
values[i] = new(sql.UnknownType) values[i] = new(sql.UnknownType)
@@ -65,6 +67,12 @@ func (_m *KeyBinding) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field id", value) return fmt.Errorf("unexpected type %T for field id", value)
} }
_m.ID = int(value.Int64) _m.ID = int(value.Int64)
case keybinding.FieldUUID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field uuid", values[i])
} else if value.Valid {
_m.UUID = value.String
}
case keybinding.FieldCreatedAt: case keybinding.FieldCreatedAt:
if value, ok := values[i].(*sql.NullString); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i]) return fmt.Errorf("unexpected type %T for field created_at", values[i])
@@ -144,6 +152,9 @@ func (_m *KeyBinding) String() string {
var builder strings.Builder var builder strings.Builder
builder.WriteString("KeyBinding(") builder.WriteString("KeyBinding(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("uuid=")
builder.WriteString(_m.UUID)
builder.WriteString(", ")
builder.WriteString("created_at=") builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt) builder.WriteString(_m.CreatedAt)
builder.WriteString(", ") builder.WriteString(", ")

View File

@@ -12,6 +12,8 @@ const (
Label = "key_binding" Label = "key_binding"
// FieldID holds the string denoting the id field in the database. // FieldID holds the string denoting the id field in the database.
FieldID = "id" FieldID = "id"
// FieldUUID holds the string denoting the uuid field in the database.
FieldUUID = "uuid"
// FieldCreatedAt holds the string denoting the created_at field in the database. // FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at" FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database. // FieldUpdatedAt holds the string denoting the updated_at field in the database.
@@ -33,6 +35,7 @@ const (
// Columns holds all SQL columns for keybinding fields. // Columns holds all SQL columns for keybinding fields.
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldUUID,
FieldCreatedAt, FieldCreatedAt,
FieldUpdatedAt, FieldUpdatedAt,
FieldDeletedAt, FieldDeletedAt,
@@ -60,6 +63,8 @@ func ValidColumn(column string) bool {
var ( var (
Hooks [2]ent.Hook Hooks [2]ent.Hook
Interceptors [1]ent.Interceptor Interceptors [1]ent.Interceptor
// DefaultUUID holds the default value on creation for the "uuid" field.
DefaultUUID func() string
// DefaultCreatedAt holds the default value on creation for the "created_at" field. // DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() string DefaultCreatedAt func() string
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field. // DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
@@ -82,6 +87,11 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc() return sql.OrderByField(FieldID, opts...).ToFunc()
} }
// ByUUID orders the results by the uuid field.
func ByUUID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUUID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field. // ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()

View File

@@ -53,6 +53,11 @@ func IDLTE(id int) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldLTE(FieldID, id)) return predicate.KeyBinding(sql.FieldLTE(FieldID, id))
} }
// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ.
func UUID(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldEQ(FieldUUID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v string) predicate.KeyBinding { func CreatedAt(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldEQ(FieldCreatedAt, v)) return predicate.KeyBinding(sql.FieldEQ(FieldCreatedAt, v))
@@ -88,6 +93,81 @@ func Enabled(v bool) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldEQ(FieldEnabled, v)) return predicate.KeyBinding(sql.FieldEQ(FieldEnabled, v))
} }
// UUIDEQ applies the EQ predicate on the "uuid" field.
func UUIDEQ(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldEQ(FieldUUID, v))
}
// UUIDNEQ applies the NEQ predicate on the "uuid" field.
func UUIDNEQ(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldNEQ(FieldUUID, v))
}
// UUIDIn applies the In predicate on the "uuid" field.
func UUIDIn(vs ...string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldIn(FieldUUID, vs...))
}
// UUIDNotIn applies the NotIn predicate on the "uuid" field.
func UUIDNotIn(vs ...string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldNotIn(FieldUUID, vs...))
}
// UUIDGT applies the GT predicate on the "uuid" field.
func UUIDGT(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldGT(FieldUUID, v))
}
// UUIDGTE applies the GTE predicate on the "uuid" field.
func UUIDGTE(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldGTE(FieldUUID, v))
}
// UUIDLT applies the LT predicate on the "uuid" field.
func UUIDLT(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldLT(FieldUUID, v))
}
// UUIDLTE applies the LTE predicate on the "uuid" field.
func UUIDLTE(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldLTE(FieldUUID, v))
}
// UUIDContains applies the Contains predicate on the "uuid" field.
func UUIDContains(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldContains(FieldUUID, v))
}
// UUIDHasPrefix applies the HasPrefix predicate on the "uuid" field.
func UUIDHasPrefix(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldHasPrefix(FieldUUID, v))
}
// UUIDHasSuffix applies the HasSuffix predicate on the "uuid" field.
func UUIDHasSuffix(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldHasSuffix(FieldUUID, v))
}
// UUIDIsNil applies the IsNil predicate on the "uuid" field.
func UUIDIsNil() predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldIsNull(FieldUUID))
}
// UUIDNotNil applies the NotNil predicate on the "uuid" field.
func UUIDNotNil() predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldNotNull(FieldUUID))
}
// UUIDEqualFold applies the EqualFold predicate on the "uuid" field.
func UUIDEqualFold(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldEqualFold(FieldUUID, v))
}
// UUIDContainsFold applies the ContainsFold predicate on the "uuid" field.
func UUIDContainsFold(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldContainsFold(FieldUUID, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field. // CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v string) predicate.KeyBinding { func CreatedAtEQ(v string) predicate.KeyBinding {
return predicate.KeyBinding(sql.FieldEQ(FieldCreatedAt, v)) return predicate.KeyBinding(sql.FieldEQ(FieldCreatedAt, v))

View File

@@ -19,6 +19,20 @@ type KeyBindingCreate struct {
hooks []Hook hooks []Hook
} }
// SetUUID sets the "uuid" field.
func (_c *KeyBindingCreate) SetUUID(v string) *KeyBindingCreate {
_c.mutation.SetUUID(v)
return _c
}
// SetNillableUUID sets the "uuid" field if the given value is not nil.
func (_c *KeyBindingCreate) SetNillableUUID(v *string) *KeyBindingCreate {
if v != nil {
_c.SetUUID(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (_c *KeyBindingCreate) SetCreatedAt(v string) *KeyBindingCreate { func (_c *KeyBindingCreate) SetCreatedAt(v string) *KeyBindingCreate {
_c.mutation.SetCreatedAt(v) _c.mutation.SetCreatedAt(v)
@@ -138,6 +152,13 @@ func (_c *KeyBindingCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save. // defaults sets the default values of the builder before save.
func (_c *KeyBindingCreate) defaults() error { func (_c *KeyBindingCreate) defaults() error {
if _, ok := _c.mutation.UUID(); !ok {
if keybinding.DefaultUUID == nil {
return fmt.Errorf("ent: uninitialized keybinding.DefaultUUID (forgotten import ent/runtime?)")
}
v := keybinding.DefaultUUID()
_c.mutation.SetUUID(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok { if _, ok := _c.mutation.CreatedAt(); !ok {
if keybinding.DefaultCreatedAt == nil { if keybinding.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized keybinding.DefaultCreatedAt (forgotten import ent/runtime?)") return fmt.Errorf("ent: uninitialized keybinding.DefaultCreatedAt (forgotten import ent/runtime?)")
@@ -217,6 +238,10 @@ func (_c *KeyBindingCreate) createSpec() (*KeyBinding, *sqlgraph.CreateSpec) {
_node = &KeyBinding{config: _c.config} _node = &KeyBinding{config: _c.config}
_spec = sqlgraph.NewCreateSpec(keybinding.Table, sqlgraph.NewFieldSpec(keybinding.FieldID, field.TypeInt)) _spec = sqlgraph.NewCreateSpec(keybinding.Table, sqlgraph.NewFieldSpec(keybinding.FieldID, field.TypeInt))
) )
if value, ok := _c.mutation.UUID(); ok {
_spec.SetField(keybinding.FieldUUID, field.TypeString, value)
_node.UUID = value
}
if value, ok := _c.mutation.CreatedAt(); ok { if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(keybinding.FieldCreatedAt, field.TypeString, value) _spec.SetField(keybinding.FieldCreatedAt, field.TypeString, value)
_node.CreatedAt = value _node.CreatedAt = value

View File

@@ -265,12 +265,12 @@ func (_q *KeyBindingQuery) Clone() *KeyBindingQuery {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// CreatedAt string `json:"created_at"` // UUID string `json:"uuid"`
// Count int `json:"count,omitempty"` // Count int `json:"count,omitempty"`
// } // }
// //
// client.KeyBinding.Query(). // client.KeyBinding.Query().
// GroupBy(keybinding.FieldCreatedAt). // GroupBy(keybinding.FieldUUID).
// Aggregate(ent.Count()). // Aggregate(ent.Count()).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *KeyBindingQuery) GroupBy(field string, fields ...string) *KeyBindingGroupBy { func (_q *KeyBindingQuery) GroupBy(field string, fields ...string) *KeyBindingGroupBy {
@@ -288,11 +288,11 @@ func (_q *KeyBindingQuery) GroupBy(field string, fields ...string) *KeyBindingGr
// Example: // Example:
// //
// var v []struct { // var v []struct {
// CreatedAt string `json:"created_at"` // UUID string `json:"uuid"`
// } // }
// //
// client.KeyBinding.Query(). // client.KeyBinding.Query().
// Select(keybinding.FieldCreatedAt). // Select(keybinding.FieldUUID).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *KeyBindingQuery) Select(fields ...string) *KeyBindingSelect { func (_q *KeyBindingQuery) Select(fields ...string) *KeyBindingSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...) _q.ctx.Fields = append(_q.ctx.Fields, fields...)

View File

@@ -194,6 +194,9 @@ func (_u *KeyBindingUpdate) sqlSave(ctx context.Context) (_node int, err error)
} }
} }
} }
if _u.mutation.UUIDCleared() {
_spec.ClearField(keybinding.FieldUUID, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok { if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(keybinding.FieldUpdatedAt, field.TypeString, value) _spec.SetField(keybinding.FieldUpdatedAt, field.TypeString, value)
} }
@@ -436,6 +439,9 @@ func (_u *KeyBindingUpdateOne) sqlSave(ctx context.Context) (_node *KeyBinding,
} }
} }
} }
if _u.mutation.UUIDCleared() {
_spec.ClearField(keybinding.FieldUUID, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok { if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(keybinding.FieldUpdatedAt, field.TypeString, value) _spec.SetField(keybinding.FieldUpdatedAt, field.TypeString, value)
} }

View File

@@ -12,6 +12,7 @@ var (
// DocumentsColumns holds the columns for the "documents" table. // DocumentsColumns holds the columns for the "documents" table.
DocumentsColumns = []*schema.Column{ DocumentsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "uuid", Type: field.TypeString, Unique: true, Nullable: true},
{Name: "created_at", Type: field.TypeString}, {Name: "created_at", Type: field.TypeString},
{Name: "updated_at", Type: field.TypeString}, {Name: "updated_at", Type: field.TypeString},
{Name: "deleted_at", Type: field.TypeString, Nullable: true}, {Name: "deleted_at", Type: field.TypeString, Nullable: true},
@@ -26,30 +27,36 @@ var (
PrimaryKey: []*schema.Column{DocumentsColumns[0]}, PrimaryKey: []*schema.Column{DocumentsColumns[0]},
Indexes: []*schema.Index{ Indexes: []*schema.Index{
{ {
Name: "document_deleted_at", Name: "document_uuid",
Unique: false,
Columns: []*schema.Column{DocumentsColumns[3]},
},
{
Name: "document_title",
Unique: false,
Columns: []*schema.Column{DocumentsColumns[4]},
},
{
Name: "document_created_at",
Unique: false, Unique: false,
Columns: []*schema.Column{DocumentsColumns[1]}, Columns: []*schema.Column{DocumentsColumns[1]},
}, },
{ {
Name: "document_updated_at", Name: "document_deleted_at",
Unique: false,
Columns: []*schema.Column{DocumentsColumns[4]},
},
{
Name: "document_title",
Unique: false,
Columns: []*schema.Column{DocumentsColumns[5]},
},
{
Name: "document_created_at",
Unique: false, Unique: false,
Columns: []*schema.Column{DocumentsColumns[2]}, Columns: []*schema.Column{DocumentsColumns[2]},
}, },
{
Name: "document_updated_at",
Unique: false,
Columns: []*schema.Column{DocumentsColumns[3]},
},
}, },
} }
// ExtensionsColumns holds the columns for the "extensions" table. // ExtensionsColumns holds the columns for the "extensions" table.
ExtensionsColumns = []*schema.Column{ ExtensionsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "uuid", Type: field.TypeString, Unique: true, Nullable: true},
{Name: "created_at", Type: field.TypeString}, {Name: "created_at", Type: field.TypeString},
{Name: "updated_at", Type: field.TypeString}, {Name: "updated_at", Type: field.TypeString},
{Name: "deleted_at", Type: field.TypeString, Nullable: true}, {Name: "deleted_at", Type: field.TypeString, Nullable: true},
@@ -63,21 +70,27 @@ var (
Columns: ExtensionsColumns, Columns: ExtensionsColumns,
PrimaryKey: []*schema.Column{ExtensionsColumns[0]}, PrimaryKey: []*schema.Column{ExtensionsColumns[0]},
Indexes: []*schema.Index{ Indexes: []*schema.Index{
{
Name: "extension_uuid",
Unique: false,
Columns: []*schema.Column{ExtensionsColumns[1]},
},
{ {
Name: "extension_deleted_at", Name: "extension_deleted_at",
Unique: false, Unique: false,
Columns: []*schema.Column{ExtensionsColumns[3]}, Columns: []*schema.Column{ExtensionsColumns[4]},
}, },
{ {
Name: "extension_enabled", Name: "extension_enabled",
Unique: false, Unique: false,
Columns: []*schema.Column{ExtensionsColumns[5]}, Columns: []*schema.Column{ExtensionsColumns[6]},
}, },
}, },
} }
// KeyBindingsColumns holds the columns for the "key_bindings" table. // KeyBindingsColumns holds the columns for the "key_bindings" table.
KeyBindingsColumns = []*schema.Column{ KeyBindingsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "uuid", Type: field.TypeString, Unique: true, Nullable: true},
{Name: "created_at", Type: field.TypeString}, {Name: "created_at", Type: field.TypeString},
{Name: "updated_at", Type: field.TypeString}, {Name: "updated_at", Type: field.TypeString},
{Name: "deleted_at", Type: field.TypeString, Nullable: true}, {Name: "deleted_at", Type: field.TypeString, Nullable: true},
@@ -92,26 +105,32 @@ var (
Columns: KeyBindingsColumns, Columns: KeyBindingsColumns,
PrimaryKey: []*schema.Column{KeyBindingsColumns[0]}, PrimaryKey: []*schema.Column{KeyBindingsColumns[0]},
Indexes: []*schema.Index{ Indexes: []*schema.Index{
{
Name: "keybinding_uuid",
Unique: false,
Columns: []*schema.Column{KeyBindingsColumns[1]},
},
{ {
Name: "keybinding_deleted_at", Name: "keybinding_deleted_at",
Unique: false, Unique: false,
Columns: []*schema.Column{KeyBindingsColumns[3]}, Columns: []*schema.Column{KeyBindingsColumns[4]},
}, },
{ {
Name: "keybinding_extension", Name: "keybinding_extension",
Unique: false, Unique: false,
Columns: []*schema.Column{KeyBindingsColumns[6]}, Columns: []*schema.Column{KeyBindingsColumns[7]},
}, },
{ {
Name: "keybinding_enabled", Name: "keybinding_enabled",
Unique: false, Unique: false,
Columns: []*schema.Column{KeyBindingsColumns[7]}, Columns: []*schema.Column{KeyBindingsColumns[8]},
}, },
}, },
} }
// ThemesColumns holds the columns for the "themes" table. // ThemesColumns holds the columns for the "themes" table.
ThemesColumns = []*schema.Column{ ThemesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "uuid", Type: field.TypeString, Unique: true, Nullable: true},
{Name: "created_at", Type: field.TypeString}, {Name: "created_at", Type: field.TypeString},
{Name: "updated_at", Type: field.TypeString}, {Name: "updated_at", Type: field.TypeString},
{Name: "deleted_at", Type: field.TypeString, Nullable: true}, {Name: "deleted_at", Type: field.TypeString, Nullable: true},
@@ -125,10 +144,15 @@ var (
Columns: ThemesColumns, Columns: ThemesColumns,
PrimaryKey: []*schema.Column{ThemesColumns[0]}, PrimaryKey: []*schema.Column{ThemesColumns[0]},
Indexes: []*schema.Index{ Indexes: []*schema.Index{
{
Name: "theme_uuid",
Unique: false,
Columns: []*schema.Column{ThemesColumns[1]},
},
{ {
Name: "theme_deleted_at", Name: "theme_deleted_at",
Unique: false, Unique: false,
Columns: []*schema.Column{ThemesColumns[3]}, Columns: []*schema.Column{ThemesColumns[4]},
}, },
}, },
} }

View File

@@ -38,6 +38,7 @@ type DocumentMutation struct {
op Op op Op
typ string typ string
id *int id *int
uuid *string
created_at *string created_at *string
updated_at *string updated_at *string
deleted_at *string deleted_at *string
@@ -148,6 +149,55 @@ func (m *DocumentMutation) IDs(ctx context.Context) ([]int, error) {
} }
} }
// SetUUID sets the "uuid" field.
func (m *DocumentMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *DocumentMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the Document entity.
// If the Document object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DocumentMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ClearUUID clears the value of the "uuid" field.
func (m *DocumentMutation) ClearUUID() {
m.uuid = nil
m.clearedFields[document.FieldUUID] = struct{}{}
}
// UUIDCleared returns if the "uuid" field was cleared in this mutation.
func (m *DocumentMutation) UUIDCleared() bool {
_, ok := m.clearedFields[document.FieldUUID]
return ok
}
// ResetUUID resets all changes to the "uuid" field.
func (m *DocumentMutation) ResetUUID() {
m.uuid = nil
delete(m.clearedFields, document.FieldUUID)
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (m *DocumentMutation) SetCreatedAt(s string) { func (m *DocumentMutation) SetCreatedAt(s string) {
m.created_at = &s m.created_at = &s
@@ -424,7 +474,10 @@ func (m *DocumentMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *DocumentMutation) Fields() []string { func (m *DocumentMutation) Fields() []string {
fields := make([]string, 0, 6) fields := make([]string, 0, 7)
if m.uuid != nil {
fields = append(fields, document.FieldUUID)
}
if m.created_at != nil { if m.created_at != nil {
fields = append(fields, document.FieldCreatedAt) fields = append(fields, document.FieldCreatedAt)
} }
@@ -451,6 +504,8 @@ func (m *DocumentMutation) Fields() []string {
// schema. // schema.
func (m *DocumentMutation) Field(name string) (ent.Value, bool) { func (m *DocumentMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case document.FieldUUID:
return m.UUID()
case document.FieldCreatedAt: case document.FieldCreatedAt:
return m.CreatedAt() return m.CreatedAt()
case document.FieldUpdatedAt: case document.FieldUpdatedAt:
@@ -472,6 +527,8 @@ func (m *DocumentMutation) Field(name string) (ent.Value, bool) {
// database failed. // database failed.
func (m *DocumentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { func (m *DocumentMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name { switch name {
case document.FieldUUID:
return m.OldUUID(ctx)
case document.FieldCreatedAt: case document.FieldCreatedAt:
return m.OldCreatedAt(ctx) return m.OldCreatedAt(ctx)
case document.FieldUpdatedAt: case document.FieldUpdatedAt:
@@ -493,6 +550,13 @@ func (m *DocumentMutation) OldField(ctx context.Context, name string) (ent.Value
// type. // type.
func (m *DocumentMutation) SetField(name string, value ent.Value) error { func (m *DocumentMutation) SetField(name string, value ent.Value) error {
switch name { switch name {
case document.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
case document.FieldCreatedAt: case document.FieldCreatedAt:
v, ok := value.(string) v, ok := value.(string)
if !ok { if !ok {
@@ -565,6 +629,9 @@ func (m *DocumentMutation) AddField(name string, value ent.Value) error {
// mutation. // mutation.
func (m *DocumentMutation) ClearedFields() []string { func (m *DocumentMutation) ClearedFields() []string {
var fields []string var fields []string
if m.FieldCleared(document.FieldUUID) {
fields = append(fields, document.FieldUUID)
}
if m.FieldCleared(document.FieldDeletedAt) { if m.FieldCleared(document.FieldDeletedAt) {
fields = append(fields, document.FieldDeletedAt) fields = append(fields, document.FieldDeletedAt)
} }
@@ -585,6 +652,9 @@ func (m *DocumentMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema. // error if the field is not defined in the schema.
func (m *DocumentMutation) ClearField(name string) error { func (m *DocumentMutation) ClearField(name string) error {
switch name { switch name {
case document.FieldUUID:
m.ClearUUID()
return nil
case document.FieldDeletedAt: case document.FieldDeletedAt:
m.ClearDeletedAt() m.ClearDeletedAt()
return nil return nil
@@ -599,6 +669,9 @@ func (m *DocumentMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema. // It returns an error if the field is not defined in the schema.
func (m *DocumentMutation) ResetField(name string) error { func (m *DocumentMutation) ResetField(name string) error {
switch name { switch name {
case document.FieldUUID:
m.ResetUUID()
return nil
case document.FieldCreatedAt: case document.FieldCreatedAt:
m.ResetCreatedAt() m.ResetCreatedAt()
return nil return nil
@@ -675,6 +748,7 @@ type ExtensionMutation struct {
op Op op Op
typ string typ string
id *int id *int
uuid *string
created_at *string created_at *string
updated_at *string updated_at *string
deleted_at *string deleted_at *string
@@ -785,6 +859,55 @@ func (m *ExtensionMutation) IDs(ctx context.Context) ([]int, error) {
} }
} }
// SetUUID sets the "uuid" field.
func (m *ExtensionMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *ExtensionMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the Extension entity.
// If the Extension object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ExtensionMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ClearUUID clears the value of the "uuid" field.
func (m *ExtensionMutation) ClearUUID() {
m.uuid = nil
m.clearedFields[extension.FieldUUID] = struct{}{}
}
// UUIDCleared returns if the "uuid" field was cleared in this mutation.
func (m *ExtensionMutation) UUIDCleared() bool {
_, ok := m.clearedFields[extension.FieldUUID]
return ok
}
// ResetUUID resets all changes to the "uuid" field.
func (m *ExtensionMutation) ResetUUID() {
m.uuid = nil
delete(m.clearedFields, extension.FieldUUID)
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (m *ExtensionMutation) SetCreatedAt(s string) { func (m *ExtensionMutation) SetCreatedAt(s string) {
m.created_at = &s m.created_at = &s
@@ -1061,7 +1184,10 @@ func (m *ExtensionMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *ExtensionMutation) Fields() []string { func (m *ExtensionMutation) Fields() []string {
fields := make([]string, 0, 6) fields := make([]string, 0, 7)
if m.uuid != nil {
fields = append(fields, extension.FieldUUID)
}
if m.created_at != nil { if m.created_at != nil {
fields = append(fields, extension.FieldCreatedAt) fields = append(fields, extension.FieldCreatedAt)
} }
@@ -1088,6 +1214,8 @@ func (m *ExtensionMutation) Fields() []string {
// schema. // schema.
func (m *ExtensionMutation) Field(name string) (ent.Value, bool) { func (m *ExtensionMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case extension.FieldUUID:
return m.UUID()
case extension.FieldCreatedAt: case extension.FieldCreatedAt:
return m.CreatedAt() return m.CreatedAt()
case extension.FieldUpdatedAt: case extension.FieldUpdatedAt:
@@ -1109,6 +1237,8 @@ func (m *ExtensionMutation) Field(name string) (ent.Value, bool) {
// database failed. // database failed.
func (m *ExtensionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { func (m *ExtensionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name { switch name {
case extension.FieldUUID:
return m.OldUUID(ctx)
case extension.FieldCreatedAt: case extension.FieldCreatedAt:
return m.OldCreatedAt(ctx) return m.OldCreatedAt(ctx)
case extension.FieldUpdatedAt: case extension.FieldUpdatedAt:
@@ -1130,6 +1260,13 @@ func (m *ExtensionMutation) OldField(ctx context.Context, name string) (ent.Valu
// type. // type.
func (m *ExtensionMutation) SetField(name string, value ent.Value) error { func (m *ExtensionMutation) SetField(name string, value ent.Value) error {
switch name { switch name {
case extension.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
case extension.FieldCreatedAt: case extension.FieldCreatedAt:
v, ok := value.(string) v, ok := value.(string)
if !ok { if !ok {
@@ -1202,6 +1339,9 @@ func (m *ExtensionMutation) AddField(name string, value ent.Value) error {
// mutation. // mutation.
func (m *ExtensionMutation) ClearedFields() []string { func (m *ExtensionMutation) ClearedFields() []string {
var fields []string var fields []string
if m.FieldCleared(extension.FieldUUID) {
fields = append(fields, extension.FieldUUID)
}
if m.FieldCleared(extension.FieldDeletedAt) { if m.FieldCleared(extension.FieldDeletedAt) {
fields = append(fields, extension.FieldDeletedAt) fields = append(fields, extension.FieldDeletedAt)
} }
@@ -1222,6 +1362,9 @@ func (m *ExtensionMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema. // error if the field is not defined in the schema.
func (m *ExtensionMutation) ClearField(name string) error { func (m *ExtensionMutation) ClearField(name string) error {
switch name { switch name {
case extension.FieldUUID:
m.ClearUUID()
return nil
case extension.FieldDeletedAt: case extension.FieldDeletedAt:
m.ClearDeletedAt() m.ClearDeletedAt()
return nil return nil
@@ -1236,6 +1379,9 @@ func (m *ExtensionMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema. // It returns an error if the field is not defined in the schema.
func (m *ExtensionMutation) ResetField(name string) error { func (m *ExtensionMutation) ResetField(name string) error {
switch name { switch name {
case extension.FieldUUID:
m.ResetUUID()
return nil
case extension.FieldCreatedAt: case extension.FieldCreatedAt:
m.ResetCreatedAt() m.ResetCreatedAt()
return nil return nil
@@ -1312,6 +1458,7 @@ type KeyBindingMutation struct {
op Op op Op
typ string typ string
id *int id *int
uuid *string
created_at *string created_at *string
updated_at *string updated_at *string
deleted_at *string deleted_at *string
@@ -1423,6 +1570,55 @@ func (m *KeyBindingMutation) IDs(ctx context.Context) ([]int, error) {
} }
} }
// SetUUID sets the "uuid" field.
func (m *KeyBindingMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *KeyBindingMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the KeyBinding entity.
// If the KeyBinding object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *KeyBindingMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ClearUUID clears the value of the "uuid" field.
func (m *KeyBindingMutation) ClearUUID() {
m.uuid = nil
m.clearedFields[keybinding.FieldUUID] = struct{}{}
}
// UUIDCleared returns if the "uuid" field was cleared in this mutation.
func (m *KeyBindingMutation) UUIDCleared() bool {
_, ok := m.clearedFields[keybinding.FieldUUID]
return ok
}
// ResetUUID resets all changes to the "uuid" field.
func (m *KeyBindingMutation) ResetUUID() {
m.uuid = nil
delete(m.clearedFields, keybinding.FieldUUID)
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (m *KeyBindingMutation) SetCreatedAt(s string) { func (m *KeyBindingMutation) SetCreatedAt(s string) {
m.created_at = &s m.created_at = &s
@@ -1735,7 +1931,10 @@ func (m *KeyBindingMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *KeyBindingMutation) Fields() []string { func (m *KeyBindingMutation) Fields() []string {
fields := make([]string, 0, 7) fields := make([]string, 0, 8)
if m.uuid != nil {
fields = append(fields, keybinding.FieldUUID)
}
if m.created_at != nil { if m.created_at != nil {
fields = append(fields, keybinding.FieldCreatedAt) fields = append(fields, keybinding.FieldCreatedAt)
} }
@@ -1765,6 +1964,8 @@ func (m *KeyBindingMutation) Fields() []string {
// schema. // schema.
func (m *KeyBindingMutation) Field(name string) (ent.Value, bool) { func (m *KeyBindingMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case keybinding.FieldUUID:
return m.UUID()
case keybinding.FieldCreatedAt: case keybinding.FieldCreatedAt:
return m.CreatedAt() return m.CreatedAt()
case keybinding.FieldUpdatedAt: case keybinding.FieldUpdatedAt:
@@ -1788,6 +1989,8 @@ func (m *KeyBindingMutation) Field(name string) (ent.Value, bool) {
// database failed. // database failed.
func (m *KeyBindingMutation) OldField(ctx context.Context, name string) (ent.Value, error) { func (m *KeyBindingMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name { switch name {
case keybinding.FieldUUID:
return m.OldUUID(ctx)
case keybinding.FieldCreatedAt: case keybinding.FieldCreatedAt:
return m.OldCreatedAt(ctx) return m.OldCreatedAt(ctx)
case keybinding.FieldUpdatedAt: case keybinding.FieldUpdatedAt:
@@ -1811,6 +2014,13 @@ func (m *KeyBindingMutation) OldField(ctx context.Context, name string) (ent.Val
// type. // type.
func (m *KeyBindingMutation) SetField(name string, value ent.Value) error { func (m *KeyBindingMutation) SetField(name string, value ent.Value) error {
switch name { switch name {
case keybinding.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
case keybinding.FieldCreatedAt: case keybinding.FieldCreatedAt:
v, ok := value.(string) v, ok := value.(string)
if !ok { if !ok {
@@ -1890,6 +2100,9 @@ func (m *KeyBindingMutation) AddField(name string, value ent.Value) error {
// mutation. // mutation.
func (m *KeyBindingMutation) ClearedFields() []string { func (m *KeyBindingMutation) ClearedFields() []string {
var fields []string var fields []string
if m.FieldCleared(keybinding.FieldUUID) {
fields = append(fields, keybinding.FieldUUID)
}
if m.FieldCleared(keybinding.FieldDeletedAt) { if m.FieldCleared(keybinding.FieldDeletedAt) {
fields = append(fields, keybinding.FieldDeletedAt) fields = append(fields, keybinding.FieldDeletedAt)
} }
@@ -1910,6 +2123,9 @@ func (m *KeyBindingMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema. // error if the field is not defined in the schema.
func (m *KeyBindingMutation) ClearField(name string) error { func (m *KeyBindingMutation) ClearField(name string) error {
switch name { switch name {
case keybinding.FieldUUID:
m.ClearUUID()
return nil
case keybinding.FieldDeletedAt: case keybinding.FieldDeletedAt:
m.ClearDeletedAt() m.ClearDeletedAt()
return nil return nil
@@ -1924,6 +2140,9 @@ func (m *KeyBindingMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema. // It returns an error if the field is not defined in the schema.
func (m *KeyBindingMutation) ResetField(name string) error { func (m *KeyBindingMutation) ResetField(name string) error {
switch name { switch name {
case keybinding.FieldUUID:
m.ResetUUID()
return nil
case keybinding.FieldCreatedAt: case keybinding.FieldCreatedAt:
m.ResetCreatedAt() m.ResetCreatedAt()
return nil return nil
@@ -2003,6 +2222,7 @@ type ThemeMutation struct {
op Op op Op
typ string typ string
id *int id *int
uuid *string
created_at *string created_at *string
updated_at *string updated_at *string
deleted_at *string deleted_at *string
@@ -2113,6 +2333,55 @@ func (m *ThemeMutation) IDs(ctx context.Context) ([]int, error) {
} }
} }
// SetUUID sets the "uuid" field.
func (m *ThemeMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *ThemeMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the Theme entity.
// If the Theme object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ThemeMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ClearUUID clears the value of the "uuid" field.
func (m *ThemeMutation) ClearUUID() {
m.uuid = nil
m.clearedFields[theme.FieldUUID] = struct{}{}
}
// UUIDCleared returns if the "uuid" field was cleared in this mutation.
func (m *ThemeMutation) UUIDCleared() bool {
_, ok := m.clearedFields[theme.FieldUUID]
return ok
}
// ResetUUID resets all changes to the "uuid" field.
func (m *ThemeMutation) ResetUUID() {
m.uuid = nil
delete(m.clearedFields, theme.FieldUUID)
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (m *ThemeMutation) SetCreatedAt(s string) { func (m *ThemeMutation) SetCreatedAt(s string) {
m.created_at = &s m.created_at = &s
@@ -2389,7 +2658,10 @@ func (m *ThemeMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *ThemeMutation) Fields() []string { func (m *ThemeMutation) Fields() []string {
fields := make([]string, 0, 6) fields := make([]string, 0, 7)
if m.uuid != nil {
fields = append(fields, theme.FieldUUID)
}
if m.created_at != nil { if m.created_at != nil {
fields = append(fields, theme.FieldCreatedAt) fields = append(fields, theme.FieldCreatedAt)
} }
@@ -2416,6 +2688,8 @@ func (m *ThemeMutation) Fields() []string {
// schema. // schema.
func (m *ThemeMutation) Field(name string) (ent.Value, bool) { func (m *ThemeMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case theme.FieldUUID:
return m.UUID()
case theme.FieldCreatedAt: case theme.FieldCreatedAt:
return m.CreatedAt() return m.CreatedAt()
case theme.FieldUpdatedAt: case theme.FieldUpdatedAt:
@@ -2437,6 +2711,8 @@ func (m *ThemeMutation) Field(name string) (ent.Value, bool) {
// database failed. // database failed.
func (m *ThemeMutation) OldField(ctx context.Context, name string) (ent.Value, error) { func (m *ThemeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name { switch name {
case theme.FieldUUID:
return m.OldUUID(ctx)
case theme.FieldCreatedAt: case theme.FieldCreatedAt:
return m.OldCreatedAt(ctx) return m.OldCreatedAt(ctx)
case theme.FieldUpdatedAt: case theme.FieldUpdatedAt:
@@ -2458,6 +2734,13 @@ func (m *ThemeMutation) OldField(ctx context.Context, name string) (ent.Value, e
// type. // type.
func (m *ThemeMutation) SetField(name string, value ent.Value) error { func (m *ThemeMutation) SetField(name string, value ent.Value) error {
switch name { switch name {
case theme.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
case theme.FieldCreatedAt: case theme.FieldCreatedAt:
v, ok := value.(string) v, ok := value.(string)
if !ok { if !ok {
@@ -2530,6 +2813,9 @@ func (m *ThemeMutation) AddField(name string, value ent.Value) error {
// mutation. // mutation.
func (m *ThemeMutation) ClearedFields() []string { func (m *ThemeMutation) ClearedFields() []string {
var fields []string var fields []string
if m.FieldCleared(theme.FieldUUID) {
fields = append(fields, theme.FieldUUID)
}
if m.FieldCleared(theme.FieldDeletedAt) { if m.FieldCleared(theme.FieldDeletedAt) {
fields = append(fields, theme.FieldDeletedAt) fields = append(fields, theme.FieldDeletedAt)
} }
@@ -2550,6 +2836,9 @@ func (m *ThemeMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema. // error if the field is not defined in the schema.
func (m *ThemeMutation) ClearField(name string) error { func (m *ThemeMutation) ClearField(name string) error {
switch name { switch name {
case theme.FieldUUID:
m.ClearUUID()
return nil
case theme.FieldDeletedAt: case theme.FieldDeletedAt:
m.ClearDeletedAt() m.ClearDeletedAt()
return nil return nil
@@ -2564,6 +2853,9 @@ func (m *ThemeMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema. // It returns an error if the field is not defined in the schema.
func (m *ThemeMutation) ResetField(name string) error { func (m *ThemeMutation) ResetField(name string) error {
switch name { switch name {
case theme.FieldUUID:
m.ResetUUID()
return nil
case theme.FieldCreatedAt: case theme.FieldCreatedAt:
m.ResetCreatedAt() m.ResetCreatedAt()
return nil return nil

View File

@@ -15,22 +15,28 @@ import (
// to their package variables. // to their package variables.
func init() { func init() {
documentMixin := schema.Document{}.Mixin() documentMixin := schema.Document{}.Mixin()
documentMixinHooks0 := documentMixin[0].Hooks()
documentMixinHooks1 := documentMixin[1].Hooks() documentMixinHooks1 := documentMixin[1].Hooks()
document.Hooks[0] = documentMixinHooks0[0] documentMixinHooks2 := documentMixin[2].Hooks()
document.Hooks[1] = documentMixinHooks1[0] document.Hooks[0] = documentMixinHooks1[0]
documentMixinInters1 := documentMixin[1].Interceptors() document.Hooks[1] = documentMixinHooks2[0]
document.Interceptors[0] = documentMixinInters1[0] documentMixinInters2 := documentMixin[2].Interceptors()
document.Interceptors[0] = documentMixinInters2[0]
documentMixinFields0 := documentMixin[0].Fields() documentMixinFields0 := documentMixin[0].Fields()
_ = documentMixinFields0 _ = documentMixinFields0
documentMixinFields1 := documentMixin[1].Fields()
_ = documentMixinFields1
documentFields := schema.Document{}.Fields() documentFields := schema.Document{}.Fields()
_ = documentFields _ = documentFields
// documentDescUUID is the schema descriptor for uuid field.
documentDescUUID := documentMixinFields0[0].Descriptor()
// document.DefaultUUID holds the default value on creation for the uuid field.
document.DefaultUUID = documentDescUUID.Default.(func() string)
// documentDescCreatedAt is the schema descriptor for created_at field. // documentDescCreatedAt is the schema descriptor for created_at field.
documentDescCreatedAt := documentMixinFields0[0].Descriptor() documentDescCreatedAt := documentMixinFields1[0].Descriptor()
// document.DefaultCreatedAt holds the default value on creation for the created_at field. // document.DefaultCreatedAt holds the default value on creation for the created_at field.
document.DefaultCreatedAt = documentDescCreatedAt.Default.(func() string) document.DefaultCreatedAt = documentDescCreatedAt.Default.(func() string)
// documentDescUpdatedAt is the schema descriptor for updated_at field. // documentDescUpdatedAt is the schema descriptor for updated_at field.
documentDescUpdatedAt := documentMixinFields0[1].Descriptor() documentDescUpdatedAt := documentMixinFields1[1].Descriptor()
// document.DefaultUpdatedAt holds the default value on creation for the updated_at field. // document.DefaultUpdatedAt holds the default value on creation for the updated_at field.
document.DefaultUpdatedAt = documentDescUpdatedAt.Default.(func() string) document.DefaultUpdatedAt = documentDescUpdatedAt.Default.(func() string)
// documentDescTitle is the schema descriptor for title field. // documentDescTitle is the schema descriptor for title field.
@@ -60,22 +66,28 @@ func init() {
// document.DefaultLocked holds the default value on creation for the locked field. // document.DefaultLocked holds the default value on creation for the locked field.
document.DefaultLocked = documentDescLocked.Default.(bool) document.DefaultLocked = documentDescLocked.Default.(bool)
extensionMixin := schema.Extension{}.Mixin() extensionMixin := schema.Extension{}.Mixin()
extensionMixinHooks0 := extensionMixin[0].Hooks()
extensionMixinHooks1 := extensionMixin[1].Hooks() extensionMixinHooks1 := extensionMixin[1].Hooks()
extension.Hooks[0] = extensionMixinHooks0[0] extensionMixinHooks2 := extensionMixin[2].Hooks()
extension.Hooks[1] = extensionMixinHooks1[0] extension.Hooks[0] = extensionMixinHooks1[0]
extensionMixinInters1 := extensionMixin[1].Interceptors() extension.Hooks[1] = extensionMixinHooks2[0]
extension.Interceptors[0] = extensionMixinInters1[0] extensionMixinInters2 := extensionMixin[2].Interceptors()
extension.Interceptors[0] = extensionMixinInters2[0]
extensionMixinFields0 := extensionMixin[0].Fields() extensionMixinFields0 := extensionMixin[0].Fields()
_ = extensionMixinFields0 _ = extensionMixinFields0
extensionMixinFields1 := extensionMixin[1].Fields()
_ = extensionMixinFields1
extensionFields := schema.Extension{}.Fields() extensionFields := schema.Extension{}.Fields()
_ = extensionFields _ = extensionFields
// extensionDescUUID is the schema descriptor for uuid field.
extensionDescUUID := extensionMixinFields0[0].Descriptor()
// extension.DefaultUUID holds the default value on creation for the uuid field.
extension.DefaultUUID = extensionDescUUID.Default.(func() string)
// extensionDescCreatedAt is the schema descriptor for created_at field. // extensionDescCreatedAt is the schema descriptor for created_at field.
extensionDescCreatedAt := extensionMixinFields0[0].Descriptor() extensionDescCreatedAt := extensionMixinFields1[0].Descriptor()
// extension.DefaultCreatedAt holds the default value on creation for the created_at field. // extension.DefaultCreatedAt holds the default value on creation for the created_at field.
extension.DefaultCreatedAt = extensionDescCreatedAt.Default.(func() string) extension.DefaultCreatedAt = extensionDescCreatedAt.Default.(func() string)
// extensionDescUpdatedAt is the schema descriptor for updated_at field. // extensionDescUpdatedAt is the schema descriptor for updated_at field.
extensionDescUpdatedAt := extensionMixinFields0[1].Descriptor() extensionDescUpdatedAt := extensionMixinFields1[1].Descriptor()
// extension.DefaultUpdatedAt holds the default value on creation for the updated_at field. // extension.DefaultUpdatedAt holds the default value on creation for the updated_at field.
extension.DefaultUpdatedAt = extensionDescUpdatedAt.Default.(func() string) extension.DefaultUpdatedAt = extensionDescUpdatedAt.Default.(func() string)
// extensionDescKey is the schema descriptor for key field. // extensionDescKey is the schema descriptor for key field.
@@ -101,22 +113,28 @@ func init() {
// extension.DefaultEnabled holds the default value on creation for the enabled field. // extension.DefaultEnabled holds the default value on creation for the enabled field.
extension.DefaultEnabled = extensionDescEnabled.Default.(bool) extension.DefaultEnabled = extensionDescEnabled.Default.(bool)
keybindingMixin := schema.KeyBinding{}.Mixin() keybindingMixin := schema.KeyBinding{}.Mixin()
keybindingMixinHooks0 := keybindingMixin[0].Hooks()
keybindingMixinHooks1 := keybindingMixin[1].Hooks() keybindingMixinHooks1 := keybindingMixin[1].Hooks()
keybinding.Hooks[0] = keybindingMixinHooks0[0] keybindingMixinHooks2 := keybindingMixin[2].Hooks()
keybinding.Hooks[1] = keybindingMixinHooks1[0] keybinding.Hooks[0] = keybindingMixinHooks1[0]
keybindingMixinInters1 := keybindingMixin[1].Interceptors() keybinding.Hooks[1] = keybindingMixinHooks2[0]
keybinding.Interceptors[0] = keybindingMixinInters1[0] keybindingMixinInters2 := keybindingMixin[2].Interceptors()
keybinding.Interceptors[0] = keybindingMixinInters2[0]
keybindingMixinFields0 := keybindingMixin[0].Fields() keybindingMixinFields0 := keybindingMixin[0].Fields()
_ = keybindingMixinFields0 _ = keybindingMixinFields0
keybindingMixinFields1 := keybindingMixin[1].Fields()
_ = keybindingMixinFields1
keybindingFields := schema.KeyBinding{}.Fields() keybindingFields := schema.KeyBinding{}.Fields()
_ = keybindingFields _ = keybindingFields
// keybindingDescUUID is the schema descriptor for uuid field.
keybindingDescUUID := keybindingMixinFields0[0].Descriptor()
// keybinding.DefaultUUID holds the default value on creation for the uuid field.
keybinding.DefaultUUID = keybindingDescUUID.Default.(func() string)
// keybindingDescCreatedAt is the schema descriptor for created_at field. // keybindingDescCreatedAt is the schema descriptor for created_at field.
keybindingDescCreatedAt := keybindingMixinFields0[0].Descriptor() keybindingDescCreatedAt := keybindingMixinFields1[0].Descriptor()
// keybinding.DefaultCreatedAt holds the default value on creation for the created_at field. // keybinding.DefaultCreatedAt holds the default value on creation for the created_at field.
keybinding.DefaultCreatedAt = keybindingDescCreatedAt.Default.(func() string) keybinding.DefaultCreatedAt = keybindingDescCreatedAt.Default.(func() string)
// keybindingDescUpdatedAt is the schema descriptor for updated_at field. // keybindingDescUpdatedAt is the schema descriptor for updated_at field.
keybindingDescUpdatedAt := keybindingMixinFields0[1].Descriptor() keybindingDescUpdatedAt := keybindingMixinFields1[1].Descriptor()
// keybinding.DefaultUpdatedAt holds the default value on creation for the updated_at field. // keybinding.DefaultUpdatedAt holds the default value on creation for the updated_at field.
keybinding.DefaultUpdatedAt = keybindingDescUpdatedAt.Default.(func() string) keybinding.DefaultUpdatedAt = keybindingDescUpdatedAt.Default.(func() string)
// keybindingDescKey is the schema descriptor for key field. // keybindingDescKey is the schema descriptor for key field.
@@ -164,22 +182,28 @@ func init() {
// keybinding.DefaultEnabled holds the default value on creation for the enabled field. // keybinding.DefaultEnabled holds the default value on creation for the enabled field.
keybinding.DefaultEnabled = keybindingDescEnabled.Default.(bool) keybinding.DefaultEnabled = keybindingDescEnabled.Default.(bool)
themeMixin := schema.Theme{}.Mixin() themeMixin := schema.Theme{}.Mixin()
themeMixinHooks0 := themeMixin[0].Hooks()
themeMixinHooks1 := themeMixin[1].Hooks() themeMixinHooks1 := themeMixin[1].Hooks()
theme.Hooks[0] = themeMixinHooks0[0] themeMixinHooks2 := themeMixin[2].Hooks()
theme.Hooks[1] = themeMixinHooks1[0] theme.Hooks[0] = themeMixinHooks1[0]
themeMixinInters1 := themeMixin[1].Interceptors() theme.Hooks[1] = themeMixinHooks2[0]
theme.Interceptors[0] = themeMixinInters1[0] themeMixinInters2 := themeMixin[2].Interceptors()
theme.Interceptors[0] = themeMixinInters2[0]
themeMixinFields0 := themeMixin[0].Fields() themeMixinFields0 := themeMixin[0].Fields()
_ = themeMixinFields0 _ = themeMixinFields0
themeMixinFields1 := themeMixin[1].Fields()
_ = themeMixinFields1
themeFields := schema.Theme{}.Fields() themeFields := schema.Theme{}.Fields()
_ = themeFields _ = themeFields
// themeDescUUID is the schema descriptor for uuid field.
themeDescUUID := themeMixinFields0[0].Descriptor()
// theme.DefaultUUID holds the default value on creation for the uuid field.
theme.DefaultUUID = themeDescUUID.Default.(func() string)
// themeDescCreatedAt is the schema descriptor for created_at field. // themeDescCreatedAt is the schema descriptor for created_at field.
themeDescCreatedAt := themeMixinFields0[0].Descriptor() themeDescCreatedAt := themeMixinFields1[0].Descriptor()
// theme.DefaultCreatedAt holds the default value on creation for the created_at field. // theme.DefaultCreatedAt holds the default value on creation for the created_at field.
theme.DefaultCreatedAt = themeDescCreatedAt.Default.(func() string) theme.DefaultCreatedAt = themeDescCreatedAt.Default.(func() string)
// themeDescUpdatedAt is the schema descriptor for updated_at field. // themeDescUpdatedAt is the schema descriptor for updated_at field.
themeDescUpdatedAt := themeMixinFields0[1].Descriptor() themeDescUpdatedAt := themeMixinFields1[1].Descriptor()
// theme.DefaultUpdatedAt holds the default value on creation for the updated_at field. // theme.DefaultUpdatedAt holds the default value on creation for the updated_at field.
theme.DefaultUpdatedAt = themeDescUpdatedAt.Default.(func() string) theme.DefaultUpdatedAt = themeDescUpdatedAt.Default.(func() string)
// themeDescKey is the schema descriptor for key field. // themeDescKey is the schema descriptor for key field.

View File

@@ -17,17 +17,19 @@ type Theme struct {
config `json:"-"` config `json:"-"`
// ID of the ent. // ID of the ent.
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// 创建时间 // UUID for cross-device sync (UUIDv7)
UUID string `json:"uuid"`
// creation time
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
// 最后更新时间 // update time
UpdatedAt string `json:"updated_at"` UpdatedAt string `json:"updated_at"`
// 删除时间NULL表示未删除 // deleted at
DeletedAt *string `json:"deleted_at,omitempty"` DeletedAt *string `json:"deleted_at,omitempty"`
// 主题标识符 // theme key
Key string `json:"key"` Key string `json:"key"`
// 主题类型 // theme type
Type theme.Type `json:"type"` Type theme.Type `json:"type"`
// 主题颜色配置 // theme colors
Colors map[string]interface{} `json:"colors"` Colors map[string]interface{} `json:"colors"`
selectValues sql.SelectValues selectValues sql.SelectValues
} }
@@ -41,7 +43,7 @@ func (*Theme) scanValues(columns []string) ([]any, error) {
values[i] = new([]byte) values[i] = new([]byte)
case theme.FieldID: case theme.FieldID:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case theme.FieldCreatedAt, theme.FieldUpdatedAt, theme.FieldDeletedAt, theme.FieldKey, theme.FieldType: case theme.FieldUUID, theme.FieldCreatedAt, theme.FieldUpdatedAt, theme.FieldDeletedAt, theme.FieldKey, theme.FieldType:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
default: default:
values[i] = new(sql.UnknownType) values[i] = new(sql.UnknownType)
@@ -64,6 +66,12 @@ func (_m *Theme) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field id", value) return fmt.Errorf("unexpected type %T for field id", value)
} }
_m.ID = int(value.Int64) _m.ID = int(value.Int64)
case theme.FieldUUID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field uuid", values[i])
} else if value.Valid {
_m.UUID = value.String
}
case theme.FieldCreatedAt: case theme.FieldCreatedAt:
if value, ok := values[i].(*sql.NullString); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i]) return fmt.Errorf("unexpected type %T for field created_at", values[i])
@@ -139,6 +147,9 @@ func (_m *Theme) String() string {
var builder strings.Builder var builder strings.Builder
builder.WriteString("Theme(") builder.WriteString("Theme(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("uuid=")
builder.WriteString(_m.UUID)
builder.WriteString(", ")
builder.WriteString("created_at=") builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt) builder.WriteString(_m.CreatedAt)
builder.WriteString(", ") builder.WriteString(", ")

View File

@@ -14,6 +14,8 @@ const (
Label = "theme" Label = "theme"
// FieldID holds the string denoting the id field in the database. // FieldID holds the string denoting the id field in the database.
FieldID = "id" FieldID = "id"
// FieldUUID holds the string denoting the uuid field in the database.
FieldUUID = "uuid"
// FieldCreatedAt holds the string denoting the created_at field in the database. // FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at" FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database. // FieldUpdatedAt holds the string denoting the updated_at field in the database.
@@ -33,6 +35,7 @@ const (
// Columns holds all SQL columns for theme fields. // Columns holds all SQL columns for theme fields.
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldUUID,
FieldCreatedAt, FieldCreatedAt,
FieldUpdatedAt, FieldUpdatedAt,
FieldDeletedAt, FieldDeletedAt,
@@ -59,6 +62,8 @@ func ValidColumn(column string) bool {
var ( var (
Hooks [2]ent.Hook Hooks [2]ent.Hook
Interceptors [1]ent.Interceptor Interceptors [1]ent.Interceptor
// DefaultUUID holds the default value on creation for the "uuid" field.
DefaultUUID func() string
// DefaultCreatedAt holds the default value on creation for the "created_at" field. // DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() string DefaultCreatedAt func() string
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field. // DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
@@ -98,6 +103,11 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc() return sql.OrderByField(FieldID, opts...).ToFunc()
} }
// ByUUID orders the results by the uuid field.
func ByUUID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUUID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field. // ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()

View File

@@ -53,6 +53,11 @@ func IDLTE(id int) predicate.Theme {
return predicate.Theme(sql.FieldLTE(FieldID, id)) return predicate.Theme(sql.FieldLTE(FieldID, id))
} }
// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ.
func UUID(v string) predicate.Theme {
return predicate.Theme(sql.FieldEQ(FieldUUID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v string) predicate.Theme { func CreatedAt(v string) predicate.Theme {
return predicate.Theme(sql.FieldEQ(FieldCreatedAt, v)) return predicate.Theme(sql.FieldEQ(FieldCreatedAt, v))
@@ -73,6 +78,81 @@ func Key(v string) predicate.Theme {
return predicate.Theme(sql.FieldEQ(FieldKey, v)) return predicate.Theme(sql.FieldEQ(FieldKey, v))
} }
// UUIDEQ applies the EQ predicate on the "uuid" field.
func UUIDEQ(v string) predicate.Theme {
return predicate.Theme(sql.FieldEQ(FieldUUID, v))
}
// UUIDNEQ applies the NEQ predicate on the "uuid" field.
func UUIDNEQ(v string) predicate.Theme {
return predicate.Theme(sql.FieldNEQ(FieldUUID, v))
}
// UUIDIn applies the In predicate on the "uuid" field.
func UUIDIn(vs ...string) predicate.Theme {
return predicate.Theme(sql.FieldIn(FieldUUID, vs...))
}
// UUIDNotIn applies the NotIn predicate on the "uuid" field.
func UUIDNotIn(vs ...string) predicate.Theme {
return predicate.Theme(sql.FieldNotIn(FieldUUID, vs...))
}
// UUIDGT applies the GT predicate on the "uuid" field.
func UUIDGT(v string) predicate.Theme {
return predicate.Theme(sql.FieldGT(FieldUUID, v))
}
// UUIDGTE applies the GTE predicate on the "uuid" field.
func UUIDGTE(v string) predicate.Theme {
return predicate.Theme(sql.FieldGTE(FieldUUID, v))
}
// UUIDLT applies the LT predicate on the "uuid" field.
func UUIDLT(v string) predicate.Theme {
return predicate.Theme(sql.FieldLT(FieldUUID, v))
}
// UUIDLTE applies the LTE predicate on the "uuid" field.
func UUIDLTE(v string) predicate.Theme {
return predicate.Theme(sql.FieldLTE(FieldUUID, v))
}
// UUIDContains applies the Contains predicate on the "uuid" field.
func UUIDContains(v string) predicate.Theme {
return predicate.Theme(sql.FieldContains(FieldUUID, v))
}
// UUIDHasPrefix applies the HasPrefix predicate on the "uuid" field.
func UUIDHasPrefix(v string) predicate.Theme {
return predicate.Theme(sql.FieldHasPrefix(FieldUUID, v))
}
// UUIDHasSuffix applies the HasSuffix predicate on the "uuid" field.
func UUIDHasSuffix(v string) predicate.Theme {
return predicate.Theme(sql.FieldHasSuffix(FieldUUID, v))
}
// UUIDIsNil applies the IsNil predicate on the "uuid" field.
func UUIDIsNil() predicate.Theme {
return predicate.Theme(sql.FieldIsNull(FieldUUID))
}
// UUIDNotNil applies the NotNil predicate on the "uuid" field.
func UUIDNotNil() predicate.Theme {
return predicate.Theme(sql.FieldNotNull(FieldUUID))
}
// UUIDEqualFold applies the EqualFold predicate on the "uuid" field.
func UUIDEqualFold(v string) predicate.Theme {
return predicate.Theme(sql.FieldEqualFold(FieldUUID, v))
}
// UUIDContainsFold applies the ContainsFold predicate on the "uuid" field.
func UUIDContainsFold(v string) predicate.Theme {
return predicate.Theme(sql.FieldContainsFold(FieldUUID, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field. // CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v string) predicate.Theme { func CreatedAtEQ(v string) predicate.Theme {
return predicate.Theme(sql.FieldEQ(FieldCreatedAt, v)) return predicate.Theme(sql.FieldEQ(FieldCreatedAt, v))

View File

@@ -19,6 +19,20 @@ type ThemeCreate struct {
hooks []Hook hooks []Hook
} }
// SetUUID sets the "uuid" field.
func (_c *ThemeCreate) SetUUID(v string) *ThemeCreate {
_c.mutation.SetUUID(v)
return _c
}
// SetNillableUUID sets the "uuid" field if the given value is not nil.
func (_c *ThemeCreate) SetNillableUUID(v *string) *ThemeCreate {
if v != nil {
_c.SetUUID(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (_c *ThemeCreate) SetCreatedAt(v string) *ThemeCreate { func (_c *ThemeCreate) SetCreatedAt(v string) *ThemeCreate {
_c.mutation.SetCreatedAt(v) _c.mutation.SetCreatedAt(v)
@@ -116,6 +130,13 @@ func (_c *ThemeCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save. // defaults sets the default values of the builder before save.
func (_c *ThemeCreate) defaults() error { func (_c *ThemeCreate) defaults() error {
if _, ok := _c.mutation.UUID(); !ok {
if theme.DefaultUUID == nil {
return fmt.Errorf("ent: uninitialized theme.DefaultUUID (forgotten import ent/runtime?)")
}
v := theme.DefaultUUID()
_c.mutation.SetUUID(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok { if _, ok := _c.mutation.CreatedAt(); !ok {
if theme.DefaultCreatedAt == nil { if theme.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized theme.DefaultCreatedAt (forgotten import ent/runtime?)") return fmt.Errorf("ent: uninitialized theme.DefaultCreatedAt (forgotten import ent/runtime?)")
@@ -183,6 +204,10 @@ func (_c *ThemeCreate) createSpec() (*Theme, *sqlgraph.CreateSpec) {
_node = &Theme{config: _c.config} _node = &Theme{config: _c.config}
_spec = sqlgraph.NewCreateSpec(theme.Table, sqlgraph.NewFieldSpec(theme.FieldID, field.TypeInt)) _spec = sqlgraph.NewCreateSpec(theme.Table, sqlgraph.NewFieldSpec(theme.FieldID, field.TypeInt))
) )
if value, ok := _c.mutation.UUID(); ok {
_spec.SetField(theme.FieldUUID, field.TypeString, value)
_node.UUID = value
}
if value, ok := _c.mutation.CreatedAt(); ok { if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(theme.FieldCreatedAt, field.TypeString, value) _spec.SetField(theme.FieldCreatedAt, field.TypeString, value)
_node.CreatedAt = value _node.CreatedAt = value

View File

@@ -265,12 +265,12 @@ func (_q *ThemeQuery) Clone() *ThemeQuery {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// CreatedAt string `json:"created_at"` // UUID string `json:"uuid"`
// Count int `json:"count,omitempty"` // Count int `json:"count,omitempty"`
// } // }
// //
// client.Theme.Query(). // client.Theme.Query().
// GroupBy(theme.FieldCreatedAt). // GroupBy(theme.FieldUUID).
// Aggregate(ent.Count()). // Aggregate(ent.Count()).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *ThemeQuery) GroupBy(field string, fields ...string) *ThemeGroupBy { func (_q *ThemeQuery) GroupBy(field string, fields ...string) *ThemeGroupBy {
@@ -288,11 +288,11 @@ func (_q *ThemeQuery) GroupBy(field string, fields ...string) *ThemeGroupBy {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// CreatedAt string `json:"created_at"` // UUID string `json:"uuid"`
// } // }
// //
// client.Theme.Query(). // client.Theme.Query().
// Select(theme.FieldCreatedAt). // Select(theme.FieldUUID).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *ThemeQuery) Select(fields ...string) *ThemeSelect { func (_q *ThemeQuery) Select(fields ...string) *ThemeSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...) _q.ctx.Fields = append(_q.ctx.Fields, fields...)

View File

@@ -167,6 +167,9 @@ func (_u *ThemeUpdate) sqlSave(ctx context.Context) (_node int, err error) {
} }
} }
} }
if _u.mutation.UUIDCleared() {
_spec.ClearField(theme.FieldUUID, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok { if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(theme.FieldUpdatedAt, field.TypeString, value) _spec.SetField(theme.FieldUpdatedAt, field.TypeString, value)
} }
@@ -379,6 +382,9 @@ func (_u *ThemeUpdateOne) sqlSave(ctx context.Context) (_node *Theme, err error)
} }
} }
} }
if _u.mutation.UUIDCleared() {
_spec.ClearField(theme.FieldUUID, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok { if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(theme.FieldUpdatedAt, field.TypeString, value) _spec.SetField(theme.FieldUpdatedAt, field.TypeString, value)
} }

View File

@@ -25,6 +25,7 @@ func (Document) Annotations() []schema.Annotation {
// Mixin of the Document. // Mixin of the Document.
func (Document) Mixin() []ent.Mixin { func (Document) Mixin() []ent.Mixin {
return []ent.Mixin{ return []ent.Mixin{
mixin.UUIDMixin{},
mixin.TimeMixin{}, mixin.TimeMixin{},
mixin.SoftDeleteMixin{}, mixin.SoftDeleteMixin{},
} }

View File

@@ -25,6 +25,7 @@ func (Extension) Annotations() []schema.Annotation {
// Mixin of the Extension. // Mixin of the Extension.
func (Extension) Mixin() []ent.Mixin { func (Extension) Mixin() []ent.Mixin {
return []ent.Mixin{ return []ent.Mixin{
mixin.UUIDMixin{},
mixin.TimeMixin{}, mixin.TimeMixin{},
mixin.SoftDeleteMixin{}, mixin.SoftDeleteMixin{},
} }

View File

@@ -25,6 +25,7 @@ func (KeyBinding) Annotations() []schema.Annotation {
// Mixin of the KeyBinding. // Mixin of the KeyBinding.
func (KeyBinding) Mixin() []ent.Mixin { func (KeyBinding) Mixin() []ent.Mixin {
return []ent.Mixin{ return []ent.Mixin{
mixin.UUIDMixin{},
mixin.TimeMixin{}, mixin.TimeMixin{},
mixin.SoftDeleteMixin{}, mixin.SoftDeleteMixin{},
} }

View File

@@ -17,6 +17,14 @@ func NowString() string {
return time.Now().Format(TimeFormat) return time.Now().Format(TimeFormat)
} }
// skipAutoUpdateKey context key for skipping auto update
type skipAutoUpdateKey struct{}
// SkipAutoUpdate 返回跳过自动更新 updated_at 的 context
func SkipAutoUpdate(ctx context.Context) context.Context {
return context.WithValue(ctx, skipAutoUpdateKey{}, true)
}
// TimeMixin 时间字段混入 // TimeMixin 时间字段混入
// created_at: 创建时间 // created_at: 创建时间
// updated_at: 更新时间(自动更新) // updated_at: 更新时间(自动更新)
@@ -44,6 +52,10 @@ func (TimeMixin) Hooks() []ent.Hook {
return []ent.Hook{ return []ent.Hook{
func(next ent.Mutator) ent.Mutator { func(next ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
// 跳过自动更新(用于同步导入场景)
if ctx.Value(skipAutoUpdateKey{}) != nil {
return next.Mutate(ctx, m)
}
// 只在更新操作时设置 updated_at // 只在更新操作时设置 updated_at
if m.Op().Is(ent.OpUpdate | ent.OpUpdateOne) { if m.Op().Is(ent.OpUpdate | ent.OpUpdateOne) {
if setter, ok := m.(interface{ SetUpdatedAt(string) }); ok { if setter, ok := m.(interface{ SetUpdatedAt(string) }); ok {

View File

@@ -0,0 +1,36 @@
package mixin
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"entgo.io/ent/schema/mixin"
"github.com/google/uuid"
)
// UUIDMixin 添加 UUID 字段用于跨设备同步
// 使用 UUIDv7具有时间有序性索引性能更好
type UUIDMixin struct {
mixin.Schema
}
// Fields of the UUIDMixin.
func (UUIDMixin) Fields() []ent.Field {
return []ent.Field{
field.String("uuid").
DefaultFunc(func() string {
return uuid.Must(uuid.NewV7()).String()
}).
Unique().
Immutable().
StructTag(`json:"uuid"`).
Comment("UUID for cross-device sync (UUIDv7)"),
}
}
// Indexes of the UUIDMixin.
func (UUIDMixin) Indexes() []ent.Index {
return []ent.Index{
index.Fields("uuid"),
}
}

View File

@@ -24,6 +24,7 @@ func (Theme) Annotations() []schema.Annotation {
// Mixin of the Theme. // Mixin of the Theme.
func (Theme) Mixin() []ent.Mixin { func (Theme) Mixin() []ent.Mixin {
return []ent.Mixin{ return []ent.Mixin{
mixin.UUIDMixin{},
mixin.TimeMixin{}, mixin.TimeMixin{},
mixin.SoftDeleteMixin{}, mixin.SoftDeleteMixin{},
} }

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,7 @@ import (
"voidraft/internal/models/ent" "voidraft/internal/models/ent"
"voidraft/internal/models/ent/extension" "voidraft/internal/models/ent/extension"
"voidraft/internal/models/ent/keybinding"
"voidraft/internal/models/schema/mixin" "voidraft/internal/models/schema/mixin"
"github.com/wailsapp/wails/v3/pkg/application" "github.com/wailsapp/wails/v3/pkg/application"
@@ -113,9 +114,23 @@ func (s *ExtensionService) UpdateExtensionEnabled(ctx context.Context, key strin
if ext == nil { if ext == nil {
return fmt.Errorf("extension not found: %s", key) return fmt.Errorf("extension not found: %s", key)
} }
return s.db.Client.Extension.UpdateOneID(ext.ID).
// 更新扩展状态
if err := s.db.Client.Extension.UpdateOneID(ext.ID).
SetEnabled(enabled). SetEnabled(enabled).
Exec(ctx) Exec(ctx); err != nil {
return err
}
// 同步更新该扩展关联的快捷键启用状态
if _, err := s.db.Client.KeyBinding.Update().
Where(keybinding.Extension(key)).
SetEnabled(enabled).
Save(ctx); err != nil {
return fmt.Errorf("update keybindings for extension %s error: %w", key, err)
}
return nil
} }
// UpdateExtensionConfig 更新扩展配置 // UpdateExtensionConfig 更新扩展配置