Giter Club home page Giter Club logo

pocketbaselib's Introduction

ko-fi

PocketbaseLib

A PocketBase lib written in GDScript 4.x. Far from feature complete but the basics are covered ๐Ÿคž

quick usage summary:

class_name PocketBaseExamples extends Control


var pb := PocketBase.new("http://127.0.0.1", 8081)


func _ready() -> void:
	list_search()


func login_example() -> void:
	var username := "woogy"
	var password := "12345678"
	var result := await pb.collection("users").auth_with_password(username, password)
	_print("login", result)


func list_search() -> void:
	# fetch a paginated records list
	var result_list := await pb.collection("temp").get_list(1, 50, {
		"filter" : "created >= '2024-07-16 00:00:00'"
	})
	_print("get_list", result_list)

	# you can also fetch all records at once via getFullList
	var records := await pb.collection("temp").get_full_list({
		"sort" : "-created"
	})
	_print("get_full_list", records)

	# or fetch only the first record that matches the specified filter
	var result := await pb.collection("temp").get_first_list_item("data='3748291'")
	_print("get_first_list_item", result)


func view_example() -> void:
	var result := await pb.collection("temp").get_one("hmgeq2zj2pgqn1i")
	_print("get_one", result)


func create_example() -> void:
	# example create data
	var data := {
		"data": Time.get_ticks_msec()
	}

	var record := await pb.collection("temp").create(data)
	_print("create", record)


func update_example() -> void:
	# example create data
	var data := {
		"data": "That will be changed"
	}

	var record := await pb.collection("temp").create(data)
	_print("create", record)

	#example update data
	var updated_data := {
		"data": "This is the new value"
	}
	var updated_record := await pb.collection("temp").update(record["id"], updated_data)
	_print("update", updated_record)


func delete_example() -> void:
	# example create data
	var data := {
		"data": "i will be deleted"
	}

	var record := await pb.collection("temp").create(data)
	_print("create", record)

	# deleted is null when successful else it is a dictionary
	var deleted := await pb.collection("temp").delete(record["id"])
	_print("delete", deleted)


func realtime_example() -> void:
	# login if needed
	var username := "woogy"
	var password := "12345678"
	await pb.collection("users").auth_with_password(username, password)

	# subscribe to every event
	pb.collection("temp").subscribe("*", temp_callback)

	# create data to test the subscription
	var data := {
		"data": Time.get_ticks_msec()
	}
	await pb.collection("temp").create(data)

	# unsubscribe if needed
	pb.collection("temp").unsubscribe("*")


func temp_callback(action:String, record:Variant) -> void:
	_print("temp_callback", {"action": action, "record": record})


func _print(title:String, data:Variant) -> void:
	print("\n========== %s ==========" % title)
	var pretty = JSON.stringify(data, "\t")
	print(pretty)

pocketbaselib's People

Contributors

woogyface avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.