Git Product home page Git Product logo

elec-sqlite-vue's Introduction

Vue 3 + Electron + Sqlite + Sequelize

POC for Electron app with Vue 3 frontend and persisted database with SQlite.

Setup

Inside project root folder

note: I prefer using yarn as npm is highly unstable with electron and vue integration

yarn 

yarn electron:serve

To Build App for OS executables

yarn electron:build

File Structure

  • The project is a normal Vue CLI project. So the file structure is pretty familiar.
  • The electron builder plugin adds a new file src/background.ts , this serves as the entry point of the electron app.
  • src/data.db In project SQlite 3 database for testing.
  • getdb.ts Initiates the Sequelize instance for using the database.
  • main.ts entry of vue app. It creates the vue instance and mounts the app.

Where to code ?

  • For adding pages/views for electron app go to > src/views.
  • For adding components to be used i Vue pages/views go to > src/components
  • To create new app window / or any electron stuff go to > src/background.ts
  • For working with database i.e. creating models for sequelize go to > src/getdb.ts

Config Files

  • tsconfig.json for configuring typescript.
  • vue.config.js Vue config. Not recommended to change anything in this file.

A brief note on Sequelize

  • Sequelize is a promise based ORM. So using it is pretty easy.
  • Whe using sequelize we don't have to create tables as it creates and syncs tables according to the defined models.
  • Sequelize models are a abstaction of the data schema or the table schema of a db. So instead of using SQL queries for creating tables we can make sequelize to do that by using models.
  • A sample model User is defined in src/getdb.ts. Learn more about sequelize Models
// a sample model USer
const User = sequelize.define('User', {
    firstName: {
        type: DataTypes.STRING,
        allowNull: false
    },
    lastName: {
        type: DataTypes.STRING
    },

}, {
});
  • SQL queries are replaced by sequelize model queries .
// sample query for model User
// inside an async function

User.findAll().then((res)=>{
	console.log(res)
}).catch(err=> console.log(err))

Lean more about model Queries here

  • More about Sequelize can be found in their Docs. Not that good but functional.

Notes

  • Usage with Vuex is not recommended as it causes the db process to stop on reload.

Known Bugs

  • There are no known bugs as the build was successful with no errors.
  • To report a bug create an issue.

Errors

For errors try googling or contact me!

References

elec-sqlite-vue's People

Contributors

soulsam480 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.