56 lines
1.5 KiB
C#
Raw Normal View History

using MySql.Data.MySqlClient;
using System;
2023-01-27 11:34:31 -08:00
namespace MontoyaTech.MySqlPlus.Example
{
public class Program
{
[MySqlRow("cars")]
public class Car
2023-01-27 11:34:31 -08:00
{
[MySqlColumn(Id = true, Name = "id")]
2023-01-27 11:34:31 -08:00
public ulong Id = 0;
[MySqlColumn("make")]
public string Make = null;
[MySqlColumn("model")]
2023-01-27 11:34:31 -08:00
public string Model = null;
[MySqlColumn("year")]
public uint Year = 0;
//[MySqlColumn("dateCreated", typeof(DateTime2UnixConverter))]
//public DateTime DateCreated = DateTime.UtcNow;
2023-01-27 11:34:31 -08:00
}
public class DateTime2UnixConverter
{
}
public static void Main(string[] args)
{
var session = new MySqlSession("server=db.zone2d.com;user=root;database=zone2d;port=3306;password=-+W6!?Kv-6wDL2Vj5f=kC^Q&;SslMode=Required");
session.Insert(new Car() { Make = "Chevy", Model = "Camaro", Year = 2011 });
session.Insert(new Car() { Make = "GMC", Model = "Sierra", Year = 2000 });
var cars = session.GetAll<Car>();
foreach (var car in cars)
Console.WriteLine($"Make: {car.Make}, Model: {car.Model}, Year: {car.Year}");
cars[0].Make = "test";
session.Update(cars[0]);
foreach (var car in cars)
session.Delete(car);
Console.WriteLine("Done.");
Console.ReadLine();
2023-01-27 11:34:31 -08:00
}
}
}