Giter Site home page Giter Site logo

Support for SQLite about records HOT 7 CLOSED

kennethreitz avatar kennethreitz commented on May 4, 2024
Support for SQLite

from records.

Comments (7)

kennethreitz avatar kennethreitz commented on May 4, 2024

I haven't used the DB-API directly myself. What would the integration look like?

from records.

MichaelMartinez avatar MichaelMartinez commented on May 4, 2024

Using the Sqlite standard lib is straightforward: here is some code I wrote while scraping Living Social for my wife. 😈 It is not the prettiest code out there, but it works... and a reason why a simple method to do this with Records will be highly requested.

# Start the DB
def init_db():
    con = sqlite3.connect("Living_Social.db")
    cur = con.cursor()
    cur.execute(
        '''CREATE TABLE IF NOT EXISTS deals (id INTEGER PRIMARY KEY, name TEXT, price_before REAL, price_after REAL, url TEXT UNIQUE, scrapetime text )''')
    con.commit()
    cur.close()
    con.close()


def save_to_db(deal_info):
    con = sqlite3.connect("Living_Social.db")
    cur = con.cursor()
    # Had to use OR IGNORE due scrape pulling down more than one listing
    # Using the URL as the Unique identifier because it contains the deal ID and we need it anyway
    cur.execute("INSERT OR IGNORE INTO deals (name, price_before, price_after, url, scrapetime) VALUES (?,?,?,?,?)", \
                [deal_info['name'], deal_info['price_before'], deal_info['price_after'], deal_info['url'], deal_info['scrapetime']])
    con.commit()
    cur.close()
    con.close()

As far as integration into records is concerned... no idea. 😕

from records.

lucianmarin avatar lucianmarin commented on May 4, 2024

You can simply check DATABASE_URL string and use sqlite3.connect() instead of psycopg2.connect().

from records.

kennethreitz avatar kennethreitz commented on May 4, 2024

It looks like the parameterization style is different. I'd have to take a closer look.

If we're going to support multiple databases, I think using SQLAlchemy as our driver would be the simplest choice.

from records.

kennethreitz avatar kennethreitz commented on May 4, 2024

Currently, this library plans to support Postgres–only. That may change, but not now.

from records.

kennethreitz avatar kennethreitz commented on May 4, 2024

cough support for sqlite has been added!

from records.

kennethreitz avatar kennethreitz commented on May 4, 2024

✨ 🍰 ✨

v0.4.0 includes support for all major databases. Enjoy!

from records.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.