{"id":21947691,"url":"https://github.com/masich/datab","last_synced_at":"2026-04-05T08:35:46.956Z","repository":{"id":39923126,"uuid":"132438853","full_name":"masich/DataB","owner":"masich","description":"Simple and easy to use JDBC based ORM for Java and Kotlin","archived":false,"fork":false,"pushed_at":"2023-05-25T04:54:09.000Z","size":4217,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-29T05:51:56.424Z","etag":null,"topics":["datab","database","db","java","jdbc","jdbc-database","kotlin","sql"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/masich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-07T09:35:12.000Z","updated_at":"2022-05-21T06:47:45.000Z","dependencies_parsed_at":"2025-03-22T16:57:06.784Z","dependency_job_id":null,"html_url":"https://github.com/masich/DataB","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/masich/DataB","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masich%2FDataB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masich%2FDataB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masich%2FDataB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masich%2FDataB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masich","download_url":"https://codeload.github.com/masich/DataB/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masich%2FDataB/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31430009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T08:13:15.228Z","status":"ssl_error","status_checked_at":"2026-04-05T08:13:11.839Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datab","database","db","java","jdbc","jdbc-database","kotlin","sql"],"created_at":"2024-11-29T05:09:13.705Z","updated_at":"2026-04-05T08:35:46.933Z","avatar_url":"https://github.com/masich.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataB\n\u003e Simple and easy-to-use JDBC-based ORM for Java and Kotlin.\n\nDataB is a library for Java and Kotlin programming languages that \ncan help you to store application data in a database. You can save almost all types of data into a database using internal DataB \nfunctionality.\n\n**The latest version** is \u003cins\u003e0.0.4-SNAPSHOT\u003c/ins\u003e\n\n**Status**: in development.\n*Unstable, untested, and has a meager functionality.*\n\n## Table of Contents  \n1. [Installation](#Installation)  \n    * [Modules](#Modules)\n    * [Build and install from sources](#Build-and-install-from-sources)\n    * [Maven](#Maven)\n    * [Gradle](#Gradle)\n2. [Getting started](#Getting-started)\n    * [Initialization](#Initialization)\n    * [Data models for DataB](#Data-models-for-DataB)\n    * [Using DataB features](#Using-DataB-features)\n3. [License](#License)\n\n\n## Installation\nDataB is provided as a set of Maven repositories containing a lot of modules \nto construct a unique environment for every user. A list of modules and their \ndescriptions are shown below.\n\n### Modules\n| Module name | Description |\n| ----------- | ----------- |\n| datab       | Core module. It contains all main components, abstract classes, and interfaces to work with JDBC and databases. |\n| datab-converters | Additional module that contains different implementations of the DataB [Converter](datab/src/main/java/com/masich/datab/converter/Converter.java) interface. Currently, this module has only one implementation that can convert different objects to JSON. |\n| datab-providers | Additional important module that contains the implementation of DataB [Provider](datab/src/main/java/com/masich/datab/provider/DBProvider.java) and other components. |\n| datab-examples | Module that provides examples of using a DataB library. |\n\n\nAs was mentioned before, the DataB is a set of Maven repositories. \nSo, you can install each of them using both Maven and Gradle.\n\n### Build and install from sources\n1. Download sources and extract them.\n2. Go to the parent source directory.\n3. Open a terminal/console here and execute the following command:\n```shell\nmvn clean install\n```\n\nThis command will compile and install DataB modules into your local Maven repository, and you will be able to use them in your projects. \n\n### Maven\n\nTo use DataB in your Maven projects, you should add appropriate DataB\nmodules as dependencies. This example depends on such modules as ```datab``` main module, ```provider-sqlite``` and ```converter-gson```.\n\n```xml\n    \u003cdependencies\u003e\n        ...\n\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.masich.datab\u003c/groupId\u003e\n            \u003cartifactId\u003edatab\u003c/artifactId\u003e\n            \u003cversion\u003e0.0.4-SNAPSHOT\u003c/version\u003e\n        \u003c/dependency\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.masich.datab\u003c/groupId\u003e\n            \u003cartifactId\u003eprovider-sqlite\u003c/artifactId\u003e\n            \u003cversion\u003e0.0.4-SNAPSHOT\u003c/version\u003e\n        \u003c/dependency\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.masich.datab\u003c/groupId\u003e\n            \u003cartifactId\u003econverter-gson\u003c/artifactId\u003e\n            \u003cversion\u003e0.0.4-SNAPSHOT\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n```\n\n### Gradle\n\nTo use DataB in your Gradle project, you also must indicate that you are\nusing Maven local repository.\n\n```groovy\n\nrepositories {\n    ...\n    \n    mavenLocal()\n}\n\ndependencies {\n    ...\n    \n    implementation(\"com.masich.datab:datab:0.0.4-SNAPSHOT\")\n    implementation(\"com.masich.datab:provider-sqlite:0.0.4-SNAPSHOT\")\n    implementation(\"com.masich.datab:converter-gson:0.0.4-SNAPSHOT\")\n}\n\n```\n\n## Getting started\n\n### Initialization\nBefore using databases and any DataB core functionality, it is necessary \nto initialize it. An example of a method that initializes the DataB is \nprovided below.\n```java\nprivate static void initDB() throws SQLException {\n    DBManager manager = new DBManager.Builder()\n            //Provider for your type of database\n            .addProviderFactory(new SQLiteProviderFactory())\n            //Path to your database. You also can use a full path like \"jdbc:sqlite:sample.db\"\n            .addDatabaseSrc(\"sample.db\")\n            //Converter for saving custom classes (which are not DataB Entities) into a database\n            .addConverterFactory(new GsonConverterFactory())\n            .build();\n\n    DBManager.setSingleton(manager);\n}\n```\n### Data models for DataB\nIn DataB, we define all database tables as specific Java classes. \nTo define a class as a DataB table (called entity), you need to inherit this \ncustom class from a superclass [Entity](datab\\src\\main\\java\\com\\masich\\datab\\Entity.java) \nand annotate it using [@Table](/datab/src/main/java/com/masich/datab/annotation/Table.java) annotation. You also need to specify the table name as an annotation value. For example, let's define the Java class Person associated with the database table \"Person\" as a DataB Entity.\n\n```java\n@Table(\"Person\")\npublic class Person extends Entity {\n\n}\n```\n\nIt's also required to provide an empty constructor. This thing is\nnecessary to create instances of the saved objects and restore\ntheir states.\n\n```java\npublic Person() {}\n```\n\nAfter that, we can add additional fields to the Person class. Let's\ndefine such fields as a person's name and phone number. Every person has a unique phone number, and it's a good idea to describe it as a primary key for our table.\n\n```java\n//Name of the column in a database that will be related to this field\n@Field(\"name\")\nprivate String name;\n\n//Unique primary key of the table. It can be almost anything \n//In this example, we are using a phone number\n@PrimaryKey(\"phone_number\")\nprivate String phoneNumber;\n```\n\nSo, now we have defined a simple [Person](datab-examples/src/main/java/com/masich/datab/examples/simple/models/Person.java) class with a set of payload. So, let's use DataB functionality to communicate with a database and the Person table!  \n\n### Using DataB features\n\nAfter determining our custom DataB Entity, we can start using DataB core\nfunctionality. The first thing that we need to do before we start is to invoke\nour ```initDB()``` method.\n\n```java\ninitDB();\n```\n\nThis method will set up and initialize core DataB instances and database tables.\nThe SQLite database file ```sample.db``` will also be created after invoking \nthis method. Finally, it is time to make Person instances and play with our database.\n\n```java\nString maxTel = \"160-332\", bobTel = \"161-200\";\nPerson max = new Person(\"Max\", maxTel);\nPerson bob = new Person(\"Bob\", bobTel);\n```\nWe have Max and Bob as our Person class instances. And we can easily save \nthem into our database using ```save()``` method:\n\n```java\nmax.save();\nbob.save();\n```\nAnd now, our database looks as follows:\n\n| № | name | phone_number (PK) |\n|---|------|-------------------|\n| 1 | Max  | 160-332           |\n| 2 | Bob  | 161-200           |\n\nWe can get a particular person in our database by using ```Person.getById()```\nmethod. This method will return a person from the database with the appropriate id (Primary Key) or ```null``` if the person with such id isn't in the database table.\n\n```java\nSystem.out.println(Person.getById(maxTel, Person.class));\n```\n\nThis will print ```Person{name='Max', phoneNumber='160-332'}``` in the console.\nWe also can use ```Person.getAll()``` method to get all rows in the Person database table. The result of this method is a ```List``` with all of the\ntable rows.\n\n```java\nSystem.out.println(Person.getAll(Person.class));\n```\n\nAnd this operation will print such information as:\n\n```[Person{name='Max', phoneNumber='160-332'}, Person{name='Bob', phoneNumber='161-200'}]```\n\nOf course, removing row or rows from the database is possible. To do it\nyou can use either ```delete()``` for one row or ```Person.deleteAll(Person.class)```\nfor all rows in the database table:\n\n```java\nbob.delete()\nSystem.out.println(Person.getById(maxTel, Person.class));\nSystem.out.println(Person.getAll(Person.class));\n\nPerson.deleteAll(Person.class);\nSystem.out.println(Person.getAll(Person.class));\n```\n\nAnd the result will be as follows:\n\n```\nnull\n[Person{name='Bob', phoneNumber='161-200'}]\n[]\n```\n\nYou can also create ```Iterable``` instance and save it in a database table\nusing ```Person.saveAll()```:\n\n```java\nList\u003cPerson\u003e people = new ArrayList\u003c\u003e();\npeople.add(max);\npeople.add(bob);\npeople.add(new Person(\"Lara\", \"163-213\"));\npeople.add(new Person(\"Julia\", \"162-112\"));\n\nPerson.saveAll(people);\n```\n\nAnd now our Person database table looks like this:\n\n| № | name   | phone_number (PK) |\n|---|--------|-------------------|\n| 1 | Max    | 160-332           |\n| 2 | Bob    | 161-200           |\n| 3 | Lara   | 163-213           |\n| 4 | Julia  | 162-112           |\n\nAnd, of course, we can get all these rows:\n\n```java \nSystem.out.println(Person.getAll(Person.class));\n```\nWith a result such as this:\n\n```[Person{name='Max', phoneNumber='160-332'}, Person{name='Bob', phoneNumber='161-200'}, Person{name='Lara', phoneNumber='163-213'}, Person{name='Julia', phoneNumber='162-112'}]```\n\nThe complete source code of this example is presented [here](datab-examples/src/main/java/com/masich/datab/examples/simple).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasich%2Fdatab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasich%2Fdatab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasich%2Fdatab/lists"}