{"id":15069370,"url":"https://github.com/tylersuehr7/sqlite-java-library","last_synced_at":"2025-04-10T17:43:54.164Z","repository":{"id":130831682,"uuid":"101229430","full_name":"tylersuehr7/sqlite-java-library","owner":"tylersuehr7","description":"A library to help simplify using the SQLite JDBC when using the Java JDK. Support code-first and database-first SQLite databases!","archived":false,"fork":false,"pushed_at":"2019-01-20T05:44:43.000Z","size":5770,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T15:22:00.264Z","etag":null,"topics":["java","jdbc","jdk","sqlite","sqlite-jdbc"],"latest_commit_sha":null,"homepage":null,"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/tylersuehr7.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":"2017-08-23T22:16:41.000Z","updated_at":"2023-09-20T22:21:06.000Z","dependencies_parsed_at":"2023-07-18T02:30:28.708Z","dependency_job_id":null,"html_url":"https://github.com/tylersuehr7/sqlite-java-library","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylersuehr7%2Fsqlite-java-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylersuehr7%2Fsqlite-java-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylersuehr7%2Fsqlite-java-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylersuehr7%2Fsqlite-java-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tylersuehr7","download_url":"https://codeload.github.com/tylersuehr7/sqlite-java-library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248262283,"owners_count":21074281,"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":["java","jdbc","jdk","sqlite","sqlite-jdbc"],"created_at":"2024-09-25T01:42:03.964Z","updated_at":"2025-04-10T17:43:54.147Z","avatar_url":"https://github.com/tylersuehr7.png","language":"Java","readme":"# SQLite Java Library\nA library to help simplify using the SQLite JDBC when using the Java JDK. Supports code-first and database-first SQLite databases!\n\n### Code-First Approach\nUse this approach if you want your database to be created during runtime. \n\nIf you're using this approach, `SQLiteOpenHelper`, guarantees that `onCreate(SQLiteDatabase)` will be called only after the SQLite database file has first been created. This method can be used to create all the tables, views, and/or insert initial data.\n\nIncrementing the database version, after it has been created, guarantees that `SQLiteOpenHelper` will call `onUpdate(SQLiteDatabase, int, int)`. This method can be used to update table structures or drop and re-create all tables.\n\n### Database-First Approach\nUse this approach if you already have a SQLite database file that you wish to use during runtime.\n\nIf you're using this approach, `SQLiteOpenHelper`, will NOT call `onCreate(SQLiteDatabase)`. However, you can still utilize the database version if you wish to update the database programmatically. Incrementing the database version will still guarentee that `SQLiteOpenHelper` will call `onUpdate(SQLiteDatabase, int, int)`.\n\n### Code-First Example\nStep 1: Inherit `SQLiteOpenHelper` and implement the abtract methods.\n```java\n  public final class DatabaseClient extends SQLiteOpenHelper {\n      @Override\n      protected void onCreate(SQLiteDatabase db) {\n          ...\n      }\n      \n      @Override\n      protected void onUpdate(SQLiteDatabase db, int oldVersion, int newVersion) {\n          ...\n      }\n  }\n```\nStep 2: Create using a Singleton, add logic for your database structure, and expose the `SQLiteDatabase`.\n```java\n  public final class DatabaseClient extends SQLiteOpenHelper {\n      private static final String DB_NAME = \"johnny_vaughn_db\";\n      private static final int DB_VERSION = 1;\n      private static volatile DatabaseClient instance;\n      private final SQLiteDatabase db;\n      \n      \n      private DatabaseClient() {\n          super(DB_NAME, DB_VERSION);\n          this.db = getWritableDatabase();\n      }\n      \n      public static synchronized DatabaseClient getInstance() {\n          if (instance == null) {\n              instance = new DatabaseClient();\n          }\n          return instance;\n      }\n      \n      @Override\n      protected void onCreate(SQLiteDatabase db) {\n          createUsersTable(db);\n      }\n      \n      @Override\n      protected void onUpdate(SQLiteDatabase db, int oldVersion, int newVersion) {\n          db.execSql(\"DROP TABLE IF EXISTS [users];\");\n          onCreate(db);\n      }\n      \n      /**\n       * Expose the SQLiteDatabase to anything that wants to use it.\n       */\n      public SQLiteDatabase getDatabase() {\n          return db;\n      }\n      \n      private void createUsersTable(SQLiteDatabase db) {\n          db.execSql(\"CREATE TABLE [users]([id] INTEGER PRIMARY KEY, [name] TEXT NOT NULL);\");\n      }\n  }\n```\n\n### Database-First Example\nStep 1: Inherit `SQLiteOpenHelper` and implement the abtract methods. You won't need to add code to `onCreate(SQLiteDatabase)`, but you can for `onUpdate(SQLiteDatabase, int, int)` if you're going to manage updates programmatically.\n```java\n  public final class DatabaseClient extends SQLiteOpenHelper {\n      @Override\n      protected void onCreate(SQLiteDatabase db) {}\n      \n      @Override\n      protected void onUpdate(SQLiteDatabase db, int oldVersion, int newVersion) {\n          ...\n      }\n  }\n```\nStep 2: Setup using the Singleton design pattern and be sure to use the exact path of your SQLite database file you want to use. Expose the `SQLiteDatabase` object.\n```java\n  public final class DatabaseClient extends SQLiteOpenHelper {\n      private static final String DB_NAME = \"name_of_existing_database_file.db\";\n      private static final int DB_VERSION = 1;\n      private static volatile DatabaseClient instance;\n      private final SQLiteDatabase db;\n      \n      \n      private DatabaseClient() {\n          super(DB_NAME, DB_VERSION);\n          this.db = getWritableDatabase();\n      }\n      \n      public static synchronized DatabaseClient getInstance() {\n          if (instance == null) {\n              instance = new DatabaseClient();\n          }\n          return instance;\n      }\n      \n      @Override\n      protected void onCreate(SQLiteDatabase db) {}\n      \n      @Override\n      protected void onUpdate(SQLiteDatabase db, int oldVersion, int newVersion) {}\n      \n      /**\n       * Expose the SQLiteDatabase to anything that wants to use it.\n       */\n      public SQLiteDatabase getDatabase() {\n          return db;\n      }\n  }\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylersuehr7%2Fsqlite-java-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylersuehr7%2Fsqlite-java-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylersuehr7%2Fsqlite-java-library/lists"}