一個輕量級,0配置orm框架 sharkchili-feifei

mmflys發表於2019-02-28

sharkchili-feifei

Feifei is a slight orm frame,almost zero configuration,running in container based on native sql,supporting query based on object and string sql query.

Links

How to build

Note that this is build-time requirement. JDK 8 is enough to run your feifei-based application.

How to start

Add this dependency to you pom.

    <dependency>
    <groupId>com.fishbyby.sharkchili</groupId>
    <artifactId>sharkchili-feifei</artifactId>
    <version>1.0.0</version>
    </dependency>
複製程式碼

Usages

Operation before querying

Launch the feifei container

    QueryConfig queryConfig = QueryConfig.deFaultConfig();
    queryConfig.setEntityPackage("com.shark.test.feifei.entity");
    Container container = new DefaultFeiFeiContainer();
    ((DefaultFeiFeiContainer) container).setQueryConfig(queryConfig);
    FeiFeiBootStrap.get().container(container).launch();
複製程式碼

SELECT

  • Query based on original sql.
    Query query = StudentQuery.create("SELECT * FROM student")
    List<Student> students = query.query();
複製程式碼
  • Update based on EntityQuery.
    Query query = StudentQuery.create().select(Student.create().setName("mike").setAge(13));
    List<Student> students=query.query();
複製程式碼
  • Query based on entity.
    Student condition = Student.create().setName("mike").setAddress("China");
    Student student = condition.selectSingle();
複製程式碼

INSERT

  • Insert based on original sql.
    Query query = StudentQuery.create("INSERT INTO student(id,name,age) VALUES(1,`mike`,15)");
    query.query();
複製程式碼
  • Insert based on EntityQuery.
    Query query = EntityQuery.create().insert(Student.create().setName("Jenny").setAge(16).setAddress("America").setCreateTime(new Date()));
    query.query();
複製程式碼
  • Insert based on Entity.
    Student student = Student.create().setName("Nick").setAge(10).setAddress("America").setCreateTime(new Date());
    student.insert();
複製程式碼

UPDATE

  • Update based on original sql.
    Query query = StudentQuery.create("UPDATE student SET name=`mike`");
    query.query();
複製程式碼
  • Update based on EntityQuery.
    Query query = EntityQuery.create().update(Student.create().setId(1).setName("MIKE"));
    query.query();
複製程式碼
  • Update based on Entity.
    Student student = Student.create().setId(18).setName("Nick").setAge(10).setAddress("China").setCreateTime(new Date());
    student.update();
複製程式碼

DELETE

  • Delete based on original sql.
    Query query = StudentQuery.create("DELETE FROM student WHERE id=1");
    query.query();
複製程式碼
  • Delete based on EntityQuery.
    Query query = EntityQuery.create().delete(Student.create().setName("Rose"));
    query.query();
複製程式碼
  • Delete based on Entity.
    Student student = Student.create().setId(19);
    student.delete();
複製程式碼

Config

Feifei have all default config instead of entity path.

Query config

  • entityPackage: path of your entity(it`s necessary).
  • queryOptions: provide option that whether return record,return id after querying or not,auto add from phrase,auto print query result and so on.
  • dataBaseType: type of your database,mysql supported temporarily.
  • connectionGet: how to get a connection,you can implement this interface to set how to get connection,use FeiFeiPoolDatasource by default.
  • ignore: ignore string when database table map to entity,eg table name `t_test_student` -> `test`
  • nameStyle: the name style of database table and column.
  • cacheConfig: config of cache,if you need to use cache.

Cache config

  • openCache: if false,will query from database
  • fireType: type of fire cache,provide ANY(any query),THREAD(same thread),CONDITION_FIRE(config by yourself)
  • fireCaches: is corresponding fire type CONDITION_FIRE,implement FireCache class if you want config a condition to fire cache.
  • cacheStoryLoad: type of story cache,provide app cache now,will support redis cache later.
  • fireCacheManager: this need to ben config

Email me,if you have any idea.
Email: sharkchili.su@gmail.com

相關文章