What is Swift CoreData ?

About Swift core data


Swift Core Data is a powerful framework provided by Apple for managing the persistence of data in iOS and macOS applications. It offers developers a seamless and efficient way to work with a local database, providing features such as data modeling, querying, and relationship management.

At its core, Core Data consists of four key components: managed object model, managed object context, persistent store coordinator, and persistent store. These components work together to facilitate the storage and retrieval of data, making it easier for developers to work with complex data structures.

One of the advantages of using Core Data in Swift is its flexibility in terms of data modeling. You can define entities, attributes, and relationships using a visual editor called Xcode’s Data Model Inspector. This allows you to create a structured data model that represents the entities and their relationships in your application.

Another notable feature of Core Data is its support for various forms of data persistence. By default, Core Data uses SQLite as the persistent store, but it also supports other stores such as XML, binary, and in-memory stores. This flexibility allows you to choose the most suitable persistent store for your application’s needs.

Working with Core Data in Swift involves interacting with managed objects that represent real-world entities in your application. These managed objects are instances of classes generated by Xcode based on your data model. You can perform CRUD (Create, Read, Update, Delete) operations on these objects, allowing you to store, fetch, update, and remove data from the persistent store.

To interact with Core Data, you typically use the Managed Object Context, which acts as a scratchpad for managing the lifecycle of managed objects. It provides methods for inserting, fetching, updating, and deleting objects, as well as handling relationships between objects.

In conclusion, Swift Core Data is a powerful and versatile framework that simplifies the management of data persistence in iOS and macOS applications. Its flexible data modeling capabilities, support for various persistent stores, and intuitive API make it an excellent choice for developers looking to build applications that require efficient and scalable data storage.

How to auto create tables based on sequelize models

Auto create table based on sequelize models


We had discussed how to auto create API using sequelize, on thing I missed is auto creation of tables.

Sequelize

Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication and more.

Auto create tables

Sequelize module has provided a function called sync in order to create tables based on the Sequelize models we created.

Place the call in the authenticate method of the Sequelize configuration as follows

const Sequelize=require('sequelize')
module.exports=new Sequelize('todo_collections','root','123',{
    host:'127.0.0.1',
    port:3306,
    dialect:'mysql',
    pool:{
        max:5,
        min:0,
        acquire:30000,
        idle:10000
    }
})

.......
.......

const db = require("./config/database");
db.authenticate()
  .then(() => {
      console.log("Database connected")
    db.sync()
    })
  .catch((e) => console.log("Error:" + e));
app.get("/", (req, res) => {
  res.send("Hello world");
});

We can use sync({force:true}) for drop the tables already created

You may like to read these sequelize posts too

Create REST-API using sequelize -MariaDB ORM in Nodejs

How to create REST-API using sequelize ORM for MariaDB in Node-Expressjs


We had many posts on API and I am moving on sequelize ORM which allows us to perform CURD operation in REST manner or using Modals, just like we done with mongoose.

Sequelize

Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication and more.

MariaDB

MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system, intended to remain free and open-source software under the GNU General Public License. The standard installation come with Heidi SQL GUI which help us create and manage database and schemas.

You can download and install it from the official website

Todo API

todos table in Heidi SQL

Our API is used to create the todos ,store in MariaDB , and perform all CURD operations using sequelize modal.

First we need to create the above table in your Maria. Now lets create a basic Nodejs project.

Continue reading “Create REST-API using sequelize -MariaDB ORM in Nodejs”

Create REST-API using sequelize-Mysql in Nodejs

How to create REST-API using sequelize-MySQL ORM in Node-Expressjs


We had many posts on API and I am moving on sequelize ORM which allows us to perform CURD operation in REST manner or using Modals, just like we done with mongoose.

Sequelize

Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication and more.

MySQL

MySQL is an open-source relational database management system. Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language. A workbench , which GUI tool to manage database object is available at MySQL website along with MySQL Downloads

Todo API

todos table in Workbench

Our API is used to create the todos ,store in MySQL DB , and perform all CURD operations using sequelize modal.

First we need to create the above table in your MySQL. Now lets create a basic Nodejs project.

Continue reading “Create REST-API using sequelize-Mysql in Nodejs”

Create REST-API using sequelize-Postgres in Nodejs

How to create REST-API using sequelize ORM in Node-Expressjs


We had many posts on API and I am moving on sequelize ORM which allows us to perform CURD operation in REST manner or using Modals, just like we done with mongoose.

Sequelize

Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication and more.

PostgreSQL

Postgres is an opensource DBMS, it is free and perform faster results. It come with pg-admin web interface which allows navigate through database. You can download and install it from the official website

Todo API

todos table in pg admin

Our API is used to create the todos ,store in pg (PostgreSQL) , and perform all CURD operations using sequelize modal.

First we need to create the above table in your pg. Now lets create a basic Nodejs project.

Continue reading “Create REST-API using sequelize-Postgres in Nodejs”