6 Star 3 Fork 1

HarmonyOS-TPC / RushOrm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

RushOrm

RushOrm replaces the need for SQL by mapping java classes to SQL tables.

概述

What projects is it right for?

  • Projects with complex data structures
  • Projects that want to implement database storage in the minimum amount of time
  • Projects that talk to a rest api

Why was RushOrm written?

  • Complex relationships - RushObjects support Lists of other RushObjects
  • SQL free migration
  • Easily extendable
  • No dependencies
  • Support asynchronous call
  • Be fast through compound inserts and selects
  • Support importing and exporting data to and from JSON
  • Unique ids to support merging databases
  • Supports conflict resolution when importing data
While there are a number of other ORMs, the areas many seem to fall short is the support of 'one to many' relationships, migration and extensions. While claiming all the same basic feature of most other ORMs RushOrm supports 'List' properties without having to add the parent object to it's children. It also handles migrating the class structure without any SQL scripts being required by the developer. Finally it is designed with the understanding that not every situation can be anticipated so instead it can be easily customized.

演示效果

集成

方式一
通过library生成har包添加har包到libs文件夹内
在entry的gradle内添加如下代码
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])

方式二
allprojects{
    repositories{
        mavenCentral()
    }
}
implementation 'io.openharmony.tpc.thirdlib:RushOrm_rushohos:1.0.6' 

entry运行要求

通过DevEco studio,并下载SDK 将项目中的build.gradle文件中dependencies→classpath版本改为对应的版本(即你的IDE新建项目中所用的版本)

示例

1.

public class Car extends RushObject {

    public String color;
    public Engine engine;

    public String anotherField;

    @RushList(classType = Wheel.class)
    public List<Wheel> wheels;

    public Car(){
        /* Empty constructor required */
    }

    public Car(String color, Engine engine){
        this.color = color;
        this.engine = engine;
    }
}


public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(MainAbilitySlice.class.getName());
        List<Class<? extends Rush>> classes = new ArrayList<>();
        classes.add(Car.class);
        classes.add(Engine.class);
        classes.add(Wheel.class);
        OhosInitializeConfig ohosInitializeConfig = new OhosInitializeConfig(getApplicationContext(), classes);
        RushOhos.initialize(ohosInitializeConfig);
    }
}



2.
        Button btnSave = (Button) findComponentById(ResourceTable.Id_btn_save);
        Button btnSelect = (Button) findComponentById(ResourceTable.Id_btn_select);
        Button btnDel = (Button) findComponentById(ResourceTable.Id_btn_del);
        Text tvShow = (Text) findComponentById(ResourceTable.Id_text_show);
        //保存
        btnSave.setClickedListener(component -> {
            final long startTime = System.currentTimeMillis();
            final int numberToSave = 100;
            List<Car> cars = new ArrayList<>(numberToSave);
            for (int i = 0; i < numberToSave; i++) {
                Car car = new Car("Red", new Engine());
                car.wheels = new ArrayList<>();
                for (int j = 0; j < 4; j++) {
                    car.wheels.add(new Wheel("Michelin"));
                }
                cars.add(car);
            }

            RushCore.getInstance().save(cars, () -> {
                long endTime = System.currentTimeMillis();
                final double saveTime = (endTime - startTime) / 1000.0;
                getAbility().getContext().getUITaskDispatcher().asyncDispatch(new Runnable() {
                    @Override
                    public void run() {
                        tvShow.setText("保存成功!总耗时:"+String.format("%1$,.2f s", saveTime));
                    }
                });
            });
        });
        //查询
        btnSelect.setClickedListener(component -> {
            new Thread(() -> {
                List<Car> cars = new RushSearch().find(Car.class);
                getAbility().getContext().getUITaskDispatcher().asyncDispatch(new Runnable() {
                    @Override
                    public void run() {
                        LogUtil.error("test", "Rush main select complete====");
                        tvShow.setText("查询成功:"+JSON.toJSONString(cars));
                    }
                });
            }).start();
        });
        //删除
        btnDel.setClickedListener(component -> new Thread(() -> {
            RushCore.getInstance().deleteAll(Car.class);
            RushCore.getInstance().deleteAll(Engine.class);
            RushCore.getInstance().deleteAll(Wheel.class);
            getAbility().getContext().getUITaskDispatcher().asyncDispatch(new Runnable() {
                @Override
                public void run() {
                    tvShow.setText("删除成功");
                }
            });
        }).start());

Licence Apache License, Version 2.0

Copyright (C) 2015 Stuart Campbell Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

空文件

简介

RushOrm replaces the need for SQL by mapping java classes to SQL tables. 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/HarmonyOS-tpc/RushOrm.git
git@gitee.com:HarmonyOS-tpc/RushOrm.git
HarmonyOS-tpc
RushOrm
RushOrm
master

搜索帮助