{"id":16681762,"url":"https://github.com/casidiablo/persistence","last_synced_at":"2025-03-17T00:32:38.357Z","repository":{"id":2266174,"uuid":"3222400","full_name":"casidiablo/persistence","owner":"casidiablo","description":"Android persistence library","archived":false,"fork":false,"pushed_at":"2020-10-12T19:23:20.000Z","size":780,"stargazers_count":73,"open_issues_count":9,"forks_count":20,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-15T04:28:49.539Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://casidiablo.github.io/persistence","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"lord/slate","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/casidiablo.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}},"created_at":"2012-01-20T00:02:18.000Z","updated_at":"2025-01-27T08:31:41.000Z","dependencies_parsed_at":"2022-08-18T06:42:31.768Z","dependency_job_id":null,"html_url":"https://github.com/casidiablo/persistence","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fpersistence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fpersistence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fpersistence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fpersistence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casidiablo","download_url":"https://codeload.github.com/casidiablo/persistence/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243835942,"owners_count":20355611,"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-12T14:05:13.364Z","updated_at":"2025-03-17T00:32:38.098Z","avatar_url":"https://github.com/casidiablo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"This library works as a `SQLite` wrapper and allows you to easily create, query and work with schemas based on objects. This means\nyou can forget about handling queries and Cursors manually, and work directly with Java classes.\n\nMaven integration\n=================\n\n[![Build Status](https://travis-ci.org/casidiablo/persistence.png?branch=master)](https://travis-ci.org/casidiablo/persistence)\n\nIn order to use this library from you Android project using maven your pom should look like this:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cproject ...\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.codeslap\u003c/groupId\u003e\n            \u003cartifactId\u003epersistence\u003c/artifactId\u003e\n            \u003cversion\u003e0.9.23\u003c/version\u003e\n            \u003cscope\u003ecompile\u003c/scope\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\u003c/project\u003e\n```\n\n### Normal integration\n\nRefer to the downloads section to get a JAR to import to your project.\n\nGet started\n===========\n\nCreate a class that extends `android.app.Application` like this:\n\n```java\npublic class App extends Application {\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        DatabaseSpec database = PersistenceConfig.registerSpec(/**db version**/1);\n        database.match(Foo.class, Bar.class);\n    }\n}\n```\n\nAnd add this to your manifest:\n\n```xml\n\u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n          package=\"your.package.name\"\n          ...\u003e\n    \u003capplication ...\n                 android:name=\"your.package.name.App\"\u003e\n     ...\n```\n\nHere `Foo` and `Bar` are [POJO][1]s that you will use within your app. Persistence library will automatically create\nsqlite tables for those classes, which will allow you to insert, query, update and delete data easily:\n\nIn order to interact with the database, you must get an implementation of the [SqlAdapter][2] interface. You can do\nso this way:\n\n```java\nSqlAdapter adapter = Persistence.getAdapter(context);\n```\n\n### Inserting/updating data\n\nTo insert a simple object to the database use the `store` method:\n\n```java\n// single insertion\nFoo foo = new Foo();\n// add data to your object foo.setExample(...);\nadapter.store(foo);\n```\n\n **Notice:** if you are inserting an object of type `Foo`, you must have already registered that class in the\n *`Application` class*.\n\nIf you want to store a collection of beans use the `storeCollection(list, listener)` method:\n\n```java\nList\u003cFoo\u003e foos = new ArrayList();\n// foos.add(foo);\nadapter.storeCollection(null, new ProgressListener() {\n    @Override\n    public void onProgressChange(int percentage) {\n    }\n});\n```\n\nThis is much more efficient than implementing a loop manually since this will not insert items one-by-one but instead\nwill create a bulk insert statement. There is another version of this method called `storeUniqueCollection` which\nbasically inserts and updates objects that you pass into the list, and delete from the database those items that are not\nincluded in the list.\n\nWhen you insert an object whose primary key is not auto-increment, it will try to update it instead of inserting a new\none. In other cases use the `update` method:\n\n```java\nCity sample = new City();\nsample.setName(\"vogota\");\n\nCity newCity = new City();\nnewCity.setName(\"Bogotá\");\n\nadapter.update(newCity, sample);\n```\n\nNotice that `update` method can also be used with raw SQL statements and Android wildcards.\n\n### Querying data\n\nYou can query single objects or a collection of objects:\n\n```java\n// query a single item by example\nCity city = new City();\ncity.setName(\"Bogotá\");\nCity bogota = adapter.findFirst(city);\n```\n\nYou can also use raw SQL queries:\n\n```java\nCity bogota = adapter.findFirst(City.class, \"name LIKE 'Bogotá'\", null);\n// although it is recommended to use Android's wildcards:\nCity bogota = adapter.findFirst(City.class, \"name LIKE ?\", new String[]{\"Bogotá\"});\n```\n\nUse `findAll` to get a list of objects that matches some conditions:\n\n```java\n// Query all cities\nList\u003cCity\u003e cities = adapter.findAll(City.class);\n\n// Query cities that match a sample\nCity sample = new City();\nsample.setCountryCode(\"CO\");\nList\u003cCity\u003e colombianCities = adapter.findAll(sample);\n\n// You can set some constraints\nConstraint constraint = new Constraint().limit(3).groupBy(\"column\").orderBy(\"name\");\nList\u003cCity\u003e someCities = adapter.findAll(sample, constraint);\n```\n\n### Deleting data\n\nJust use the `delete` method:\n\n```java\n// this will truncate the table...\nadapter.delete(City.class, null, null);\n\n// this is a better way to truncate a table...\nadapter.truncate(City.class);\n\n// this will delete the items that match the sample\nCity sample = new City();\nsample.setCountryCode(\"CO\");\nadapter.delete(sample);\n```\n\n### Examples\n\nLooking for examples? You might take a look at [Github Jobs][3] app.\n\n### Feedback\n\nIf you have any questions or suggestions do not hesitate to sending me an email about it (cristian@elhacker.net).\nKeep in mind that this project is in beta phase and I do not warranty it will work as expected.\n\n  [1]: http://en.wikipedia.org/wiki/Plain_Old_Java_Object\n  [2]: https://github.com/casidiablo/persistence/blob/master/src/main/java/com/codeslap/persistence/SqlAdapter.java\n  [3]: http://github.com/casidiablo/github-jobs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasidiablo%2Fpersistence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasidiablo%2Fpersistence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasidiablo%2Fpersistence/lists"}