Skip to content

Commit

Permalink
Add insert_query for list of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomasula committed May 10, 2022
1 parent fe61545 commit 32897bc
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/odm2datamodels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pickle
from enum import Enum
from typing import Dict, Union, Any, Type
from typing import Dict, Union, Any, Type, List
import warnings

import pandas as pd
Expand Down Expand Up @@ -105,17 +105,14 @@ def read_query(self,
return df.to_dict()
raise TypeError("Unknown output format")

def insert_query(self) -> None:
"""Placeholder for bulk insert"""
#accept dataframe & model
#use pandas to_sql method to perform insert
#if except return false or maybe raise error
#else return true
raise NotImplementedError

def create_object(self, obj:object) -> Union[int, str]:
pkey_name = obj.get_pkey_name()
setattr(obj, pkey_name, None)
def insert_query(self, objs:List[object]) -> None:
with self.session_maker() as session:
session.add_all(objs)
session.commit()


with self.session_maker() as session:
session.add(obj)
Expand Down

0 comments on commit 32897bc

Please sign in to comment.