Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2-metadata-importation-doc #3

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,675 changes: 3,675 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions child-picture-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"childData":{
"children":[
{
"name":"",
"source": "",
"height": "",
"width": "",
"bbox":""
}
],
"count":""
}

}
41 changes: 41 additions & 0 deletions db/queries/queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import psycopg
import os

NACHET_DB_URL = os.getenv("NACHET_DB_URL")

NACHET_SCHEMA = os.getenv("NACHET_SCHEMA")

def createConnection():
return psycopg.connect(NACHET_DB_URL)

def createCursor(conn):
return conn.cursor()

def createSearchPath(conn,cur):
cur.execute(f"""SET search_path TO "{NACHET_SCHEMA}";""")
conn.commit()

def closeConnection(conn):
conn.close()

def closeCursor(cur):
cur.close()

def endQuery(conn,cursor):
conn.commit()
closeCursor(cursor)
closeConnection(conn)

def queryDB(conn,cur,query):
cur.execute(query)
conn.commit()
return cur

def queryParameterizedDB(conn,cur,query, params):
cur.execute(query, params)
conn.commit()
return cur

def printResults(cur):
for record in cur:
print(record)
70 changes: 70 additions & 0 deletions db/setup/db-creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import db.queries.queries as queries

# Connect to your PostgreSQL database with the DB URL
conn = queries.createConnection()
# Create a cursor object
cur = queries.createCursor(conn)

# # Create Schema
# cur.execute("""CREATE SCHEMA "nachetdb_0.0.1";""")

# # Create Search Path
# cur.execute("""SET search_path TO "nachetdb_0.0.1";""")

# #Create Users table
# cur.execute("""
# CREATE TABLE \"%s\".users (
# id uuid PRIMARY KEY,
# email VARCHAR(255)
# )
# """ % ("nachetdb_0.0.1"))

# # Create Indexes table
# cur.execute("""
# CREATE TABLE \"%s\".indexes (
# id uuid PRIMARY KEY,
# index JSON,
# ownerID uuid REFERENCES "nachetdb_0.0.1".users(id)
# )
# """ % ("nachetdb_0.0.1"))

# # Create Pictures table
# cur.execute("""
# CREATE TABLE \"%s\".pictures (
# id uuid PRIMARY KEY,
# picture JSON,
# indexID uuid REFERENCES "nachetdb_0.0.1".indexes(id)
# )
# """ % ("nachetdb_0.0.1"))

# Create seed DB
cur.execute("""
CREATE TABLE \"%s\".seeds (
id uuid PRIMARY KEY,
info JSON,
name VARCHAR(255)
)
""" % ("nachetdb_0.0.1"))

# # check if the schema exists
cur.execute("""
SELECT EXISTS (
SELECT *
FROM information_schema.schemata
WHERE schema_name = 'nachetdb_0.0.1'
)
""")

# # check if the search path exists
# cur.execute("Show search_path")


## Commit the transaction
conn.commit()

print(cur.fetchone()[0])

# Close the cursor and connection
cur.close()
conn.close()
print("done")
66 changes: 66 additions & 0 deletions db/setup/db-mock-seeds-population.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import uuid
import db.queries.queries as queries


# Connect to your PostgreSQL database with the DB URL
conn = queries.createConnection()
# Create a cursor object
cur = queries.createCursor(conn)

brassicaNapus = (str(uuid.uuid4()), "Brassica napus")
brassicaJunsea = (str(uuid.uuid4()), "Brassica juncea")
cirsiumArvense = (str(uuid.uuid4()), "Cirsium arvense")
cirsiumVulgare = (str(uuid.uuid4()), "Cirsium vulgare")
carduusNutans = (str(uuid.uuid4()), "Carduus nutans")
bromusSecalinus = (str(uuid.uuid4()), "Bromus secalinus")
bromusHordeaceus = (str(uuid.uuid4()), "Bromus hordeaceus")
bromusJaponicus = (str(uuid.uuid4()), "Bromus japonicus")
loliumTemulentum = (str(uuid.uuid4()), "Lolium temulentum")
solanumCarolinense = (str(uuid.uuid4()), "Solanum carolinense")
solanumNigrum = (str(uuid.uuid4()), "Solanum nigrum")
solanumRostratum = (str(uuid.uuid4()), "Solanum rostratum")
ambrosiaArtemisiifolia = (str(uuid.uuid4()), "Ambrosia artemisiifolia")
ambrosiaTrifida = (str(uuid.uuid4()), "Ambrosia trifida")
Ambrosiapsilostachya = (str(uuid.uuid4()), "Ambrosia psilostachya")

queries.createSearchPath(conn, cur)

# Query to insert a seed
query = "INSERT INTO seeds (id,name) VALUES (%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s),(%s,%s)"
data = (
brassicaNapus[0],
brassicaNapus[1],
brassicaJunsea[0],
brassicaJunsea[1],
cirsiumArvense[0],
cirsiumArvense[1],
cirsiumVulgare[0],
cirsiumVulgare[1],
carduusNutans[0],
carduusNutans[1],
bromusSecalinus[0],
bromusSecalinus[1],
bromusHordeaceus[0],
bromusHordeaceus[1],
bromusJaponicus[0],
bromusJaponicus[1],
loliumTemulentum[0],
loliumTemulentum[1],
solanumCarolinense[0],
solanumCarolinense[1],
solanumNigrum[0],
solanumNigrum[1],
solanumRostratum[0],
solanumRostratum[1],
ambrosiaArtemisiifolia[0],
ambrosiaArtemisiifolia[1],
ambrosiaTrifida[0],
ambrosiaTrifida[1],
Ambrosiapsilostachya[0],
Ambrosiapsilostachya[1],
)

# queries.queryParameterizedDB(conn,cur,query,data)

queries.queryDB(conn, cur, "select id,name from seeds")
queries.printResults(cur)
Loading