You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							62 lines
						
					
					
						
							1.5 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							62 lines
						
					
					
						
							1.5 KiB
						
					
					
				
								package sqlite
							 | 
						|
								
							 | 
						|
								import (
							 | 
						|
									"context"
							 | 
						|
								
							 | 
						|
									"git.aiterp.net/lucifer/lucifer/models"
							 | 
						|
								)
							 | 
						|
								
							 | 
						|
								// SessionRepository is a sqlite database.
							 | 
						|
								var SessionRepository = &sessionRepository{}
							 | 
						|
								
							 | 
						|
								type sessionRepository struct{}
							 | 
						|
								
							 | 
						|
								func (r *sessionRepository) FindByID(ctx context.Context, id string) (models.Session, error) {
							 | 
						|
									row := db.QueryRowxContext(ctx, "SELECT * FROM session WHERE id=?", id)
							 | 
						|
									if err := row.Err(); err != nil {
							 | 
						|
										return models.Session{}, err
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									session := models.Session{}
							 | 
						|
									if err := row.StructScan(&session); err != nil {
							 | 
						|
										return models.Session{}, err
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									return session, nil
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								func (r *sessionRepository) Insert(ctx context.Context, session models.Session) error {
							 | 
						|
									_, err := db.NamedExecContext(ctx, "INSERT INTO session (id, user_id, expire_date) VALUES(:id, :user_id, :expire_date)", session)
							 | 
						|
									if err != nil {
							 | 
						|
										return err
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									return nil
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								func (r *sessionRepository) Update(ctx context.Context, session models.Session) error {
							 | 
						|
									_, err := db.NamedExecContext(ctx, "UPDATE session SET user_id=:user_id AND expire_date=:expire_date", session)
							 | 
						|
									if err != nil {
							 | 
						|
										return err
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									return nil
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								func (r *sessionRepository) Remove(ctx context.Context, session models.Session) error {
							 | 
						|
									_, err := db.NamedExecContext(ctx, "DELETE FROM session WHERE id=:id", session)
							 | 
						|
									if err != nil {
							 | 
						|
										return err
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									return nil
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								func (r *sessionRepository) Clear(ctx context.Context, user models.User) error {
							 | 
						|
									_, err := db.NamedExecContext(ctx, "DELETE FROM session WHERE user_id=:id", user)
							 | 
						|
									if err != nil {
							 | 
						|
										return err
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									return nil
							 | 
						|
								}
							 |