Skip to content

Instantly share code, notes, and snippets.

View Enigo's full-sized avatar

Ruslan S. Enigo

View GitHub Profile
@Enigo
Enigo / search.rs
Last active January 13, 2024 11:40
use crate::view::loading::LoadingSpinnerGrayNoVh;
use crate::Route;
use gloo_timers::callback::Timeout;
use log::error;
use model::model::search::SearchData;
use web_sys::wasm_bindgen::JsCast;
use web_sys::HtmlInputElement;
use yew::prelude::*;
use yew_router::prelude::*;
#[derive(Serialize, Deserialize)]
pub struct SearchData {
pub asset_content_data: Vec<AssetContentData>,
}
#[derive(Serialize, Deserialize, PartialEq, Clone)]
pub struct AssetContentData {
pub token_id: i32,
pub token_address: String,
pub name: String,
pub async fn get_search_results(pool: &Pool<Postgres>, search: &String) -> Option<SearchData> {
return match query_as::<_, AssetContentDb>(
"select token_id, token_address, metadata->>'name' as name, metadata->>'image_url' as image_url from asset
where ($1~'^\\d+$' and token_id::text like '%' || $1 || '%') or lower(metadata->>'name') like '%' || $1 || '%'
order by 1, 3
limit 20",
)
.bind(search.to_lowercase())
.fetch_all(pool)
.await
use crate::utils::env_utils;
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};
use sqlx::{ConnectOptions, Pool, Postgres};
pub async fn create_pool() -> Pool<Postgres> {
let options = PgConnectOptions::new()
.host(env_utils::as_string("DB_HOST").as_str())
.port(env_utils::as_parsed::<u16>("DB_PORT"))
.database(env_utils::as_string("DB_DATABASE").as_str())
.username(env_utils::as_string("DB_USERNAME").as_str())
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let pool = db_handler::create_pool().await;
HttpServer::new(move || {
App::new()
.app_data(Data::new(pool.clone()))
.service(search_controller::get_search_results)
})
.bind(("127.0.0.1", 8080))?
use actix_web::{get, web, HttpResponse, Responder};
use serde::Deserialize;
use sqlx::{Pool, Postgres};
use crate::db::assets_handler;
#[derive(Deserialize)]
pub struct SearchParams {
search: String,
}
pipeline {
parameters {
choice(name: 'REGION', choices: ['us-east-1']) // add as per your needs
string(name: 'AMI_ID', defaultValue: '', description: '', trim: true)
}
stages {
stage('Validate pipeline parameters') {
steps {
script {
VpcId: <vpc>
Subnets:
- <subnet>
ImageId: AMI_ID
InstanceType: i3.2xlarge
@Enigo
Enigo / cfn.yaml
Created September 16, 2023 11:14
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
VpcId:
Description: VPC id where stack should be deployed
Type: AWS::EC2::VPC::Id
Subnets:
Description: Subnet IDs
Type: CommaDelimitedList
CREATE KEYSPACE zoo WITH replication = {'class': 'NetworkTopologyStrategy', '<DATACENTER>' : 3} AND durable_writes = true;
USE zoo;
CREATE TABLE animals
(
name text PRIMARY KEY,
data map<text, text>
);