{"id":4861,"date":"2025-01-30T16:17:14","date_gmt":"2025-01-30T16:17:14","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4861"},"modified":"2025-03-29T21:03:04","modified_gmt":"2025-03-29T21:03:04","slug":"work-on-sqlite-database-in-memory","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/database\/sqlite\/work-on-sqlite-database-in-memory","title":{"rendered":"Work on SQLite database in memory"},"content":{"rendered":"\n<p>If your database isn&#8217;t massive and you are carrying out lots of operations on it, it can be much faster to load it into memory instead of working with disk access<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Opening an existing SQLite database into memory<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>    #Open the database to work on from files\n    #db1 = sqlite3.connect('my_database_file.db3')\n    #db1cursor = db1.cursor()\n\n    #Open the database into memory\n    db1_source = sqlite3.connect('my_database_file.db3')\n    db1 = sqlite3.connect(':memory:')\n    db1_source.backup(db1)\n    db1cursor = db1.cursor()\n    db1_source.close()<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Saving an in memory SQLite database to file<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>    #Close the database if opened from file\n    #db1.close()\n    \n    #Close the database out of memory to file\n    db1_output = sqlite3.connect('my_database_file.db3')\n    db1.backup(db1_output)\n    db1.close()\n    db1_output.close()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If your database isn&#8217;t massive and you are carrying out lots of operations on it, it can be much faster to load it into memory instead of working with disk access Opening an existing SQLite database into memory Saving an in memory SQLite database to file<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[351],"tags":[],"class_list":["post-4861","post","type-post","status-publish","format-standard","hentry","category-sqlite"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4861"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4861\/revisions"}],"predecessor-version":[{"id":4862,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4861\/revisions\/4862"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}