Skip to content

Instantly share code, notes, and snippets.

@zelid
zelid / gist:6965002
Last active August 3, 2023 17:23
Examples of BulkInsert for PostgreSQL, MySQL and MS SQL using ServiceStack OrmLite. Work in progress...
public static void BulkInsertNpgsql<T>(this IDbConnection dbConn, IEnumerable<T> list, IEnumerable<string> insertFields = null)
{
if (list == null) return;
if (list.Count() < 1) return;
var objWithAttributes = list.FirstOrDefault();
var modelDef = OrmLiteConfig.GetModelDefinition(objWithAttributes.GetType());
if (insertFields == null) insertFields = new List<string>();
<form action="/question" method="post">
<ul>
<li>
<input type="text" name="Name" value="Question Name" />
<input type="text" name="Id" value="1" />
</li>
<li>
<ul>
<li>
<input type="text" name="Question[Answers][0].Name" value="Answer 1 Name" />
<form action="/question" method="post">
<ul>
<li>
<input type="text" name="Name" value="Question Name" />
<input type="text" name="Id" value="1" />
</li>
<li>
<ul>
<li>
<input type="text" name="Answers[0].Name" value="Answer 1 Name" />
Post["/question"] = parameters =>
{
Question question = this.Bind();
return View["question.html", question];
};
public class Question
{
public int Id { get; set; }
public string Name { get; set; }
public List<Answer> Answers { get; set; }
public List<Comment> Comments { get; set; }
}
public class Answer
{
@zelid
zelid / utils.py
Created May 19, 2012 14:37
Allow to create new model with related models in Flask-Peewee API call
def get_models_from_dictionary(model, field_dict):
if isinstance(model, Model):
model_instance = model
check_fks = True
else:
model_instance = model()
check_fks = False
models = [model_instance]
for field_name, value in field_dict.items():
field_obj = model._meta.fields[field_name]