Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
edf9a1d7
Commit
edf9a1d7
authored
May 29, 2015
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] Database connexion fix thanks to Elias.
parent
c7d3c746
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
18 deletions
+14
-18
db.py
gargantext_web/db.py
+14
-18
No files found.
gargantext_web/db.py
View file @
edf9a1d7
from
gargantext_web
import
settings
from
django.conf
import
settings
from
node
import
models
from
node
import
models
__all__
=
[
'literalquery'
,
'session'
,
'cache'
,
'Session'
,
__all__
=
[
'literalquery'
,
'session'
,
'cache'
,
'Session'
,
'bulk_insert'
,
'engine'
,
'get_cursor'
,
'User'
]
'bulk_insert'
,
'engine'
,
'get_cursor'
]
# initialize sqlalchemy
# initialize sqlalchemy
...
@@ -15,9 +15,16 @@ from sqlalchemy import create_engine, MetaData, Table, Column, ForeignKey
...
@@ -15,9 +15,16 @@ from sqlalchemy import create_engine, MetaData, Table, Column, ForeignKey
from
sqlalchemy.types
import
Integer
,
String
,
DateTime
from
sqlalchemy.types
import
Integer
,
String
,
DateTime
from
sqlalchemy.dialects.postgresql
import
JSON
from
sqlalchemy.dialects.postgresql
import
JSON
engine
=
create_engine
(
'postgresql+psycopg2://{USER}:{PASSWORD}@{HOST}/{NAME}'
.
format
(
# SQLAlchemy session management
**
settings
.
DATABASES
[
'default'
]
def
get_engine
():
))
from
sqlalchemy
import
create_engine
url
=
'postgresql+psycopg2://{USER}:{PASSWORD}@{HOST}:{PORT}/{NAME}'
.
format
(
**
settings
.
DATABASES
[
'default'
]
)
return
create_engine
(
url
,
use_native_hstore
=
True
)
engine
=
get_engine
()
Base
=
automap_base
()
Base
=
automap_base
()
Base
.
prepare
(
engine
,
reflect
=
True
)
Base
.
prepare
(
engine
,
reflect
=
True
)
...
@@ -122,17 +129,6 @@ def literalquery(statement, dialect=None):
...
@@ -122,17 +129,6 @@ def literalquery(statement, dialect=None):
return
LiteralCompiler
(
dialect
,
statement
)
return
LiteralCompiler
(
dialect
,
statement
)
# SQLAlchemy session management
def
get_engine
():
from
sqlalchemy
import
create_engine
url
=
'postgresql+psycopg2://{USER}:{PASSWORD}@{HOST}/{NAME}'
.
format
(
**
settings
.
DATABASES
[
'default'
]
)
return
create_engine
(
url
,
use_native_hstore
=
True
)
engine
=
get_engine
()
def
get_sessionmaker
():
def
get_sessionmaker
():
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.orm
import
sessionmaker
return
sessionmaker
(
bind
=
engine
)
return
sessionmaker
(
bind
=
engine
)
...
@@ -200,6 +196,7 @@ def get_cursor():
...
@@ -200,6 +196,7 @@ def get_cursor():
'user'
:
db_settings
[
'USER'
],
'user'
:
db_settings
[
'USER'
],
'password'
:
db_settings
[
'PASSWORD'
],
'password'
:
db_settings
[
'PASSWORD'
],
'host'
:
db_settings
[
'HOST'
],
'host'
:
db_settings
[
'HOST'
],
'port'
:
db_settings
[
'PORT'
]
})
})
return
db
,
db
.
cursor
()
return
db
,
db
.
cursor
()
...
@@ -233,4 +230,3 @@ class bulk_insert:
...
@@ -233,4 +230,3 @@ class bulk_insert:
return
''
return
''
readline
=
read
readline
=
read
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment