Skip to content

A stupidly simple Java/MySQL ORM with native Hikaricp, with dialect adaptations for MariaDB and Sqlite

Notifications You must be signed in to change notification settings

Mindgamesnl/storm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Storm is a fast, easy to use, no-bullshit opinionated Java ORM inspired by Doctrine. The main goal of this project is to allow future-mats to easily implement Sql-based storage and relation solutions in my projects and easily prototype concepts, without harming production usability.

Features

  • Automatic schema creation and updates based on models
  • Built in support for java types with an API to add your own
  • Support for OneToMany mappings with arraylist columns
  • Out-of-the-box adapters for Sqlite (flat file), Sqlite (Memory) and HiariCP-MariaDB
  • Dynamic SQL Dialects depending on the target platform
  • Incredibly easy to use API
  • Native mappings and support for:
    • Boolean
    • Double
    • Float
    • Integer
    • Long
    • String
    • UUID
    • Instant
    • Any java object as Blob (HashMap, etc)

Performance

Tests ran on my main workstation, targeting a Sqlite flatfile and memory database. image

Examples

// create a model
@Data
@Table(name = "user")
class User extends StormModel {

    @Column
    private String userName;

    @Column
    private Integer score;

    @Column(
            type = ColumnType.ONE_TO_MANY,
            references = {SocialPost.class},
            matchTo = "poster"
    )
    private List<SocialPost> posts;

    @Column
    private UUID minecraftUserId = UUID.randomUUID();

    @Column(
            name = "email",
            defaultValue = "[email protected]"
    )
    private String emailAddress;

}

public class SocialPost extends StormModel {

    @Column(
            notNull = true
    )
    private String content;

    @Column(
            keyType = KeyType.FOREIGN,
            references = {User.class}
    )
    private Integer poster;

}


// create an instance
Storm storm = new Storm(new SqliteDriver(dataFile));
// register one table
storm.migrate(new User());
storm.migrate(new SocialPost());
storm.runMigrations();

// create a new user
User mindgamesnl = new User();
mindgamesnl.setUserName("Mindgamesnl");
mindgamesnl.setEmailAddress("[email protected]");
mindgamesnl.setScore(9009);

// save or update the user
storm.save(mindgamesnl);

// query for users
Collection<User> justMindgamesnl =
        storm.buildQuery(User.class)
        .where("user_name", Where.EQUAL, "Mindgamesnl")
        .limit(1)
        .execute()
        .join();

Usage with HikariCP

// hikari
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://localhost:3306/simpsons");
config.setUsername("bart");
config.setPassword("51mp50n");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

Storm storm = new Storm(new HikariDriver(config));

About

A stupidly simple Java/MySQL ORM with native Hikaricp, with dialect adaptations for MariaDB and Sqlite

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages