Skip to content

Chank1e/SequelizeJava

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SequelizeJava - ORM for PostgreSQL

Simplicity of sequelize from NodeJS to Java.

  • Creating instance of Sequelize:
import sequelize.Sequelize;

Sequelize sequelize = new Sequelize("DBNAME", "USER","PASSWORD");
  • Creating Schema for your Model:
import sequelize.model.Schema;

Schema UserSchema = new Schema()
                        .withUpdatedAt() // It will create `updatedAt` timestamp to control the date of last update
                        .withCreatedAt() // It will create `createdAt` timestamp to control the date of creation
                        .insert("name", DataTypes.TEXT)
                        .insert("surname", DataTypes.TEXT);

Schema is like table in Postgres. You should describe columns you need in Schema.

  • Connect your Schema with database and create Model:
import sequelize.model.Model;

Model User = sequelize.define("User", UserSchema);

Here you say to Sequelize that in table User there are data in UserSchema format.

  • Sync your models with database:
sequelize.sync();

This method will delete all tables with each model name if it exists and create them back with columns from Model Schema

Model:

Method Returns
.create(SchemaValues) CompletedFuture
.findAll(Statement) CompletedFuture
.findOne(Statement) CompletedFuture
.update(SchemaValues, Statement) CompletedFuture
.delete(Statement) CompletedFuture

Statement:

Method Example SQL
.where(String columnName, Operator op, Object obj) .where("id", Operator.eq, 1) ... WHERE id = 1
.and() .where("id",Operator.gt,1) .and() .where("id",Operator.lt, 10) ... WHERE id > 1 AND id < 10
.or() .where("id",Operator.gt,1) .or() .where("id",Operator.lt, 10) ... WHERE id > 1 OR id < 10
.setAttributes(List attributes) .setAttributes(Arrays.asList("id","name")) SELECT "id","name" ...

Schema:

Method Example
.insert(String name, DataTypes type) .insert("name", DataTypes.TEXT)
.withCreatedAt()
.withUpdatedAt()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages