{"id":16303758,"url":"https://github.com/tokuhirom/tinyorm","last_synced_at":"2025-07-04T12:34:22.335Z","repository":{"id":37276397,"uuid":"22829409","full_name":"tokuhirom/tinyorm","owner":"tokuhirom","description":"Tiny O/R mapper for Java","archived":false,"fork":false,"pushed_at":"2023-03-31T15:16:24.000Z","size":628,"stargazers_count":30,"open_issues_count":12,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-17T23:16:36.707Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.javadoc.io/doc/me.geso/tinyorm/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tokuhirom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2014-08-11T06:38:17.000Z","updated_at":"2024-08-10T03:29:12.000Z","dependencies_parsed_at":"2024-10-10T21:01:11.345Z","dependency_job_id":"6d1f3775-88bf-43f9-b48a-b67e317909ec","html_url":"https://github.com/tokuhirom/tinyorm","commit_stats":null,"previous_names":[],"tags_count":83,"template":false,"template_full_name":null,"purl":"pkg:github/tokuhirom/tinyorm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokuhirom%2Ftinyorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokuhirom%2Ftinyorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokuhirom%2Ftinyorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokuhirom%2Ftinyorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tokuhirom","download_url":"https://codeload.github.com/tokuhirom/tinyorm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokuhirom%2Ftinyorm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263542603,"owners_count":23477455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-10T21:01:03.986Z","updated_at":"2025-07-04T12:34:22.314Z","avatar_url":"https://github.com/tokuhirom.png","language":"Java","readme":"tinyorm\n=======\n\n[![Build Status](https://travis-ci.org/tokuhirom/tinyorm.svg?branch=master)](https://travis-ci.org/tokuhirom/tinyorm)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.geso/tinyorm/badge.svg)](https://maven-badges.herokuapp.com/maven-central/me.geso/tinyorm)\n\nThis is a tiny o/r mapper for Java 8.\n\n## Setup\n\nmain/java/myapp/rows/Member.java\n\n```java\n@Table(\"member\")\n@Data // lombok\n@EqualsAndHashCode(callSuper = false)\npublic Member extends Row\u003cMember\u003e {\n  private long id;\n  private String name;\n}\n```\n\n## Examples\n\nCreate new database object.\n\n```java\nConnection connection = DriverManager.getConnection(dburl, dbuser, dbpassword);\nTinyORM db = new TinyORM(connection);\n```\n\nOr you can instantiate with lazily connection borrowing, like so;\n\n```java\nProvider\u003cConnection\u003e connectionProvider = ConnectionPool.borrow();\nTinyORM db = new TinyORM(connectionPooling);\n```\n\nPlease see [Connection](#connection) section.\n\n### Selecting one row.\n\n```java\nOptional\u003cMember\u003e member = db.single(Member.class)\n  .where(\"id=?\", 1)\n  .execute();\n```\n\n### Selecting rows.\n\n```java\nList\u003cMember\u003e member = db.search(Member.class)\n  .where(\"name LIKE CONCAT(?, '%')\", \"John\")\n  .execute();\n```\n\n### Insert row\n\n```java\ndb.insert(Member.class)\n  .value(\"name\", \"John\")\n  .execute();\n```\n\nThis statement generate following query:\n\n```sql\nINSERT INTO `member` (name) VALUES ('John')\n```\n\nIf you want to use `ON DUPLICATE KEY UPDATE`, you can call `InsertStatement#onDuplicateKeyUpdate` method.\n\nFor example:\n\n```java\norm.insert(Member.class)\n  .value(\"email\", email)\n  .value(\"name\", name)\n  .onDuplicateKeyUpdate(\"name=?\", name)\n  .execute();\n```\n\n### Insert row with form class.\n\n```java\n@Data // lombok\nclass MemberInsertForm {\n  private String name;\n}\n\nMemberInsertForm form = new MemberInsertForm();\nform.name = name;\ndb.insert(Member.class).valueByBean(form).execute();\n```\n\n### Update row with form class.\n\n```java\n@Data // lombok\nclass MemberUpdateForm {\n  private String name;\n}\n\nMemberUpdateForm form = new MemberUpdateForm();\nform.name = name;\nMember member = db.single(Member.class)\n  .where(\"id=?\", 1)\n  .execute()\n  .get();\nmember.updateByBean(form);\n```\n\n### Delete row\n\n```java\nMember member = db.single(Member.class)\n  .where(\"id=?\", 1)\n  .execute()\n  .get();\nmember.delete();\n```\n\n## Annotations\n\n```java\n@Value\n@Table(\"member\")\n@EqualsAndHashCode(callSuper = false)\npublic MemberRow extends Row\u003cMemberRow\u003e {\n    @PrimaryKey\n    private long id;\n    @Column\n    private String name;\n    @Column(\"alias_name\")\n    private String aliasName;\n    @CreatedTimestampColumn\n    private long createdOn;\n}\n```\n\n### @PrimaryKey\n\nYou need to add this annotation for the field, that is a primary key.\n\n### @Column\n\nYou need to add this annotation for each columns(Note, if you specified @PrimaryKey, @CretedOnTimeStamp or @UpdatedOnTimeStamp, you don't need to specify this annotaiton).\n\n### @Column(\"column_name\")\n\nThis annotation is almost the same as `@Column`. A point of difference; this annotation can specify a column name without regard for member variable name.\n\n### @CreatedOnTimeStamp\n\nTinyORM fills this field when inserting a row. This column must be `long`. TinyORM fills epoch seconds.\n\n### @UpdatedOnTimeStamp\n\nTinyORM fills this field when updating a row. This column must be `long`. TinyORM fills epoch seconds.\n\n### @CsvColumn\n\n```java\n@CsvColumn\nprivate List\u003cString\u003e prefectures;\n```\n\nYou can store the data in CSV format.\n\n### @JsonColumn\n\n```java\n@JsonColumn\nprivate MyComplexType myComplexThing;\n```\n\nYou can store the data in JSON format.\n\n### @SetColumn\n\n```java\n@SetColumn\nprivate Set\u003cString\u003e categories;\n```\n\nTinyORM conerts MySQL's SET value as java.util.Set.\n\n## HOOKS\n\nYou can override `TinyORM#BEFORE_INSERT` and `TinyORM#BEFORE_UPDATE` methods.\nYou can fill createdOn and updatedOn columns by this.\n\n## How do I use java.time.LocalDate?\n\nYou can use java.time.LocalDate for the column field.\n\n```java\n@Value\n@EqualsAndHashCode(callSuper = false)\n@Table(\"foo\")\npublic class Foo extends Row\u003cFoo\u003e {\n    @Column\n    private LocalDate date;\n}\n```\n\nTinyORM automatically convert java.sql.Date to java.time.LocalDate.\n\n## HOW DO I WRITE MY OWN CONSTRUCTOR?\n\nYou can create your own constructor, and create it from the constructor, you need to add `java.beans.ConstructorProperties` annotation.\n\n```java\npublic class RowExample {\n    @java.beans.ConstructorProperties({\"name\", \"age\", \"score\", \"tags\"})\n    public RowExample(String name, long age, long score, String tags) {\n       // ...\n    }\n}\n```\n\nNormally, you should use lombok.Value to create constructor.\n\n## Connection\n\n### Supports handling two divided connections\n\nTinyORM can use two connections, `read/write` connection and `read only` connection.\n\nTinyORM decide automatically which connection to use depending on the situation.\nIt means, TinyORM uses `read only` connection when handling reading query.\nOn the other hand, that uses `read/write` connection when handling writing query or handling some queries in a transaction.\n\nIt ensures using the same `read/write` connection in a transaction.\n\n#### How to use two connections\n\n```java\nConnection connection = DriverManager.getConnection(dburl, dbuser, dbpassword);\nConnection readConnection = DriverManager.getConnection(readDburl, readDbuser, readDbpassword);\nTinyORM db = new TinyORM(connection, readconnection);\n```\n\nIf you pass only one connection to the constructor, TinyORM treats that connection as `read/write` connection and always uses that.\n\n### Supports lazily connection borrowing\n\nIf you pass the type of `Provider\u003cConnection\u003e` value to the constructor,\nTinyORM defers borrowing (or establishing) connection until the connection is needed.\n\n## LICENSE\n\n  The MIT License (MIT)\n  Copyright © 2014 Tokuhiro Matsuno, http://64p.org/ \u003ctokuhirom@gmail.com\u003e\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files (the “Software”), to deal\n  in the Software without restriction, including without limitation the rights\n  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n  copies of the Software, and to permit persons to whom the Software is\n  furnished to do so, subject to the following conditions:\n\n  The above copyright notice and this permission notice shall be included in\n  all copies or substantial portions of the Software.\n\n  THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n  THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokuhirom%2Ftinyorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftokuhirom%2Ftinyorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokuhirom%2Ftinyorm/lists"}