{"id":26010308,"url":"https://github.com/renqiankun/electron-vite-template","last_synced_at":"2025-03-05T22:49:07.675Z","repository":{"id":278713538,"uuid":"697552573","full_name":"renqiankun/electron-vite-template","owner":"renqiankun","description":"electron vite vue3 bettter-sqlite3 drizzle-orm","archived":false,"fork":false,"pushed_at":"2025-02-25T05:44:44.000Z","size":319,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T06:19:45.613Z","etag":null,"topics":["better-sqlite3","drizzle-orm","electron","vite","vue3"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renqiankun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-28T01:17:53.000Z","updated_at":"2025-02-25T05:44:48.000Z","dependencies_parsed_at":"2025-02-25T06:19:47.728Z","dependency_job_id":null,"html_url":"https://github.com/renqiankun/electron-vite-template","commit_stats":null,"previous_names":["renqiankun/autotest","renqiankun/electron-vite-template"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renqiankun%2Felectron-vite-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renqiankun%2Felectron-vite-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renqiankun%2Felectron-vite-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renqiankun%2Felectron-vite-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renqiankun","download_url":"https://codeload.github.com/renqiankun/electron-vite-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242117659,"owners_count":20074436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["better-sqlite3","drizzle-orm","electron","vite","vue3"],"created_at":"2025-03-05T22:49:07.073Z","updated_at":"2025-03-05T22:49:07.661Z","avatar_url":"https://github.com/renqiankun.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[ English](README.md) | [ 中文](README.zh.md)\n# 🚀 Electron + Vite + Drizzle ORM + Better-SQLite3\n\nA modern desktop application template based on **Electron + Vite + Drizzle ORM + Better-SQLite3**.\n\n## ✨ Features\n- **Drizzle ORM**: A modern, lightweight ORM solution\n- **Vue 3**: Used as the UI layer (can be replaced as needed)\n- **Electron v34.0.0** + **Node.js v20.18.0**\n- **Better-SQLite3**: High-performance, synchronous SQLite database library\n\n---\n\n## 📂 Directory Structure\n\n```bash\n📦 Project Root\n├── assets                 # Static resources (including app icons for packaging)\n├── electron               # Electron-related code\n│   ├── main               # Main process code\n│   │   ├── auto-update    # electron-updater auto update\n│   │   ├── db             # Database-related code\n│   │   ├── router         # Routes (provides access to the database)\n│   │   ├── utils.ts       # Utility functions\n│   │   ├── dbServicesInit.ts  # Database initialization logic\n│   │   ├── index.ts       # Main process entry file\n│   ├── preload            # Preload scripts\n├── migrations             # Database migration files\n├── public                 # Vue public resources\n├── src                    # Vue source code\n├── drizzle.config.ts       # Drizzle ORM migration configuration\n├── electron-builder.json   # Electron build configuration\n├── vite.config.ts         # Vite build configuration\n```\n\n---\n\n## ⚙️ Environment Setup\n\n1. **Node.js** version `v20.18.0`\n2. **Visual Studio 2022** (requires **Desktop development with C++** component)\n3. **Python 3.7**\n4. **Configure environment variables**\n   ```sh\n   npm config edit\n   ```\n   Add the following content:\n   ```ini\n   msvs_version=2022\n   python=python3.7\n   ```\n5. **Globally install `node-gyp`**\n   ```sh\n   npm install -g node-gyp\n   ```\n\n---\n\n## 🚀 Start the Project\n\n```sh\nnpm install                  # Install dependencies\nnpm rebuild                  # Rebuild local dependencies\nnpx electron-rebuild -f -w better-sqlite3  # Adapt Electron native modules (optional: specify module name, e.g., better-sqlite3)\nnpm run syncSchema           # Sync the database schema\nnpm run dev                  # Start the project\nnpm run build                # Build the project\n```\n\n---\n\n## 🔨 Development Guide\n\n### **📌 Local Database Synchronization**\n- **After modifying the database schema, execute:**\n  ```sh\n  npm run syncSchema\n  ```\n  This command includes three steps:\n  1. `npm rebuild` - Rebuild `better-sqlite3` to match the local Node.js version\n  2. `npx drizzle-kit push` - Sync the schema directly to the local database\n  3. `npx electron-rebuild -f -w better-sqlite3` - Rebuild `better-sqlite3` for Electron compatibility\n\n### **📌 Database Upgrade During Packaging**\n\n1. Run the build command, which will first execute `npm run generateSchema` to generate database migration files:\n   ```sh\n   npm run build\n   ```\n\n   ```\n   The database file is separated into development (`.env.db`) and production (`.db`) versions.\n   This prevents issues when using Drizzle ORM for both local development and packaged installations.\n   If using the same file, remove the existing database file or rename it before installing the production package.\n   ```\n\n---\n\n### **📌 Preload Script Usage**\n1. **`webPreferences` disables Node.js in the renderer, enables context isolation, but does not enable sandbox mode**, requiring native modules or IPC communication to be exposed in `preload`.\n2. **Preload files are compiled as `.mjs` (ES module format)**, and `import` is used to include other modules internally.\n\n### **📌 Database Migration Strategy**\nDatabase migrations are handled differently for **development** and **production** environments:\n\n#### **1️⃣ Production Environment**\n- **Database migration files are automatically generated during the build process**, no manual intervention required.\n- Ensure that `drizzle.config.ts` points to the correct database file.\n\n#### **2️⃣ Development Environment**\n- **After modifying the schema, run:**\n  ```sh\n  npm run syncSchema\n  ```\n  **This executes the following steps:**\n  - Rebuild `better-sqlite3`\n  - Use `drizzle-kit push` to directly sync the database\n  - Rebuild `better-sqlite3` for Electron compatibility\n\n#### **3️⃣ Migration File Management**\n- The `migrations` directory stores database migration files.\n- **Do not delete this directory**, as it may cause data loss.\n\n---\n\n## 📌 To-Do List\n✅ **Database Communication Example**  \n✅ **App Update with electron-updater Example**  \n✅ **Add Logger**  \n⬜ **Multi-Window Example**  \n\n---\n\n🎉 **Enjoy coding with Electron + Vite + Drizzle ORM!** 🚀\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenqiankun%2Felectron-vite-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenqiankun%2Felectron-vite-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenqiankun%2Felectron-vite-template/lists"}