On Wed, Apr 10, 2019 at 6:03 AM Mohsen Pahlevanzadeh
<m.pahlevanza...@gmail.com> wrote:
>
> I have a code for mysql.(by sqlalchemy), Now I converted my data to sqlite3 
> for some reasons.Do i have to use session for sqlite? I already write the 
> following class for support mysql :
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////
> class DbAbsLayer(object):
>     '''
>     docs
>     '''
>
>     def __init__(self):
>         '''
>
>         '''
>         self.set_connection_URI();
>         self.create_engine();
>         declarative_base().metadata.create_all(self.get_engine());
>         self.create_session();
> ##############################setConnectionURI 
> function########################
>     def set_connection_URI(self):
>         self.__db_driver = "mysql";
>         self.__db_hostname = "localhost";
>         self.__db_username = "phpmyadmin";
>         self.__db_password = "123";
>         self.__db_name = "quran_uthmani";
>
> ##############################create_engine function########################
>     def create_engine(self):
>         self.__engine = create_engine(self.__db_driver + "://" + 
> self.__db_username + ":" + self.__db_password + "@" + self.__db_hostname + 
> "/" + self.__db_name + "?charset=utf8");
>
> ##############################create_session function########################
>     def create_session(self):
>         '''
>         docs
>         '''
>         Session = sessionmaker(bind = self.get_engine());
>         self.session = Session.configure(bind = self.get_engine());
>         self.session = Session();
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> How I have to do for sqlite?

You don't need to change the Session, but you do need to change the
engine. SQLite engine definitions don't use usernames, passwords, or
hostnames, they just need the name of the sqlite database file:

https://docs.sqlalchemy.org/en/latest/dialects/sqlite.html#connect-strings

Hope that helps,

Simon

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to